From 27eaaf084263bb7d38de1621449e4e22a1b49dd8 Mon Sep 17 00:00:00 2001 From: Martin Sura Date: Tue, 7 May 2019 16:15:31 +0200 Subject: [PATCH 1/4] Add unknown option --- check_http_json.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/check_http_json.py b/check_http_json.py index dac67ec..8701f21 100755 --- a/check_http_json.py +++ b/check_http_json.py @@ -224,6 +224,12 @@ class JsonRuleProcessor: failure += self.checkExists(self.rules.key_list_critical) return failure + def checkUnknown(self): + unknown = '' + if self.rules.key_value_list_unknown != None: + unknown += self.checkEquality(self.rules.key_value_list_unknown) + return unknown + def checkMetrics(self): """Return a Nagios specific performance metrics string given keys and parameter definitions""" metrics = '' @@ -291,6 +297,8 @@ def parseArgs(): Multiple key values can be delimited with colon (key,value1:value2). Return warning if equality check fails') parser.add_argument('-Q', '--key_equals_critical', dest='key_value_list_critical', nargs='*', help='Same as -q but return critical if equality check fails.') + parser.add_argument('-u', '--key_equals_unknown', dest='key_value_list_unknown', nargs='*', + help='Same as -q but return unknown if equality check fails.') parser.add_argument('-m', '--key_metric', dest='metric_list', nargs='*', help='Gathers the values of these keys (key[>alias],UnitOfMeasure,WarnRange,CriticalRange,Min,Max) for Nagios performance data.\ More information about Range format and units of measure for nagios can be found at nagios-plugins.org/doc/guidelines.html\ @@ -437,6 +445,7 @@ if __name__ == "__main__": nagios.append_warning(processor.checkWarning()) nagios.append_critical(processor.checkCritical()) nagios.append_metrics(processor.checkMetrics()) + nagios.append_unknown(processor.checkUnknown()) # Print Nagios specific string and exit appropriately print nagios.getMessage() exit(nagios.getCode()) From 81522fa9ab6a416a956ed7fc9408d46afe57ebcb Mon Sep 17 00:00:00 2001 From: Martin Sura Date: Tue, 7 May 2019 16:23:48 +0200 Subject: [PATCH 2/4] fix intedation --- check_http_json.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/check_http_json.py b/check_http_json.py index 8701f21..be4a6f7 100755 --- a/check_http_json.py +++ b/check_http_json.py @@ -227,8 +227,8 @@ class JsonRuleProcessor: def checkUnknown(self): unknown = '' if self.rules.key_value_list_unknown != None: - unknown += self.checkEquality(self.rules.key_value_list_unknown) - return unknown + unknown += self.checkEquality(self.rules.key_value_list_unknown) + return unknown def checkMetrics(self): """Return a Nagios specific performance metrics string given keys and parameter definitions""" From 3a108aef5e1390cf1d8e1b9fd82fdf20323464f4 Mon Sep 17 00:00:00 2001 From: luban8 <44843692+luban8@users.noreply.github.com> Date: Tue, 7 May 2019 16:25:00 +0200 Subject: [PATCH 3/4] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 63c06c5..a0d05cb 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,8 @@ optional arguments: -Q [KEY_VALUE_LIST_CRITICAL [KEY_VALUE_LIST_CRITICAL ...]], --key_equals_critical [KEY_VALUE_LIST_CRITICAL [KEY_VALUE_LIST_CRITICAL ...]] Same as -q but return critical if equality check fails. + -u Same as -Q but return critical if equality check + fails. -m [METRIC_LIST [METRIC_LIST ...]], --key_metric [METRIC_LIST [METRIC_LIST ...]] Gathers the values of these keys (key[>alias],UnitOfMe asure,WarnRange,CriticalRange,Min,Max) for Nagios From cbdb884dc77586448118a05f3cd28f701fbd5657 Mon Sep 17 00:00:00 2001 From: luban8 <44843692+luban8@users.noreply.github.com> Date: Tue, 7 May 2019 16:27:56 +0200 Subject: [PATCH 4/4] Update README.md --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a0d05cb..c409ef5 100644 --- a/README.md +++ b/README.md @@ -70,10 +70,9 @@ optional arguments: (key,value1:value2). Return warning if equality check fails -Q [KEY_VALUE_LIST_CRITICAL [KEY_VALUE_LIST_CRITICAL ...]], --key_equals_critical [KEY_VALUE_LIST_CRITICAL [KEY_VALUE_LIST_CRITICAL ...]] - Same as -q but return critical if equality check - fails. - -u Same as -Q but return critical if equality check - fails. + Same as -q but return critical if equality check fails. + -u [KEY_VALUE_LIST_UNKNOWN [KEY_VALUE_LIST_UNKNOWN --key_equals_unknown [KEY_VALUE_LIST_UNKNOWN [KEY_VALUE_LIST_UNKNOWN ...]] + Same as -Q but return unknown if equality check fails. -m [METRIC_LIST [METRIC_LIST ...]], --key_metric [METRIC_LIST [METRIC_LIST ...]] Gathers the values of these keys (key[>alias],UnitOfMe asure,WarnRange,CriticalRange,Min,Max) for Nagios