[packages/nagios-plugin-check_elvis_status] add -i option to invert warning and critical checks

glen glen at pld-linux.org
Thu Mar 28 14:10:35 CET 2013


commit 48c29855738b7f39678e2adb609fefd7f3edadba
Author: Elan Ruusamäe <glen at delfi.ee>
Date:   Thu Mar 28 15:10:22 2013 +0200

    add -i option to invert warning and critical checks

 check_elvis_status.php | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/check_elvis_status.php b/check_elvis_status.php
index e258005..21d9603 100755
--- a/check_elvis_status.php
+++ b/check_elvis_status.php
@@ -37,6 +37,7 @@ Plugin action specific options:
   -u    URL to Elvis DAM /server-status. Sample: http://USERNAME:PASSWORD@HOSTNAME/dam/controller/admin/server-status
   -m    Message what you are querying
   -e    Expression what to retrieve from json data. this must be valid PHP Expression
+  -i    Invert expression, critical and warning must be below the tresholds
   -w    The warning range. default '{$opt['w']}'
   -c    The critical range. default '{$opt['c']}'
   -v    Enable verbose mode.
@@ -52,7 +53,8 @@ $default_opt = array(
 	'w' => 0,
 	'c' => 0,
 );
-$opt = array_merge($default_opt, getopt("u:e:m:w:c:v"));
+$opt = array_merge($default_opt, getopt("u:e:m:w:c:vi"));
+$invert = isset($opt['i']);
 
 if (empty($opt['u']) || !isset($opt['e'])) {
 	usage();
@@ -82,10 +84,10 @@ if ($res === null) {
 } elseif ($res === false) {
 	echo LABEL, ": ERROR: {$opt['m']}: parse error: {$opt['e']}\n";
 	exit(STATE_UNKNOWN);
-} elseif ($res > $opt['c']) {
+} elseif ((!$invert && $res > $opt['c']) || ($invert && $res < $opt['c']))  {
 	echo LABEL, ": CRITICAL: {$opt['m']}: $res\n";
 	exit(STATE_CRITICAL);
-} elseif ($res > $opt['w']) {
+} elseif ((!$invert && $res > $opt['w']) || ($invert && $res < $opt['w'])) {
 	echo LABEL, ": WARNING: {$opt['m']}: $res\n";
 	exit(STATE_WARNING);
 } else {
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/nagios-plugin-check_elvis_status.git/commitdiff/48c29855738b7f39678e2adb609fefd7f3edadba



More information about the pld-cvs-commit mailing list