I wrote a script in python to get the freedisk space with check_nrpe (bash command). the problem is when I want to convert a string to integer with int(), I see in nagios web interface "null" in information. When I run manually the script in a shell, it works. When I remove the function int(), nagios gets informations on the disk space (but the IF condition doesn't work of course). Below my script :
Code: Select all
#!/usr/bin/env python
import os, traceback, threading, sys
import subprocess as sp
host=sys.argv[1]
lecteur=sys.argv[2]
def main(host, lecteur):
total=sp.Popen(["/srv/eyesofnetwork/nagios/plugins/check_nt", "-H", host, "-p", "12489", "-s", '', "-v", "USEDDISKSPACE", "-l", lecteur], stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE).communicate()[0]
total=str(total).split()[3].split(',')[0]
total=int(total)
#print "total: %s" % total
if total < 2.05 :
resultat=sp.Popen(["/srv/eyesofnetwork/nagios-3.5.1/plugins/check_nrpe", "-H", host, "-c", "check_drivesize", "-a", "drive=" + lecteur, "warning=free<0.2G", "critical=free<0.1G", "show-all", "perf-config=*(unit:G)"], stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE).communicate()[0]
res=str(resultat).split()[0]
if 'CRITICAL' in res:
print resultat
sys.exit(2)
elif 'WARNING' in res:
print resultat
sys.exit(1)
else:
print resultat
sys.exit(0)
elif total >= 2.05 and total < 99.99:
resultat=sp.Popen(["/srv/eyesofnetwork/nagios-3.5.1/plugins/check_nrpe", "-H", host, "-c", "check_drivesize", "-a", "drive=" + lecteur, "warning=free<2G", "critical=free<1G", "show-all", "perf-config=*(unit:G)"], stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE).communicate()[0]
res=str(resultat).split()[0]
if 'CRITICAL' in res:
print resultat
sys.exit(2)
elif 'WARNING' in res:
print resultat
sys.exit(1)
else:
print resultat
sys.exit(0)
elif total >= 99.99 and total < 450.99 :
resultat=sp.Popen(["/srv/eyesofnetwork/nagios-3.5.1/plugins/check_nrpe", "-H", host, "-c", "check_drivesize", "-a", "drive=" + lecteur, "warning=free<5G", "critical=free<2G", "show-all", "perf-config=*(unit:G)"], stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE).communicate()[0]
res=str(resultat).split()[0]
if 'CRITICAL' in res:
print resultat
sys.exit(2)
elif 'WARNING' in res:
print resultat
sys.exit(1)
else:
print resultat
sys.exit(0)
elif total >= 450.99 and total < 950.99 :
resultat=sp.Popen(["/srv/eyesofnetwork/nagios-3.5.1/plugins/check_nrpe", "-H", host, "-c", "check_drivesize", "-a", "drive=" + lecteur, "warning=free<200G", "critical=free<50G", "show-all", "perf-config=*(unit:G)"], stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE).communicate()[0]
res=str(resultat).split()[0]
if 'CRITICAL' in res:
print resultat
sys.exit(2)
elif 'WARNING' in res:
print resultat
sys.exit(1)
else:
print resultat
sys.exit(0)
main(host, lecteur)