This script is intended to be used with Nagios to monitor a HP P2000 SAN. Below is a description and the file can be downloaded here:

All versions can be found here: https://github.com/thomasweaver/check_p2000_api

  • Version 1.2 allowing input of username and password. Great thanks to Jon Witts who added the code which can be found here http://pastebin.com/T1DMYJbu# or download zip below
  • Version 1.3 Adds an extra check to the status check. A problem was found where by some disk failures were not picked up this was found by Tjerk Nan one extra check on the vdisk fixes this.
  • Version 1.4 Adds Individual volume status and vdisk status allowing you to create separate services for the checks. Thanks to Jon Witts for writing this http://www.jonwitts.co.uk/archives/296.
  • Version 1.5 Adds a check for vdisk Read and write latencies that’s available in later firmwares. Thanks to Tjerk Nan for adding these extra checks.
  • Version 1.6 Add a curl part to the plugin so the pecl_http module is no longer needed but curl libraries are.
  • Version 1.7 Adds a timeout of 120 seconds to the http_pecl module as timeouts on the default value have occurred on slow networks. Thanks to Aurélien MARTY for finding and fixing the issue.

NOTE: For this command to run the php-http module needs to be installed: http://php.net/manual/en/book.http.php or CURL libraries for version 1.6 and above. Only certain P2000 Firmware’s support the statistic commands and so the performance checks won’t work on some SAN’s but the status check should work on all P2000 Firmware’s. Note you may need to run dos2unix check_p2000_api.php if you get an error about not finding /usr/bin/php. A Bug has been found in version 1.0.1 whereby it may not pick up a broken disk on later Firmware versions, v1.1 fixes this by using multiple different API calls to determine the health.

The P2000 has an inbuilt API where any CLI command can be run and output in an XML format. This script utilises this api and can gather performance data and component status of the SAN.

The script uses the following commands:

show enclosure-status – /API/show/enclosure-status – This outputs all the enclosures, disks, fans, PSUs etc

show disk-statistics – /api/show/disk-statistics – This outputs the Disk statistics including IOPs, Read Speed etc.

show controller-statistics – /api/show/controller-statistics – This outputs the controller statistics including cpu etc

show vdisk-statistics – /api/show/vdisk-statistics – This outputs the vdisk statistics including IOPs, Read Speed etc

show volume-statistics – /api/show/volume-statistics – This outputs the volume statistics including IOPs, Read Speed etc

As of Version 1.2 the auth string is replaced with a Username and Password.

Version 1.1 and below:

The script first uses an authentication string which is a combination of the username and password. To get this auth string you need to capture the traffic when you login to the SAN Management HTTP interface and look at the first post and there will be the author string. The image below shows a packet capture with an authentication string highlighted.

P2000 wireshark packet capture

Once you have the auth string you can run the below command:

./check_p2000_api.php -H 192.168.0.1 -L 035ce62a046eaace03bface2abf7e740

All Versions

By default the plugin checks the status of the P2000 SAN and so only the host address username and password.

./check_p2000_api.php -H 192.168.0.1 -U admin -P password

This will loop through all Enclosures, FAN’s, PSU’s, Temperatures, Voltages and Disks. This will not output any performance data. Below is an example of the output:

OK : Enclosure 1 OK, FAN 2 OK, PSU 2 OK, Temp 4 OK, Voltage 10 OK, Disk 10 OK,

To start getting performance data you need to first decide what you want to monitor so first of all log in to the HTTP Management interface and then run the commands in the api yourself and look at the output. Below is some of the output from /api/show/disk-statistics

So say we want to get the IOPS of each disk we could run the command:

./check_p2000_api.php -H 192.168.0.1 -U admin -P password -c disk -S iops

OK : disk iops – disk_1.1 0, disk_1.2 0, disk_1.3 0, disk_1.4 0, disk_1.5 0, disk_1.6 0, disk_1.7 0, disk_1.8 0, disk_1.9 0, disk_1.10 0, | disk_1.1=0;;; disk_1.2=0;;; disk_1.3=0;;; disk_1.4=0;;; disk_1.5=0;;; disk_1.6=0;;; disk_1.7=0;;; disk_1.8=0;;; disk_1.9=0;;; disk_1.10=0;;;

