[Nagiosplug-devel] Plugin Wrapper written in python

Jamin Becker jaminbecker at gmail.com
Fri Nov 9 15:44:08 CET 2012


The other day I wrote a sort of wrapper that uses Nagios' check_icmp plugin
to monitor several nodes on our network. If any one of the nodes down it
returns a value of 1 (WARNING), if two or more nodes go down it returns a
value of 2 (CRITICAL).

Unfortunately, even if it is critical it still shows up as Ok...even though
I know it is returning a value of 2. The plugin is written in python.

#!/usr/bin/env python
import os
import subprocess
home="/usr/lib/nagios/plugins"

def checkNodes():
        up = 0
        aProblemsDetected=0
        bProblemsDetected=0
        cProblemsDetected=0
        status=0
    message=" - "
        TEST_OK=0
           TEST_WARNING=1
        TEST_CRITICAL=2
        TEST_UKNOWN=3
        try:

cloud_alpha_status=subprocess.check_output(home+"/check_icmp -H cloud-alpha
",shell=True)
                if "OK" in cloud_alpha_status:
                        ++up

                else:
                        message=message+ "Cloud Bravo does not seem to be
reachable. "
                        aProblemsDetected=1

        except:
                message=message+"Node (Cloud-Alpha) is either down or
unreachable. "
        aProblemsDetected=1
        try:

cloud_bravo_status=subprocess.check_output(home+"/check_icmp -H
cloud-bravo",shell=True)
                if "OK" in cloud_bravo_status:
                        ++up
                else:
                        print cloud_bravo_status
                        message=message+"Cloud Bravo does not seem to be
reachable. "
                        bProblemsDetected=1
        except:
                message=message+"Node (Cloud-Bravo) is either down or
unreachable. "
                bProblemsDetected=1
        try:

cloud_charlie_status=subprocess.check_output(home+"/check_icmp -H
cloud-charlie",shell=True)
                if "OK" in cloud_charlie_status:
                        ++up
                else:
                        print cloud_charlie_status
                        message=message+"Cloud Charlie does not seem to be
reachable. "
                        cProblemsDetected=1
        except:
                print "Node (Cloud-Charlie) is either down or unreachable. "
                cProblemsDetected=1

        if aProblemsDetected+bProblemsDetected+cProblemsDetected==0:
                status=TEST_OK
                message=message+"CLUSTER IS UP! -- Cloud-Alpha up --
Cloud-Bravo up -- Cloud-Charlie up"
        code='OK'
        if aProblemsDetected+bProblemsDetected+cProblemsDetected==1:
                status=TEST_WARNING
        code='WARNING'
                message="Errors Detected:"+message
        elif aProblemsDetected+bProblemsDetected+cProblemsDetected>1:
                status=TEST_CRITICAL
                message="Many Errors Detected"+message
        code='CRITICAL'
        return status,(code+' '+message)

print checkNodes()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nagios-plugins.org/archive/devel/attachments/20121109/2a937603/attachment.html>


More information about the Devel mailing list