Plugin Wrapper written in python

Jamin Becker <[email protected]>
Newsgroups gmane.network.nagios.plugins.devel
Message-ID <CALuvoQUcfWwB93zmvyjDyT--fq_4dibnE16Si69k_-4DiayWZA@mail.gmail.com>
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()

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_nov

_______________________________________________________
Nagios Plugin Development Mailing List Nagiosplug-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Unsubscribe at https://lists.sourceforge.net/lists/listinfo/nagiosplug-devel
::: Please include plugins version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.