Custom Python plugin returns NULL


#1

Hi all,

I have written a Python plugin to check our NetApp devices using SNMP. If I run it on the command line on my linux Nagios server it runs fine:

[root@monitor netapp-snmp]# /opt/nagios/libexec/check_netapp_disks.py -H netapp1 -o /vol/test1/ -w 80 -c 90
OK - /vol/test1/ - total: 250 Gb - used 6 Gb (2%) - free: 243 Gb|NetApp /vol/gate/ Used Space=6GB;160;180;0;250

But when I add it in to Nagios commands.cfg it returns “null” in the Nagios GUI:

define command{
command_name check-swe-test
command_line $USER1$/check_netapp_disks.py -H netapp1 -o /vol/test1/ -w 80 -c 90
}

For the return codes I use sys.exit in Python (0 for OK, 1 for Warning, 2 for Critical). I have written custom plugins before in shell scripts but this is my first Python one. Not sure where the issue would be exactly.

Here is the if-else where i specify the return code:

if state == 'OK': print '%s - %s - total: %s Gb - used %s Gb (%s%%) - free: %s Gb|NetApp %s Used Space=%sGB;%s;%s;0;%s' % (state, volume, total, used, used_p, avail, volume, used, warn_p, crit_p, total) sys.exit(0) elif state == 'WARNING': print '%s - %s - total: %s Gb - used %s Gb (%s%%) - free: %s Gb|NetApp %s Used Space=%sGB;%s;%s;0;%s' % (state, volume, total, used, used_p, avail, volume, used, warn_p, crit_p, total) sys.exit(1) elif state == 'CRITICAL': print '%s - %s - total: %s Gb - used %s Gb (%s%%) - free: %s Gb|NetApp %s Used Space=%sGB;%s;%s;0;%s' % (state, volume, total, used, used_p, avail, volume, used, warn_p, crit_p, total) sys.exit(2) else: sys.exit(3)

Thanks!


#2

try running the plugin from command line and then run
echo $?
to see what exit code it’s using…

if it returs NULL you probably had no output from the script?


#3

Hi Luca,

It looks like the script returns the error code:

[root@unixmonitor objects]# /opt/nagios/libexec/check_netapp_disks.py -H netapp -o /vol/test/ -w 80 -c 90 [root@unixmonitor objects]# echo $? 0

If I change the warning threshold:

[root@unixmonitor objects]# /opt/nagios/libexec/check_netapp_disks.py -H netapp -o /vol/test/ -w 1 -c 90 [root@unixmonitor objects]# echo $? 1

And if I change the critical threshold it returns 2:

[root@unixmonitor objects]# /opt/nagios/libexec/check_netapp_disks.py -H netapp -o /vol/test/ -w 1 -c 1 [root@unixmonitor objects]# echo $? 2

These are the correct return codes right?


#4

it looks like the plugin works correctly.

are you sure it is being run correctly from nagios? try running it as user nagios from command line.


#5

Here I am logged in as Nagios user and with the output enabled:

[nagios@unixmonitor ~]$ /opt/nagios/libexec/check_netapp_disks.py -H netapp -o /vol/test/ -w 50 -c 90 OK - /vol/test/ - total: 250 Gb - used 6 Gb (2%) - free: 243 Gb|NetApp /vol/test/ Used Space=6GB;100;180;0;250 [nagios@unix-monitor ~]$ echo $? 0 [nagios@unixmonitor ~]$ /opt/nagios/libexec/check_netapp_disks.py -H netapp -o /vol/test/ -w 1 -c 90 WARNING - /vol/test/ - total: 250 Gb - used 6 Gb (2%) - free: 243 Gb|NetApp /vol/test/ Used Space=6GB;2;180;0;250 [nagios@unix-monitor ~]$ echo $? 1 [nagios@unixmonitor ~]$ /opt/nagios/libexec/check_netapp_disks.py -H netapp -o /vol/test/ -w 1 -c 1 CRITICAL - /vol/test/ - total: 250 Gb - used 6 Gb (2%) - free: 243 Gb|NetApp /vol/test/ Used Space=6GB;2;2;0;250 [nagios@unix-monitor ~]$ echo $? 2

This is the entry in nagios.log:

I think I’ve covered all bases with this. Can’t think of anything else that I may have missed which why this wont work.


#6

last thing which comes to mind:

$USER1$ is /opt/nagios/libexec?


#7

Yep it is indeed:

$USER1$=/opt/nagios/libexec

To be honest it’s not critical as there is a Perl script I am using which works. It’s just that I decided to create a Python script as I am learning Python just for the hell of it. I might create something more simple and see if that works. Could be a Nagios + Python thing? Although I can’t see why. Thanks for your help luca :slight_smile:


#8

i used shell scripts the only time i created a “plugin” so i really can’t help you there… :slight_smile:

It’s still worth a couple of extra tries maybe reducing it to something basic and seeing what happens…

Have fun testing :slight_smile:

Luca