Friday, May 24, 2013

Get rid of Dashboard in Mac OS 10.9

I rarely use the dashboard. All these widgets can be fun, but I did not find one that would make me go to the dashboard regularly. I like gesture though and mission control. And I find that the dashboard is a waste of space when in mission control. So I looked around and saw this post http://www.macworld.com.au/help/how-to-use-terminal-to-speed-up-mountain-lion-70147/#.UZ8GP5VR0TM . One of the tips is how to disable completely the dashboard. So here it is, in 2 commands, how to disable dashboard ( do not use sudo here, just your normal user ) :


defaults write com.apple.dashboard mcx-disabled -boolean YES
killall Dock

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

>

Friday, February 8, 2013

Adding console output formatting to blogger

I have been looking for a way to display properly formatted command line output in blogger for quite some times now, and I finally have a solution.
Go to Design page of your blog, then click on the "advanced" link on the top left of the page. Scroll all the way down to "Add css". On the text field right below "Add custom CSS" Type the following :
pre.console {
  background-color: #666666 ;
  border: 1px solid #006600 ;
  color: #FFFFFF ;
  font-size:.8em ;
}

Now each time you want to display command output prepend your text with <pre class="console">
and append your text with </pre>

It's not very pretty at the moment, but I will work on it ! Also this does not seem to work on mobile device....

Cacti : How to use templates

Cacti is a pretty good tool to generate graph. It is developped using php and rrd to store the data collected. Its templates are very usefull and very powerfull.... if you figure out how to create them and in which order ;-)
I recently had to graph a family of devices using Cacti. Using templates was an absolute necessity so I spent time trying to figure out how to use them... It took me few days, so if I may spare that time to somebody else, I decided to write a little documentation on the subject. It's more a flow chart than anything else and it is not official documentation but it might help. Because the size of the flowchart is actually quite big, I only put a thumbsize image here but I included a link to a PDF version of the normal size one.






Link to the original post with PDF version of the document.

LSI MegaRAID failed drive replacement

Installing command line tool

The command line tool to manage raid devices should be located at /opt/MegaRAID/MegaCli/MegaCli64. If not, you can download the RPM from IBM. It is an architecture independant package. I personnaly used it on Redhat and opensuse successfully. The one I'm using for this documentation is ibm_utl_sraidmr_megacli-8.04.08_linux_32-64.zip. So you have to untar, then do rpm -Uvh on both packages ( one for library and one for the actual command line tool ).

Getting the big picture

To start with, the following command queries all adapters and returns information about the virtual drives defined, their status and all physical drives that they are made of. The command output a lot of information so I usually grep some keywords to shorten the text. Here is the command and an extract of the output :
./MegaCli64 -LDPDInfo -aALL | egrep "Adapter|Virtual Disk|Name|RAID|State|^Number|^Span|PD:|^Device|Firmware|^$"
Adapter #0

Number of Virtual Disks: 2
Virtual Disk: 0 (target id: 0)
Name:
RAID Level: Primary-5, Secondary-0, RAID Level Qualifier-3
State: Optimal
Number Of Drives:9
Span Depth:1
Number of Spans: 1
Span: 0 - Number of PDs: 9
PD: 0 Information
Device Id: 15
Firmware state: Online

PD: 1 Information
Device Id: 16
Firmware state: Online

PD: 2 Information
Device Id: 17
Firmware state: Online

...

PD: 8 Information
Device Id: 23
Firmware state: Online

Virtual Disk: 1 (target id: 1)
Name:data2
RAID Level: Primary-5, Secondary-0, RAID Level Qualifier-3
State: Degraded
Number Of Drives:24
Span Depth:1
Number of Spans: 1
Span: 0 - Number of PDs: 24
PD: 0 Information
Device Id: 42
Firmware state: Online

PD: 1 Information
Device Id: 43
Firmware state: Online

...

PD: 22 Information
Device Id: 64
Firmware state: Online

PD: 23 Information
Device Id: 65
Firmware state: Online

Adapter #1

Number of Virtual Disks: 1
Virtual Disk: 0 (target id: 0)
Name:
RAID Level: Primary-5, Secondary-0, RAID Level Qualifier-3
State: Optimal
Number Of Drives:11
Span Depth:1
Number of Spans: 1
Span: 0 - Number of PDs: 11
PD: 0 Information
Device Id: 8
Firmware state: Online

PD: 1 Information
Device Id: 9
Firmware state: Online

...

PD: 10 Information
Device Id: 18
Firmware state: Online

Finding the drive to replace

It's a good idea to start gathering info about the Adapter :


/opt/MegaRAID/MegaCli> sudo ./MegaCli64 -AdpAllInfo -aALL

Adapter #0

==============================================================================
                    Versions
                ================
Product Name    : PERC H700 Integrated
Serial No       : 18P02M3
FW Package Build: 12.10.2-0004

...

                Device Present
                ================
Virtual Drives    : 1
  Degraded        : 0
  Offline         : 0
Physical Devices  : 5
  Disks           : 4
  Critical Disks  : 0
  Failed Disks    : 0
...



