Friday, March 22, 2013

Safari opens gmail in mobile view on mac OSX

Ever wonder why your safari browser would open gmail in mobile mode on mac OSX ? It looks like it is due to a cookie. To reset this setting, open up "preferences" in Safari and go to the privacy tab. Then click on the "details" button as illustrated below :


Because you might have a LOT of cookie as I do, you might want to type google in the next window to narrow down the search. Then you should only the google's cookies. The one to remove is googleusercontent. Click on it, then click remove :


You can then click Done, and Safari should now opens gmail in Desktop mode.

Thursday, March 21, 2013

Graphing Summit switches temperature and fan speed

ExtremeNetworks switches can report internal temperature and fan speed. Because I could not find any corresponding snmp values, I decided to use a bash script to get the values. And I used Cacti to graph the result. This document is a documentation on how to do it.

Writing the script

As I mentioned, I could not find any snmp values related to internal temperature or fan speed, so I decided to write a shell script. Because ssh module for ExtremeNetworks switches need to be downloaded, I decided to use the "vanilla" conf and use telnet instead. So the script requires expect to simulate login name and password to enter the switch.

So here is the script :

#!/bin/bash

USER="XXXXXX"
PASSWORD="XXXXXX"
SWITCHNAME=$1
OUTFILE=$$.expect

if [ -e $1 ]
then
        echo "Please provide a switch name..."
        exit 99
fi

expect -c "spawn telnet $SWITCHNAME
expect \"login:\"
send \"$USER\r\"
expect \"password:\"
send \"$PASSWORD\r\"
expect \"#\"
send \"sh temp\r\"
expect \"#\"
send \"sh fans\r\"
expect \"#\"
send \"exit\r\"
expect \"(y/N)\"
send \"N\r\"
" >> /tmp/$OUTFILE

TEMPERATURE=`grep "^Switch" /tmp/$OUTFILE | awk '{print $4}'`
FAN1=`grep "Fan-1" /tmp/$OUTFILE | awk '{print $4}'`
FAN2=`grep "Fan-2" /tmp/$OUTFILE | awk '{print $4}'`
FAN3=`grep "Fan-3" /tmp/$OUTFILE | awk '{print $4}'`
FAN4=`grep "Fan-4" /tmp/$OUTFILE | awk '{print $4}'`
#echo "Current switch temperature is : $TEMPERATURE"
#echo "Current fan speed are : $FAN1, $FAN2, $FAN3, $FAN4"

rm /tmp/$OUTFILE

RRDSTRING="temperature:$TEMPERATURE speedfan1:$FAN1 speedfan2:$FAN2 speedfan3:$FAN3 speedfan4:$FAN4"

echo "$RRDSTRING"
I named this script summit-temp. Please replace USER and PASSWORD with your credentials. This script will accept one parameter : hostname. When you run it, it will only output the following line :
# ./summit-temp myhost
temperature:33.00 speedfan1:1000 speedfan2:1000 speedfan3:1000 speedfan4:1000
#

This is one of the format supported by Cacti to get values from a script. I like it because we have names associated with data and not just the data.
Save the script in cacti script directory. On my installation it is in /var/www/html/scripts/

Then login to cacti and let the fun begins !!!! It is quite tedious to create all the templates needed to graph what you want but it is worth the work. Once done, you can add as many devices as you want with just few clicks.

So let's start with the first template : Data Input Method.
In the console tab of Cacti, go to Collection Methods section and click on Data Input Method. This will list any existing DIM. On the top right corner, click on the "Add" to add a new one and fill the form like below :
It is good pratice when you create template to append its name with the type of template you are creating. In this case it is a Data Input Method, so we'll append DIM to its name.
Input type is script/command. In the next field make sure to add <hostname> after your script name. Without it Cacti won't provide this parameter to your script.
Click create.
On the next form, input fields are the data Cacti provides to your script and outfields the data your script provides to Cacti. So it should look like this :
Save it.

