Cisco Spark Webhooks using Node.js

February 20, 2017

I’ve been trying to come up with a reason to play around with node.js. I’ve also been trying to make some time to play around with the Cisco Spark API. So I figured I would merry the two of them. My intention was to setup a webhook on a channel, then in my node application display the messages being posted in my room. Pretty simple example, but it touches a few different things.

First, you need to setup your webhook to point to your server.

Second, you need to have node installed, in this case I’m using Ubuntu 16.04.

Third, write some code. Check out my comments to follow along.

//will use these for the POST request

var express = require("express");
var myParser = require("body-parser");
var app = express();

//will use this for the GET request

var http = require(‘https’);

app.use(myParser.json());
app.post("/", function(request, response){

console.log(request.method);

//console the webhook name as well as the name of the author of the message
console.log(‘Webhook:’+request.body.name);
console.log(‘Email:’+request.body.data.personEmail);

//setup your GET request to find out the actual message posted by the author

var options = {
host: ‘api.ciscospark.com’,
path: ‘/v1/messages/’+request.body.data.id,
headers: {
  ‘User-Agent’: ‘request’,
  ‘Authorization’: ‘Bearer MyAuth’
}
}

//make the request

http.request(options, OnResponse).end();
});

//capture the request response

function OnResponse(response){
var data = ”;
response.on(‘data’, function(chunk){
  data += chunk;
});

response.on(‘end’, function(){
  data = JSON.parse(data);

//console out the actual text
  console.log(data.text);
});
}

app.listen(8080);

~david

Cisco Finesse Desktop Tabs for Supervisors

February 13, 2017

This came up on this thread and figured I would post something about it is an easy mistake. The Finesse layout is devided into an Agent and Supervisor section. So adding a tab to the top of the default layout will only add it to the Agent view. You can tell the layouts apart by the following tags:

<layout>
    <role>Agent</role>
    <page>

</layout>

or

<layout>
    <role>Supervisor</role>
    <page>
</layout>

~david

Travels to India

January 30, 2017

I had the pleasure of traveling to India this past week. Here are a few observations for those of you who might be venturing out for the first time.

– I was expecting 3rd world, but really India is a new industrialized country (NIC). The media, stories from past colleagues, and just general lack of knowledge all were preparing me for some pretty grim experiences around the have and have nothings. Although there is some stark poverty and you see it often, it felt that the big cities were all moving in the right direction of the monetary spectrum.

– The honor system of driving. My preference would be to never drive in Mexico City, however I don’t think I could drive in India even if you put a gun to my head. There is a direct link between the driver and the car horn and this link is unbroken and used every 10 seconds. Imagine every motorized vehicle on the road using the horn for everything. You’re going to try and pass someone, horn. You’re going to make a turn, horn. You’re entering a lane, horn. The explanation was that this was the way to keep everyone around you informed that you were there and to mind you, honestly with so many horns going off at the same time, it’s difficult for me to not understand how do people not become immune to that sound. The system seems to work as I didn’t see a single accident, and traffic cops were few and far between.

– When two wheels will inherit the earth. Motorbikes and mopeds outnumber cars in the big cities. Followed by these little 3 wheel “taxis”. These vehicles are like ants, they can get into any space and will utilize any lane available. Which generally means a lane which is not a lane. What Americans would consider a normal 3 lane road for 3 cars, in India the space will allow 2 cars, 5 motorbikes, and 2 taxies to weave in and around each other in a single car length.

– Expecting Mexican Spicy. I love spicy food and I eat a lot of India food in the US which you can generally ask for it to be made spicier. No matter how much I tried, I couldn’t get anyone to give me any decent heat on any of my meals.

– Personal space means nothing. In the US we generally will occupy an elevator by moving towards the walls. You start with the call directly opposite to the door, then move to the wall closes to the controls, and finally the corners. When the walls are occupied, it’s now time to take the centered most area created by this square of people. Not in India. If the walls are utilized, someone will stand closest to whoever they see first. This means an 8 inches away, face to face ride where I found myself asking, “Is this gentleman going to try and kiss me?” I had a few other occurrences where strangers would look over my shoulder at my phone and where hand holding, hugging, and all around physical contact was significantly different than what you see in the states.

