From: Elan Ruusamäe Date: Thu, 28 Mar 2013 13:10:22 +0000 (+0200) Subject: add -i option to invert warning and critical checks X-Git-Tag: auto/th/nagios-plugin-check_elvis_status-0.1-1~4 X-Git-Url: http://git.pld-linux.org/gitweb.cgi?a=commitdiff_plain;h=48c29855738b7f39678e2adb609fefd7f3edadba;p=packages%2Fnagios-plugin-check_elvis_status.git add -i option to invert warning and critical checks --- 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 {