So we know now that the current machine has one adapter : Adapter 0. So in the following command, we will specify -a0 for adpater 0. Then we get enclosure information :
/opt/MegaRAID/MegaCli> sudo ./MegaCli64 -EncInfo -a0

    Number of enclosures on adapter 0 -- 1

    Enclosure 0:
    Device ID                     : 32
    Number of Slots               : 6
    Number of Power Supplies      : 0
    Number of Fans                : 0
    Number of Temperature Sensors : 0
    Number of Alarms              : 0
    Number of SIM Modules         : 0
    Number of Physical Drives     : 4
    Status                        : Normal
    Position                      : 0
    Connector Name                : Unavailable
    Enclosure type                : SES
    FRU Part Number               : N/A
    Enclosure Serial Number       : N/A
    ESM Serial Number             : N/A
    Enclosure Zoning Mode         : N/A
    Partner Device Id             : 65535

    Inquiry data                  :
        Vendor Identification     : DP
        Product Identification    : BACKPLANE
        Product Revision Level    : 1.07
        Vendor Specific           : 18NJ5VP


Exit Code: 0x00
So we have one adapter a0 and one enclosure with an id of 32. We now query for the logical drive information :
/opt/MegaRAID/MegaCli> sudo ./MegaCli64 -LDInfo -LALL -a0


Adapter 0 -- Virtual Drive Information:
Virtual Drive: 0 (Target Id: 0)
Name                :server
RAID Level          : Primary-1, Secondary-0, RAID Level Qualifier-0
Size                : 557.75 GB
Mirror Data         : 557.75 GB
State               : Degraded
Strip Size          : 64 KB
Number Of Drives per span:2
Span Depth          : 2
Default Cache Policy: WriteBack, ReadAdaptive, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteBack, ReadAdaptive, Direct, No Write Cache if Bad BBU
Default Access Policy: Read/Write
Current Access Policy: Read/Write
Disk Cache Policy   : Disk's Default
Encryption Type     : None
Bad Blocks Exist: No
Is VD Cached: Yes
Cache Cade Type : Read Only
This shows us the RAID level used ( 1-0 so a mirror of strippes ) and the status of this raid device : Degraded.
So now we look for the deffective drive with the following command. The field we need to watch is Firmware State : Failed.
/opt/MegaRAID/MegaCli> sudo ./MegaCli64 -PDList -a0

Adapter #0

...

Enclosure Device ID: 32
Slot Number: 3
...

Firmware state: Failed

...
The output has been truncated to show only relevant information. So in our case, it's the drive in slot number 3 of enclosure ID 32 that needs to be replaced.

Replacing the drive

We prepare the drive for replacement :
/opt/MegaRAID/MegaCli> sudo ./MegaCli64 -PDOffline -PhysDrv\[32:3\] -a0

Adapter: 0: EnclId-32 SlotId-3 state changed to OffLine.

Exit Code: 0x00
/opt/MegaRAID/MegaCli> sudo ./MegaCli64 -PDMarkMissing -PhysDrv\[32:3\] -a0

EnclId-32 SlotId-3 is marked Missing.

Exit Code: 0x00
/opt/MegaRAID/MegaCli> sudo ./MegaCli64 -PDPrpRmv -PhysDrv\[32:3\] -a0


Prepare for removal Success

Exit Code: 0x00
Now it's time for the physical replacement.

Then if everything went smoothly, you should see the array being rebuild :
/opt/MegaRAID/MegaCli> sudo ./MegaCli64 -PDInfo -PhysDrv\[32:3\] -a0

Enclosure Device ID: 32
Slot Number: 3
Drive's postion: DiskGroup: 0, Span: 1, Arm: 1
Enclosure position: N/A
Device Id: 3

...
Firmware state: Rebuild

...
We can query the controler to see the actual rebuild progress :
/opt/MegaRAID/MegaCli> sudo ./MegaCli64 -PDRbld -ShowProg -PhysDrv\[32:3\] -a0

Rebuild Progress on Device at Enclosure 32, Slot 3 Completed 7% in 3 Minutes.

Exit Code: 0x00

Checking

Eventually, you should see something like that :
/opt/MegaRAID/MegaCli> sudo ./MegaCli64 -PDRbld -ShowProg -PhysDrv\[32:3\] -a0

Device(Encl-32 Slot-3) is not in rebuild process

Exit Code: 0x00 

/opt/MegaRAID/MegaCli> sudo ./MegaCli64 -LDInfo -LALL -a0


Adapter 0 -- Virtual Drive Information:
Virtual Drive: 0 (Target Id: 0)
Name                :server
RAID Level          : Primary-1, Secondary-0, RAID Level Qualifier-0
Size                : 557.75 GB
Mirror Data         : 557.75 GB
State               : Optimal
Strip Size          : 64 KB
Number Of Drives per span:2
Span Depth          : 2
Default Cache Policy: WriteBack, ReadAdaptive, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteBack, ReadAdaptive, Direct, No Write Cache if Bad BBU
Default Access Policy: Read/Write
Current Access Policy: Read/Write
Disk Cache Policy   : Disk's Default
Encryption Type     : None
Bad Blocks Exist: No
Is VD Cached: Yes
Cache Cade Type : Read Only



Exit Code: 0x00