– Time zones where sleep goes to die. If you’re expecting to conduct business with your US counterparts and will be in India for any significant amount of time, prepare to hurt. The first few nights it was not so bad to have a meeting at 10:30 PM India Standard Time (IST), but anything beyond that and things got very difficult or impossible. Add to the fact that you’ll never really be on IST, but on some nebulous I’ll sleep for short periods of time and feel exhausted most of the time I’m awake time zone. Move all your meetings as early as possible. Send emails which don’t require some back and forth.

– IT is it. If you’ve been to Silicon Valley you’ll see vast zones with big building dedicated to technology. In India, you’ll see the same thing with bigger buildings an more people. I knew IT was big in India, I didn’t know just how big. I’m not sure if it’s just that the building seems larger and that people tend to spend more time outside, but it just felt bigger than any single US city.

I’m looking forward to going back, hopefully with more time and with an opportunity to travel all over the country.

~david

Armada by Ernest Cline (Who wrote Ready Player One)

November 22, 2016

This book has been on my nightstand for a long while and I finally sat down and got a chance to finish it. I didn’t hate the book, but I didn’t love it either.

First, it was a very similar premise to Ready Player One*. A young kid who lives his life playing video games and has an afinity for 80s music. Second, a lot of things felt very rushed. The book could have spent more time on the attacks and talked a bit more about Earth’s reaction. Instead it just focused on a few “dog fights” and didn’t deliver on the bigger effect accross the world. Finally, the love story seemed very forced. I understand the need to use this element, but it seemed so unecessary in the context of this book. Almost, felt like she was written in after the fact and to just check a box off.

If you’re on the fence on which book to read first or which book to read at all, skip Armada* and go for Ready Player One.

~david

*ref links

Install AWS Elastic Beanstalk CLI in Vagrant

October 15, 2016

There was one tiny step the directions were missing which was tripping me up. This assumes Vagrant 1.8.4.

1. Confirm your python version.

2. Install pythond-dev.

3. Install pip if you don’t have it.

4. Edit bashrc: vi ~/.bashrc

5. At the end of the file add: PATH=~/.local/bin:$PATH

6. Reload .barshrc: . ~/.bashrc

7. Test eb: eb –version

Another star!

July 7, 2016

A lot of people run into me in the Cisco Support Forums as I try to keep pretty active not only to keep my memory fresh on some stuff I don’t touch much but to also keep a pulse on what the world is working on. The forum allows other users to provide you with points based on how they find your answers useful. Just got to the next level based on points awarded, a lovely shade of blue.

image

The breakdown:

image

Using git to push and pull repositories.

February 17, 2016

I’ve been trying to get more proficient with git and figured the only way to do that is to get my hands dirty and write some simple app(s) and push them to a production server. There are my notes, mainly for me to help me remember how this stuff works.

The very first time you do a git init to initialize your repository.

git init

You do this every time you want to add new changes to your reposiotry.

git add .

To see the status of things which are going to be added, removed.

git status

Once you’re happy with what you want to commit, leave your future self a little love note.

git commit –m “Doing something”

You only do this the first time to setup your remote repository destination.

git remote add origin git@github.com:dmaciasSS/myrepo.git

Then you do this every time you want to push your commit.

git push –u origin master

Now, let’s say I want to pull my repository to a new host e.g. production. If you’re using Laravel make sure you’re setting up your environment name in your vhost file first.

sudo git clone https://github.com/dmaciasSS/myrepo.git locaton/in/my/server

Laravel specific commands.

chown -R :www-data app/storage

chmod –R 777 app/storage

‘composer install’

php artisan cache:clear

I’ve found for 5.1 you might have to do this the first time too.

mkdir storage/views

mkdir storage/sessions

chown –R :www-data app/storage

Now, once you’ve cloned your repository you need to updated it every time you want to pull down any new commits.

sudo git pull origin master

composer update

php artisan cache:clear

~david

Microsoft Azure and Laravel 5.1 from Scratch

February 16, 2016

While most people use AWS, I like to use Azure and there’s just not a lot of information relating Azure and Laravel, so figured this might be useful for others. This assumes a level of comfort with Linux and Azure.

  • Login: https://portal.azure.com/#
  • Click on Virtual machines (classic) and search for Ubuntu. My preference has always been Ubuntu server 14.04 LTS, select this.
  • Select deployment model: Resource Manager and click Create.
  • Give your VM some basic information: Name, User name, Authentication Type (SSH public key is my preference). Create a new resource group, I always use the same name as the VM and Location. I usually do the A1 Standard size.
  • Click ok to choose the defauls under Settings.
  • Click OK on summary and your VM will start deploying, this will take about 10-15 minutes to complete.
  • Once running, click the VM, Public Ip address/DNS name label, All Settings, Configuration, and give it a DNS name. I do this to not have to deal with IP addresses and use actual names.