Once you have your Data Input Method, you have to create your Data Template. In the templates section, click on data templates. On the top right corner click "Add".
In the data template, you specify what kind of data you are going to use. There are basically 2 types :
- counter : for data that will constantly increase like a packet count on a network interface
- gauge : a reading like temperature or memory used for instance.
In our case, it's gonna be only gauge.
Fill in the form so it looks like this :
Make sure you write |host_description| in the name of the data source. This will be replace by Cacti with a proper name depending on the host.
Also make sure to match the Output field name ( speedfan1- speedfan1 ) with the datasource item [ speedfan1 ] your are configuring.

We move on to the graph template. Click on graph templates then click "Add". Begin with its name and title ( don't forget the |host_description| ) then click save. You will now be prompted with a new form onto which you add all the graph items you want. This part requires a little more information :
- temperature : I made 2 graph items for the temperature. The first one will fill an area from 0 to the current temperature. So basically, instead of having a single line for the temperature, the surface between 0 and current temperature will also be painted. This is not at all mandatory but it looks better. The second item is simply the line showing the temperature.
- fan speed : Because I wanted to display both fan speed and temperature on the same graph, I had to play a little bit with the scale. Fan speed is typically 1000 and temp should be around 30. So if we try to display both on the same graph with the same scale, temperature will be almost invisible. I decided to divide the fan speed by 100. So 1000 will show up as 10. This is achieve by creating a new CDEF function that I called divide by 100. To do that you go to GraphManagement and click right below on --- CDEF, then click "Add".
The CDEF function "Divide by 100" should be as follow :

So back to the graph template. Your definition should look like this :

Your temperature graph items should be :

And your fan speed graph item like this :
Note here the use of CDEF function "Divide by 100".

The last part of the template definition is the host template. This is basically to associate a type of host with a type of graph. So in our case, we are going to associate the host type "Summit" with the graph type "Extreme - Temp and fan speed - GT" :

Once done, all your templates have been created and this one time job is done. Now it's time to create devices. A device is the actual equipment you want the graph for. Click on Device and "Add" and fill in the form like this :
then the graph should show up in the graph section. Click on it to select then click on "Create graph for this host" :

You might have to wait for up to 5 mns for the graph to be created. Don't panic ! If after 5mns it is still not there then there might be an issue.
If everything is fine you will have something like this :

Hope this document will help.

Monday, March 11, 2013

Disk usage using awk

This command will give you the top 20 files or directories that take the most space in the current directory :

sudo du -k -x --max-depth=1 | sed 's/\.$/Total\n/g' | sort -rn | head -20 | awk 'BEGIN{printf "\n%20s %-30s","Size in Kbytes","file or directory"}{printf "\n%20'\''d %-30s", $1, $2} END{print "\n"}'

Here it is in action :)


> sudo du -k -x --max-depth=1 | sed 's/\.$/Total\n/g' | sort -rn | head -20 | awk 'BEGIN{printf "\n%20s %-30s","Size in Kbytes","file or directory"}{printf "\n%20'\''d %-30s", $1, $2} END{print "\n"}'

      Size in Kbytes file or directory
          12,964,287 Total
             455,377 ./Photos
             238,572 ./realtek-linux-audiopack-5.17
             235,719 ./IPMI
             135,153 ./realtek-linux-audiopack-5.16
             123,731 ./PCoIP_Driver_SW_v3-0-6_Linux(source
             119,884 ./alsa-driver-1.0.25
              97,912 ./pcoip_host_software
              69,968 ./nagios-plugins-1.4.16
              58,653 ./BMC
              53,357 ./PCoIP-Test
              50,866 ./scim-1.4.9
              50,793 ./sunbird
              48,648 ./leostream
              41,160 ./teradici-firmware
              24,886 ./cacti-0.8.8a
              19,548 ./wqy-zenhei-0.9.45
              16,258 ./leolog
              15,888 ./PCoIP_Host_Software_Driver_Linux_r4-0-5
              14,394 ./Leostream

>