Skip to content

Commit fb4e58b

Browse files
author
drewkerrigan
committed
Adding support for -E, -Q, -w, -c, fixing threshold checking on -m, added UnitTest task, removed -l, -g
1 parent 32a8884 commit fb4e58b

File tree

2 files changed

+288
-140
lines changed

2 files changed

+288
-140
lines changed

README.md

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Add the following command definition to your commands config (`commands.config`)
3737
3838
define command{
3939
command_name <command_name>
40-
command_line /usr/bin/python /usr/local/nagios/libexec/plugins/check_http_json.py -H <host>:<port> -p <path> [-e|-q|-l|-g <rules>] [-m <metrics>]
40+
command_line /usr/bin/python /usr/local/nagios/libexec/plugins/check_http_json.py -H <host>:<port> -p <path> [-e|-q|-w|-c <rules>] [-m <metrics>]
4141
}
4242
4343
```
@@ -49,60 +49,73 @@ More info about options in Usage.
4949
Executing `./check_http_json.py -h` will yield the following details:
5050

5151
```
52-
usage: check_http_json.py [-h] -H HOST [-P PORT] [-B AUTH] [-p PATH] [-D DATA]
52+
usage: check_http_json.py [-h] [-d] [-s] -H HOST [-P PORT] [-p PATH]
53+
[-t TIMEOUT] [-B AUTH] [-D DATA] [-f SEPARATOR]
54+
[-w [KEY_THRESHOLD_WARNING [KEY_THRESHOLD_WARNING ...]]]
55+
[-c [KEY_THRESHOLD_CRITICAL [KEY_THRESHOLD_CRITICAL ...]]]
5356
[-e [KEY_LIST [KEY_LIST ...]]]
57+
[-E [KEY_LIST_CRITICAL [KEY_LIST_CRITICAL ...]]]
5458
[-q [KEY_VALUE_LIST [KEY_VALUE_LIST ...]]]
55-
[-l [KEY_LTE_LIST [KEY_LTE_LIST ...]]]
56-
[-g [KEY_GTE_LIST [KEY_GTE_LIST ...]]]
57-
[-m [METRIC_LIST [METRIC_LIST ...]]] [-s]
58-
[-t TIMEOUT] [-f SEPARATOR] [-d]
59+
[-Q [KEY_VALUE_LIST_CRITICAL [KEY_VALUE_LIST_CRITICAL ...]]]
60+
[-m [METRIC_LIST [METRIC_LIST ...]]]
5961
6062
Nagios plugin which checks json values from a given endpoint against argument
6163
specified rules and determines the status and performance data for that
6264
service
6365
6466
optional arguments:
6567
-h, --help show this help message and exit
68+
-d, --debug Debug mode.
69+
-s, --ssl HTTPS mode.
6670
-H HOST, --host HOST Host.
6771
-P PORT, --port PORT TCP port
72+
-p PATH, --path PATH Path.
73+
-t TIMEOUT, --timeout TIMEOUT
74+
Connection timeout (seconds)
6875
-B AUTH, --basic-auth AUTH
6976
Basic auth string "username:password"
70-
-p PATH, --path PATH Path.
7177
-D DATA, --data DATA The http payload to send as a POST
78+
-f SEPARATOR, --field_separator SEPARATOR
79+
Json Field separator, defaults to "." ; Select element
80+
in an array with "(" ")"
81+
-w [KEY_THRESHOLD_WARNING [KEY_THRESHOLD_WARNING ...]], --warning [KEY_THRESHOLD_WARNING [KEY_THRESHOLD_WARNING ...]]
82+
Warning threshold for these values
83+
(key1[>alias],WarnRange key2[>alias],WarnRange).
84+
WarnRange is in the format [@]start:end, more
85+
information at nagios-plugins.org/doc/guidelines.html.
86+
-c [KEY_THRESHOLD_CRITICAL [KEY_THRESHOLD_CRITICAL ...]], --critical [KEY_THRESHOLD_CRITICAL [KEY_THRESHOLD_CRITICAL ...]]
87+
Critical threshold for these values
88+
(key1[>alias],CriticalRange
89+
key2[>alias],CriticalRange. CriticalRange is in the
90+
format [@]start:end, more information at nagios-
91+
plugins.org/doc/guidelines.html.
7292
-e [KEY_LIST [KEY_LIST ...]], --key_exists [KEY_LIST [KEY_LIST ...]]
7393
Checks existence of these keys to determine status.
94+
Return warning if key is not present.
95+
-E [KEY_LIST_CRITICAL [KEY_LIST_CRITICAL ...]], --key_exists_critical [KEY_LIST_CRITICAL [KEY_LIST_CRITICAL ...]]
96+
Same as -e but return critical if key is not present.
7497
-q [KEY_VALUE_LIST [KEY_VALUE_LIST ...]], --key_equals [KEY_VALUE_LIST [KEY_VALUE_LIST ...]]
7598
Checks equality of these keys and values
7699
(key[>alias],value key2,value2) to determine status.
77100
Multiple key values can be delimited with colon
78-
(key,value1:value2)
79-
-l [KEY_LTE_LIST [KEY_LTE_LIST ...]], --key_lte [KEY_LTE_LIST [KEY_LTE_LIST ...]]
80-
Checks that these keys and values (key[>alias],value
81-
key2,value2) are less than or equal to the returned
82-
json value to determine status.
83-
-g [KEY_GTE_LIST [KEY_GTE_LIST ...]], --key_gte [KEY_GTE_LIST [KEY_GTE_LIST ...]]
84-
Checks that these keys and values (key[>alias],value
85-
key2,value2) are greater than or equal to the returned
86-
json value to determine status.
101+
(key,value1:value2). Return warning if equality check
102+
fails
103+
-Q [KEY_VALUE_LIST_CRITICAL [KEY_VALUE_LIST_CRITICAL ...]], --key_equals_critical [KEY_VALUE_LIST_CRITICAL [KEY_VALUE_LIST_CRITICAL ...]]
104+
Same as -q but return critical if equality check
105+
fails.
87106
-m [METRIC_LIST [METRIC_LIST ...]], --key_metric [METRIC_LIST [METRIC_LIST ...]]
88107
Gathers the values of these keys (key[>alias],UnitOfMe
89-
asure,Min,Max,WarnRange,CriticalRange) for Nagios
108+
asure,WarnRange,CriticalRange,Min,Max) for Nagios
90109
performance data. More information about Range format
91110
and units of measure for nagios can be found at
92111
nagios-plugins.org/doc/guidelines.html Additional
93-
formats for this parameter are: (key),
94-
(key,UnitOfMeasure), (key,UnitOfMeasure,Min,Max).
95-
-s, --ssl HTTPS mode.
96-
-t TIMEOUT, --timeout TIMEOUT
97-
Connection timeout (seconds)
98-
-f SEPARATOR, --field_separator SEPARATOR
99-
Json Field separator, defaults to "." ; Select element
100-
in an array with "(" ")"
101-
-d, --debug Debug mode.
112+
formats for this parameter are: (key[>alias]),
113+
(key[>alias],UnitOfMeasure),
114+
(key[>alias],UnitOfMeasure,WarnRange,CriticalRange).
102115
```
103116

104117
Access a specific JSON field by following this syntax: `alpha.beta.gamma(3).theta.omega(0)`
105-
Dots are field separators (changeable), parantheses are for entering arrays.
118+
Dots are field separators (changeable), parentheses are for entering arrays.
106119

107120
If the root of the JSON data is itself an array like the following:
108121

@@ -153,27 +166,23 @@ Let's say we want to use `check_http_json.py` to read from Docker's `/info` HTTP
153166
`localhost.cfg`
154167

155168
```
156-
157169
define service {
158170
use local-service
159171
host_name localhost
160172
service_description Docker info status checker
161173
check_command check_docker
162174
}
163-
164175
```
165176

166177
#### Command Definition with Arguments
167178

168179
`commands.cfg`
169180

170181
```
171-
172182
define command{
173183
command_name check_docker
174-
command_line /usr/bin/python /usr/local/nagios/libexec/plugins/check_http_json.py -H 127.0.0.1:4243 -p info -e Containers -q IPv4Forwarding,1 -l Debug,2 -g Images,1 -m Containers,,0,1000 Images NEventsListener NFd NGoroutines SwapLimit
184+
command_line /usr/bin/python /usr/local/nagios/libexec/plugins/check_http_json.py -H 127.0.0.1:4243 -p info -e Containers -q IPv4Forwarding,1 -w Debug,2:2 -c Images,1:1 -m Containers,0:250,0:500,0,1000 Images NEventsListener NFd NGoroutines SwapLimit
175185
}
176-
177186
```
178187

179188
#### Sample Output
@@ -201,27 +210,23 @@ OK: Status OK.|'Containers'=1;0;1000 'Images'=11;0;0 'NEventsListener'=3;0;0 'NF
201210
`localhost.cfg`
202211

203212
```
204-
205213
define service {
206214
use local-service
207215
host_name localhost
208216
service_description Docker container liveness check
209217
check_command check_my_container
210218
}
211-
212219
```
213220

214221
#### Command Definition with Arguments
215222

216223
`commands.cfg`
217224

218225
```
219-
220226
define command{
221227
command_name check_my_container
222228
command_line /usr/bin/python /usr/local/nagios/libexec/plugins/check_http_json.py -H 127.0.0.1:4243 -p /containers/2356e8ccb3de8308ccb16cf8f5d157bc85ded5c3d8327b0dfb11818222b6f615/json -q ID,2356e8ccb3de8308ccb16cf8f5d157bc85ded5c3d8327b0dfb11818222b6f615 State.Running,True
223229
}
224-
225230
```
226231

227232
#### Sample Output

0 commit comments

Comments
 (0)