python script return null information

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
denisnav
Posts: 2
Joined: Tue Oct 23, 2018 7:55 am

python script return null information

Post by denisnav »

Hello,
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)
Thanks.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: python script return null information

Post by npolovenko »

Hi, @denisnav. I'd like to see what the total value looks like. Try changing the line to look like this:
total=float(total)
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
denisnav
Posts: 2
Joined: Tue Oct 23, 2018 7:55 am

Re: python script return null information

Post by denisnav »

Hi @npolovenko,
The result of total=float(total) is 5119.0 and now nagios gets good information in the web interface. I suppose it's was because I compared integer with float. Thank you very much.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: python script return null information

Post by npolovenko »

@denisnav, Glad to hear! I will be closing this thread as resolved.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked