[Nagiosplug-devel] Plugin Wrapper written in python

Joram Agten joram.agten at gmail.com
Mon Nov 12 09:15:19 CET 2012


the last lines of your python program should contain something like
status_code, message = checkNodes()
# print message to stdout
print(message)
# end process with correct exit status
sys.exit(status_code)


On Fri, Nov 9, 2012 at 3:44 PM, Jamin Becker <jaminbecker at gmail.com> wrote:

> 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 at lists.sourceforge.net
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-plugins.org/archive/devel/attachments/20121112/d72ddcd3/attachment.html>


More information about the Devel mailing list