nagios-http-json
nagios-http-json copied to clipboard
Multiple keys equals only take the last comparison into account
Hello!
It seems the check only takes the last comparison into account when multiple key equals are used:
This ist OK, while the first test failed:
>> ./check_http_json.py -H "fqdn" -p "api/v1/status/info" -s -k -v -q "a_available,Blah" -q "b_available,True"
{
"api_version": "1.2.3.4",
"server_name": "hostname",
"a_available": true,
"b_available": true
}
OK: Status OK.
But it becomes WARNING if the last test fails:
>> ./check_http_json.py -H "fqdn" -p "api/v1/status/info" -s -k -v -q "a_available,True" -q "b_available,Blah"
{
"api_version": "1.2.3.4",
"server_name": "hostname",
"a_available": true,
"b_available": true
}
WARNING: Status WARNING. Key b_available mismatch. Blah != True
When both tests fail, the output only mentions the last test:
>> ./check_http_json.py -H "fqdn" -p "api/v1/status/info" -s -k -v -q "a_available,Blah" -q "b_available,Blah"
{
"api_version": "1.2.3.4",
"server_name": "hostname",
"a_available": true,
"b_available": true
}
WARNING: Status WARNING. Key b_available mismatch. Blah != True
I whould expect the first failed test in the line of arguments to be mentioned. This leads me to the asumption, that only the last comparison matters.
This behavior happens with:
--key_equals (q)
--key_equals_critical (Q)
Tested with version 2.3.0.
Hi, can you give this a try? https://github.com/drewkerrigan/nagios-http-json/tree/fix/multiple-flags
Not final yet, since the same probably applies to other flags as well, but I haven't had the time to fully test this.
Thanks for your effort. I will give feedback next week. Meanwhile happy easter to you and all colleagues! 🐰
We tested with -q and -Q and it works. Do need some other keys to be tested as well?
@K0nne I assume we also need to change the other flags. If you have the setup and time to test this that would be great.
The check is well-used in our setup. I can help.
With icinga2 and lists I use repeat_key = false and an array for each element:
"-Q" = {
value = "$http_json_key_equals_critical$"
repeat_key = false
description = "Check key/value equality (critical if fails)"
}
http_json_key_equals_critical = ["states.mongodb,ok", "states.tasks,ok", "errors,[]"]
I use this:
arguments = {
"-d" = {
set_if = "$http_json_debug$"
description = "Enable debug mode"
}
"-v" = {
repeat_key = true
set_if = "$http_json_verbose$"
description = "Increase verbosity (can be repeated)"
}
"-s" = {
set_if = "$http_json_ssl$"
description = "Use TLS to connect to remote host"
}
"-H" = {
value = "$http_json_host$"
description = "Remote host to query"
}
"-k" = {
set_if = "$http_json_insecure$"
description = "Do not check server SSL certificate"
}
"-X" = {
value = "$http_json_request$"
description = "Custom request method (GET or POST)"
}
"--base64" = {
value = "$http_json_base64$"
description = "JSON path to base64 encoded content (dot notation, e.g., data.content)"
}
"--cacert" = {
value = "$http_json_cacert$"
description = "SSL CA certificate"
}
"--cert" = {
value = "$http_json_cert$"
description = "SSL client certificate"
}
"--key" = {
value = "$http_json_key$"
description = "SSL client key (if not bundled into cert)"
}
"-P" = {
value = "$http_json_port$"
description = "TCP port"
}
"-p" = {
value = "$http_json_path$"
description = "Path"
}
"-t" = {
value = "$http_json_timeout$"
description = "Connection timeout (seconds)"
}
"--unreachable-state" = {
value = "$http_json_unreachable_state$"
description = "Exit code when URL is unreachable (1=Warning, 2=Critical, 3=Unknown)"
}
"--invalid-json-state" = {
value = "$http_json_invalid_json_state$"
description = "Exit code when no valid JSON is returned (1=Warning, 2=Critical, 3=Unknown)"
}
"-B" = {
value = "$http_json_basic_auth$"
description = "Basic auth string 'username:password'"
}
"-D" = {
value = "$http_json_data$"
description = "HTTP payload to send as POST"
}
"-A" = {
value = "$http_json_headers$"
description = "HTTP headers in JSON format"
}
"-f" = {
value = "$http_json_field_separator$"
description = "JSON field separator (default: '.')"
}
"-F" = {
value = "$http_json_value_separator$"
description = "JSON value separator (default: ':')"
}
"-w" = {
value = "$http_json_warning$"
repeat_key = false
description = "Warning thresholds for keys (key1[>alias],WarnRange ...)"
}
"-c" = {
value = "$http_json_critical$"
repeat_key = false
description = "Critical thresholds for keys (key1[>alias],CriticalRange ...)"
}
"-e" = {
value = "$http_json_key_exists$"
repeat_key = false
description = "Check existence of keys (warning if missing)"
}
"-E" = {
value = "$http_json_key_exists_critical$"
repeat_key = false
description = "Check existence of keys (critical if missing)"
}
"-q" = {
value = "$http_json_key_equals$"
repeat_key = false
description = "Check key/value equality (warning if fails)"
}
"-Q" = {
value = "$http_json_key_equals_critical$"
repeat_key = false
description = "Check key/value equality (critical if fails)"
}
"--key_time" = {
value = "$http_json_key_time$"
repeat_key = false
description = "Check timestamp age of keys (warning if too old/young)"
}
"--key_time_critical" = {
value = "$http_json_key_time_critical$"
repeat_key = false
description = "Check timestamp age of keys (critical if too old/young)"
}
"-u" = {
value = "$http_json_key_equals_unknown$"
repeat_key = false
description = "Check key/value equality (unknown if fails)"
}
"-y" = {
value = "$http_json_key_not_equals$"
repeat_key = false
description = "Check key/value inequality (warning if equals)"
}
"-Y" = {
value = "$http_json_key_not_equals_critical$"
repeat_key = false
description = "Check key/value inequality (critical if equals)"
}
"-m" = {
value = "$http_json_key_metric$"
repeat_key = false
description = "Gather key values for Nagios performance data"
}
}
I assume we also need to change the other flags.
You were right. At least -m (--metric-list) is also affected.
Thanks for testing it. I'll update the flags