-c is the command we want to run there are currently 5 options status, disk, vdisk, volume and controller these map directly to the commands shown above so specifying disk will run the command /api/show/disk-statistics. -S specifies which value to get from the output. This is basically the value given to the “name” argument in the XML output in our example this is “iops”, but you could use “bytes-per-second-numeric” as the -S option. If no -S value is given then this defaults to iops. If the above command is run it will give the IOPs for all disks in the controller.

What if we want to get the CPU utilization of the controller. Well we need to specify enclosure for the -c value and then cpu-load for the -S value. We can provide more options to the script such as a warning and critical value these are provided using -w and -C by default this will mean if the value from the API is greater than either warning or critical then return the appropriate warning or critical state. This is great in most situations but what if you want to be warned if the iops or cpu or whatever is lower than these values well you can specify this with the -t option with a value of “lessthan”. We can also specify what units the value is measured in with the -u option this will simply add the value to the end of the output. All this can also be done securely over HTTPS by specifying a value of 1 with the -s option (NOTE there is a bug in at least one version of the HP P2000 where sometimes authentication over HTTPS doesn’t work.). So lets put all this into a command

./check_p2000_api.php -H 192.168.0.1 -U admin -P password -c controller -S cpu-load -s 1 -u “%” -w 60 -C 80

So this command will get the CPU load of the controllers in the enclosure over HTTPS and will append the % sign to the output. It will be in a Warning state if the utilisation is over 60% and Critical if its over 80%.

The command would output something like below:

OK : controller cpu-load – controller_A 1%, controller_B 1%, | controller_A=1%;60;80; controller_B=1%;60;80;

This command would give you a graph like below:

P2000 CPU graph

Once you have tested everything in the command line its time to add it to nagios. So first create the command:

define command {

   command_name                             check_p2000

   command_line                             $USER1$/check_p2000_api.php -H $HOSTADDRESS$ -U $USER11$ -P $USER12$ $ARG1$

}

$USER1$ is obviously the path to your plugin directory. I put $USER11$ in the nagios resource.cfg this is so you can easily change it if you need to.

Once you have the command defined you then need to define the service:

define service {

    host_name                       SANHOST

    service_description             Controller CPU

    use                             generic-service

    check_command                   check_p2000!-c controller -S cpu-load -u "%" -w 60 -C 80!!!!!!!

    register                        1

   }

Don’t forget always run nagios -v to confirm your configuration is correct before restarting the nagios service.

Installing on Ubuntu

To get the plugin working on Ubuntu you will need to install the pecl_http extension. To do this first install php-pear:

apt-get install  php-pear
apt-get install libcurl4-gnutls-dev
apt-get install make
pecl install pecl_http

You will be asked a few questions during this install just use all default answers. If you get an error saying it can’t find curl header make sure you have installed the curl libraries with the command above. If this installs successfully it should say “You should add “extension=http.so” to php.ini”. So lets do that using a text editor:

Add the line extension=http.so to /etc/php/php If all that went well then you should now be able to use the script.

Installing on Groundwork

Groundwork comes with its own version of PHP located in /usr/local/groundwork/php.

To use this version of PHP I had to download the pecl_http extension and compile it from source. Before that you need to make sure a few things are installed first. I used CentOS but the principle should be the same on other Distros:

yum install autoconf
yum install make
yum install zlib-devel
yum install libcurl-devel

Now you need to download the latest pecl_http extension source from here:

wget http://pecl.php.net/get/pecl_http-1.7.4.tgz
tar -xvf pecl_http-1.7.4.tgz
cd pecl_http-1.7.4.tgz
phpize
./configure
make
make test
make install

Once installed add “extension=http.so” (without the quotes) to /usr/local/groundwork/php/etc/php.ini

Now change the first line of the script to:

#!/usr/local/groundwork/php/bin/php

Everything should work with the script now.