diff --git a/check_other/README b/check_other/README new file mode 100644 index 0000000..34b9524 --- /dev/null +++ b/check_other/README @@ -0,0 +1,14 @@ +check_other +=========== + +This plugin is designed to execute another plugin that is given as an argument. + +Usually you want this to use the perfdata parsing of pynag and you want to alert on specific thresholds in the other plugin. + +Usage: +``` +check_other -- check_nrpe -H localhost -c check_load + +# Same as above, but alert on performance metric load1 +check_other --threshold metric=load1,warn=2..inf -- check_nrpe -H localhost -c check_load +``` diff --git a/check_other/check_other b/check_other/check_other new file mode 100644 index 0000000..c30013c --- /dev/null +++ b/check_other/check_other @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# This script runs whatever command is printed on the command line +# Usage: +# ./check_other -- someotherplugin --arguments-for-the-other-plugin +# +# Example: +# ./check_other -- check_nrpe -H localhost +# +# If you want to provide options to check_other (for example to enforce a threshold: +# ./check_other --threshold=load1,warn=5..inf -- check_nrpe -H localhost check_load + + +import subprocess +import sys + +from pynag.Plugins import PluginHelper +from pynag.Utils import runCommand, PluginOutput, PerfData + +p = PluginHelper() + +p.parser.add_option('--string', dest='string', help='run this command (will be shell expanded, use quotes)') +p.parse_arguments() + + +# --string was provided +if p.options.string: + return_code, stdout, stderr = runCommand(p.options.string) +# No --string, and no arguments on the command line +elif not p.arguments: + p.parser.error("You need to provide an external command as an argument. Try: %s ls" % sys.argv[0]) +# some arguments were provided +else: + try: + proc = subprocess.Popen(p.arguments, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE,) + stdout, stderr = proc.communicate('through stdin to stdout') + return_code = proc.returncode + except Exception, e: + p.set_summary("Failed to execute '%s': %s " % (p.arguments[0], e)) + p.status(3) + p.exit() + +p.status(return_code) +other = PluginOutput(stdout) + +p.set_summary(other.summary) +p.set_long_output(other.long_output) +p._perfdata = PerfData(other.perfdata) + +p.check_all_metrics() +p.exit()