At this point, I created a CustomScript Extension using this https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-script-lamp/ and http://tutsnare.com/how-to-install-laravel-on-ubuntu-lamp/ and http://tecadmin.net/install-laravel-framework-on-ubuntu/ This will install everything you need. The script is below. To run the script through the CLI you need to use this command: azure vm extension set -c "./public_config.json" <yourresourcegroup> <yourvm> CustomScriptForLinux Microsoft.OSTCExtensions 1.4
If you want to run the script manually, just SSH into your VM and go through every step below starting at "sudo apt-get -y".

  • SSH into your machine.
  • Instal composer: curl -sS https://getcomposer.org/installer | php
  • Move composer globally: sudo mv composer.phar /usr/local/bin/composer
  • Install Laravel: sudo composer create-project laravel/laravel /var/www/laravel 5.1.*
    • sudo mkdir laravel/app/storage
    • sudo chown -R www-data.www-data /var/www/laravel
    • sudo chmod -R 755 /var/www/laravel
    • sudo chmod -R 777 /var/www/laravel/app/storage
  • Create VirtualHost and use sample below: vim /etc/apache2/sites-available/yourhost.com.conf
  • Enable your site config: sudo a2ensite yourhost.com
  • Reload Apache: sudo service apache2 reload
  • Disable default site: sudo a2dissite 0000-default
  • Reload Apache: sudo service apache2 reload
  • Open VM firewall: sudo iptables -A INPUT -p tcp –dport 80 -j ACCEPT
  • Restart VM: sudo shutdown -r now
  • In Azure Portal Network Security Group find "inbound security rules" and add a rule for port 80.
  • Go to your http://yourhost.com Welcome!

Azure LAMP install script:
#!/bin/bash
# set up a silent install of MySQL
dbpass="YourPasswordHere"

export DEBIAN_FRONTEND=noninteractive
echo mysql-server-5.6 mysql-server/root_password password $dbpass | debconf-set-selections
echo mysql-server-5.6 mysql-server/root_password_again password $dbpass | debconf-set-selections

# install the LAMP stack
sudo apt-get -y install apache2 mysql-server php5 php5-mysql php5-curl

#install extensions
#installing json extension
sudo apt-get install php5-json
#installing unzip extension
sudo apt-get install unzip
#installing curl extension
sudo apt-get install curl
#installing openssl extension
sudo apt-get install openssl
#installing mcrypt extension
sudo apt-get install php5-mcrypt
#enable mcrypt extension
sudo php5enmod mcrypt
#installing git
sudo apt-get install -y git-core
#enable mod rewrite extension
sudo a2enmod rewrite

# write some PHP
echo \<center\>\<h1\>My Demo App\</h1\>\<br/\>\</center\> > /var/www/html/phpinfo.php
echo \<\?php phpinfo\(\)\; \?\> >> /var/www/html/phpinfo.php

# restart Apache
sudo apachectl restart

Yourhost.com.conf:
<VirtualHost *:80>
       
        ServerName laravel.example.com
        DocumentRoot /var/www/laravel/public

        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/laravel>
                AllowOverride All
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

For posterity.

This is case sensative.
public_config.json:{"fileUris":["/scripts/Laravel.sh"]’>/scripts/Laravel.sh"]’>/scripts/Laravel.sh"]’>https://<yourstorage>/scripts/Laravel.sh"], "commandToExecute":"sh Laravel.sh" }

Cisco UCS C240 M3 WebBIOS

January 17, 2016

Recently had a hard time figuring out how to get to the RAID confirugation tool in a C240 M3. No matter how much I put in Control-R or Control-V or any other convination I always ended up in EFI Shell.

EFI Shell

Well, the WebBIOS is actually right behind the EFI Shell. Just type “exit” and enjoy. Killed me. Sad smile

~david

Use of undefined constant CURL_HTTP_VERSION_1_1 – assumed ‘CURL_HTTP_VERSION_1_1’

August 29, 2015

I was getting this problem even though I did have curl installed. However, I forgot to restart apache.

To install curl:

apt-get install php5-curl

To restart Apache2:

service apache2 restart

 

~david

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org