⌨ Labor omnia vincit ☮

HP-UX SNMP check

Posted in python, UNIX by anaumov on 29.02.2016

A few days ago I upload my first nagios plugin to exchange.nagios.org. This is a small python script to monitor HP-UX servers using SNMPv2c. SNMP is the de facto standart for gathering information from network devices or servers. Many different devices from many different vendors support it as a management protocol.

SNMP manages information via a Management Information Base (MIB), which is a three-like structure that contains hierarchical information in ASN.1 format. MIBs can be referred to by name or numbers. I use following MIBs:

HP-UX MIBs
cpu 1 min 1.3.6.1.4.1.11.2.3.1.1.3
cpu 5min 1.3.6.1.4.1.11.2.3.1.1.4
cpu 15 min 1.3.6.1.4.1.11.2.3.1.1.5
memory total 1.3.6.1.4.1.11.2.3.1.1.8.0
memory free 1.3.6.1.4.1.11.2.3.1.1.7.0
FS mount point 1.3.6.1.4.1.11.2.3.1.2.2.1.10
FS usage size 1.3.6.1.4.1.11.2.3.1.2.2.1.7
FS total size 1.3.6.1.4.1.11.2.3.1.2.2.1.4
FS free space 1.3.6.1.4.1.11.2.3.1.2.2.1.5

This plugin checks the file system space usage, the CPU load average and the memory usage. Very simple, but maybe somebody will find it usefull. To get information via SNMP I use snmpwalk. I was not sure about python SNMP library and I think to install snmpwalk should be no problem for everybody.

Unfortunately HP-UX doesn’t support hrStorageTable, i.e. we can’t get storage information in tabular form. So, I implement it himself. It looks a bit like “df -h”:

> ./check_snmp_hpux.py 127.0.0.1 public file-systems

    SIZE                USED                AVALIABLE           FILE SYSTEM
==================================================================================                       
    2.0 Gb        765.3 Mb (37.37 %)        1.3 Gb (62.63 %)    /                             
    6.0 Gb         22.9 Mb (0.37 %)         6.0 Gb (99.63 %)    /home                         
   32.0 Gb         11.0 Gb (34.31 %)       21.0 Gb (65.69 %)    /opt                          
    8.0 Gb        444.4 Mb (5.42 %)         7.6 Gb (94.58 %)    /tmp                          
    8.0 Gb          3.1 Gb (38.15 %)        4.9 Gb (61.85 %)    /usr                          
   54.8 Gb         39.5 Gb (72.05 %)       15.3 Gb (27.95 %)    /var                          
   15.0 Gb         11.6 Gb (77.63 %)        3.4 Gb (22.37 %)    /oracle                       
  300.0 Mb        228.6 Mb (76.19 %)       71.4 Mb (23.81 %)    /oracle/origlog               
  300.0 Mb        228.6 Mb (76.19 %)       71.4 Mb (23.81 %)    /oracle/mirrlog               
    1.7 Tb          1.0 Tb (61.17 %)      667.9 Gb (38.83 %)    /oracle/oradata               
  100.0 Gb        129.6 Mb (0.13 %)        99.9 Gb (99.87 %)    /oracle/archives              
   64.0 Gb          3.6 Gb (5.69 %)        60.4 Gb (94.31 %)    /oracle/flash_area        
   15.0 Gb         10.0 Gb (66.96 %)        5.0 Gb (33.04 %)    /oraclog                      
  300.0 Mb        199.7 Mb (66.57 %)      100.3 Mb (33.43 %)    /oraclog/oraclog              
  300.0 Mb        199.7 Mb (66.57 %)      100.3 Mb (33.43 %)    /oraclog/mirrlog              
   12.0 Gb          5.8 Gb (48.63 %)        6.2 Gb (51.37 %)    /oraclog/oradata              
   20.0 Gb         79.7 Mb (0.39 %)        19.9 Gb (99.61 %)    /oraclog/archives             
    2.4 Gb         17.7 Mb (0.72 %)         2.4 Gb (99.28 %)    /oraclog/flash_area

> ./check_snmp_hpux.py 127.0.0.1 public fs:/ 80 90
OK: FS usage 37.37 % [ 765.4 Mb / 2.0 Gb ]|usage=37;80;90;0;100
> echo $?
0

> ./check_snmp_hpux.py 127.0.0.1 public mem 80 90
OK: Memory usage 77.89 % [99.6 Gb / 127.8 Gb]|usage=77;80;90;0;100
> echo $?
0

> ./check_snmp_hpux.py 127.0.0.1 public cpu 1 2
OK: CPU load average 0.18, 0.19, 0.21 |'1 min'=0.18;1.0;2.0;0;0 \
'5 min'=0.19;1.0;2.0;0;0 '15 min'=0.21;1.0;2.0;0;0

As you can see, the output of all checks includes performance data to be able to create graphs in Nagios, Icinga, Centreon or another monitoring tools. In case of CPU check we will get 3 graphs: for 1 min, 5 min and 15 min CPU load average.
CPU_HPUX

If plugin gets no SNMP answer, it returns UNKNOWN status (return code 3).

> ./check_snmp_hpux.py 10.10.22.22 public file-systems
Sorry, no SNMP (hrStorage) answer from 10.10.22.22
> echo $?
3

> ./check_snmp_hpux.py 10.10.22.22 public fs:/ 80 90
UNKNOWN: No SNMP answer from 10.10.22.22
> echo $?
3

> ./check_snmp_hpux.py 10.10.22.22 public mem 80 90
UNKNOWN: No SNMP answer from 10.10.22.22
> echo $?
3

Tested on the HP-UX 11i v3 running on Itanium:

> ./check_snmp_hpux.py 127.0.0.1 public os
HP-UX rasr0177 B.11.31 U ia64 0826591079

This plugin is free software. I use github as a hosting service and development platform. Feel free to ask me about details, report bugs or just give a feedback. Have fun😉

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: