Search code examples
python-2.7nagios

Nagios Python return null


I have a problem with a script in python which use bash command (I didn't resolve this problem so I tried to do the same with Python). I get the disk space in a variable with this command:

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].split("\n")

I get the value OK e:: 4.701TB/5TB used|'e: free'=306.11612G;20;5;0;5119.87206 'e: free %'=6%;0;0;0;100\n. So I use this command to get only the disk size (I know it's not clean but I'm not a expert in Python):

total=int(str(total).split()[3].split(',')[0])

But when I add this line to the script, Nagios return "null" as information. When I run the script manually it works and when I comment this line it works too in Nagios interface. I need this value to modify warning and critical threshold depending on the size of the disk.

I don't understand because I don't return this value, I use it just in the script to execute another command with an IF :

if total < 2.05 :
            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)"])
    elif total >= 2.05 and total < 99.99.......

Solution

  • Someone from another forum give me the solution.I have to use float() and not int() because I compare the variable with float after.