2020-03-03 09:49:40 +01:00
![CI ](https://github.com/drewkerrigan/nagios-http-json/workflows/CI/badge.svg )
2014-03-10 16:36:17 +01:00
# Nagios Json Plugin
2014-03-10 16:30:37 +01:00
2014-03-10 16:36:17 +01:00
This is a generic plugin for Nagios which checks json values from a given HTTP endpoint against argument specified rules and determines the status and performance data for that service.
2015-11-19 19:49:24 +01:00
## Links
2014-03-10 16:36:17 +01:00
2015-11-19 19:49:24 +01:00
* [CLI Usage ](#cli-usage )
* [Examples ](#examples )
* [Riak Stats ](docs/RIAK.md )
* [Docker ](docs/DOCKER.md )
* [Nagios Installation ](#nagios-installation )
2014-03-10 16:36:17 +01:00
2015-11-19 19:49:24 +01:00
## CLI Usage
2014-03-10 16:36:17 +01:00
Executing `./check_http_json.py -h` will yield the following details:
```
2019-05-09 15:48:29 +02:00
usage: check_http_json.py [-h] [-d] [-s] -H HOST [-k] [-V] [--cacert CACERT]
[--cert CERT] [--key KEY] [-P PORT] [-p PATH]
2016-01-08 16:21:00 +01:00
[-t TIMEOUT] [-B AUTH] [-D DATA] [-A HEADERS]
[-f SEPARATOR]
2015-11-19 05:07:50 +01:00
[-w [KEY_THRESHOLD_WARNING [KEY_THRESHOLD_WARNING ...]]]
[-c [KEY_THRESHOLD_CRITICAL [KEY_THRESHOLD_CRITICAL ...]]]
2014-03-10 16:36:17 +01:00
[-e [KEY_LIST [KEY_LIST ...]]]
2015-11-19 05:07:50 +01:00
[-E [KEY_LIST_CRITICAL [KEY_LIST_CRITICAL ...]]]
2014-03-10 16:36:17 +01:00
[-q [KEY_VALUE_LIST [KEY_VALUE_LIST ...]]]
2015-11-19 05:07:50 +01:00
[-Q [KEY_VALUE_LIST_CRITICAL [KEY_VALUE_LIST_CRITICAL ...]]]
2019-05-09 15:48:29 +02:00
[-u [KEY_VALUE_LIST_UNKNOWN [KEY_VALUE_LIST_UNKNOWN ...]]]
[-y [KEY_VALUE_LIST_NOT [KEY_VALUE_LIST_NOT ...]]]
[-Y [KEY_VALUE_LIST_NOT_CRITICAL [KEY_VALUE_LIST_NOT_CRITICAL ...]]]
2015-11-19 05:07:50 +01:00
[-m [METRIC_LIST [METRIC_LIST ...]]]
2014-03-10 16:36:17 +01:00
2019-05-09 15:48:29 +02:00
Check HTTP JSON Nagios Plugin
Generic Nagios plugin which checks json values from a given endpoint against
argument specified rules and determines the status and performance data for
that service.
Version: 1.4.0 (2019-05-09)
2014-03-10 16:36:17 +01:00
optional arguments:
-h, --help show this help message and exit
2019-05-09 15:48:29 +02:00
-d, --debug debug mode
-s, --ssl use TLS to connect to remote host
-H HOST, --host HOST remote host to query
-k, --insecure do not check server SSL certificate
-V, --version print version of this plugin
--cacert CACERT SSL CA certificate
--cert CERT SSL client certificate
--key KEY SSL client key ( if not bundled into the cert )
2015-07-13 17:05:27 +02:00
-P PORT, --port PORT TCP port
2019-05-09 15:48:29 +02:00
-p PATH, --path PATH Path
2015-11-19 05:07:50 +01:00
-t TIMEOUT, --timeout TIMEOUT
Connection timeout (seconds)
2015-04-24 17:38:27 +02:00
-B AUTH, --basic-auth AUTH
Basic auth string "username:password"
2015-11-16 05:50:12 +01:00
-D DATA, --data DATA The http payload to send as a POST
2016-01-08 16:21:00 +01:00
-A HEADERS, --headers HEADERS
The http headers in JSON format.
2015-11-19 05:07:50 +01:00
-f SEPARATOR, --field_separator SEPARATOR
2019-05-09 15:48:29 +02:00
JSON Field separator, defaults to "."; Select element
2015-11-19 05:07:50 +01:00
in an array with "(" ")"
-w [KEY_THRESHOLD_WARNING [KEY_THRESHOLD_WARNING ...]], --warning [KEY_THRESHOLD_WARNING [KEY_THRESHOLD_WARNING ...]]
Warning threshold for these values
(key1[>alias],WarnRange key2[>alias],WarnRange).
WarnRange is in the format [@]start:end, more
information at nagios-plugins.org/doc/guidelines.html.
-c [KEY_THRESHOLD_CRITICAL [KEY_THRESHOLD_CRITICAL ...]], --critical [KEY_THRESHOLD_CRITICAL [KEY_THRESHOLD_CRITICAL ...]]
Critical threshold for these values
(key1[>alias],CriticalRange
key2[>alias],CriticalRange. CriticalRange is in the
format [@]start:end, more information at nagios-
plugins.org/doc/guidelines.html.
2014-03-10 16:36:17 +01:00
-e [KEY_LIST [KEY_LIST ...]], --key_exists [KEY_LIST [KEY_LIST ...]]
2015-11-16 05:50:12 +01:00
Checks existence of these keys to determine status.
2015-11-19 05:07:50 +01:00
Return warning if key is not present.
-E [KEY_LIST_CRITICAL [KEY_LIST_CRITICAL ...]], --key_exists_critical [KEY_LIST_CRITICAL [KEY_LIST_CRITICAL ...]]
Same as -e but return critical if key is not present.
2014-03-10 16:36:17 +01:00
-q [KEY_VALUE_LIST [KEY_VALUE_LIST ...]], --key_equals [KEY_VALUE_LIST [KEY_VALUE_LIST ...]]
2015-11-16 05:50:12 +01:00
Checks equality of these keys and values
(key[>alias],value key2,value2) to determine status.
Multiple key values can be delimited with colon
2015-11-19 05:07:50 +01:00
(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 ...]]
2019-05-09 15:48:29 +02:00
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.
-y [KEY_VALUE_LIST_NOT [KEY_VALUE_LIST_NOT ...]], --key_not_equals [KEY_VALUE_LIST_NOT [KEY_VALUE_LIST_NOT ...]]
Checks equality of these keys and values
(key[>alias],value key2,value2) to determine status.
Multiple key values can be delimited with colon
(key,value1:value2). Return warning if equality check
succeeds
-Y [KEY_VALUE_LIST_NOT_CRITICAL [KEY_VALUE_LIST_NOT_CRITICAL ...]], --key_not_equals_critical [KEY_VALUE_LIST_NOT_CRITICAL [KEY_VALUE_LIST_NOT_CRITICAL ...]]
Same as -q but return critical if equality check
succeeds.
2014-03-10 16:36:17 +01:00
-m [METRIC_LIST [METRIC_LIST ...]], --key_metric [METRIC_LIST [METRIC_LIST ...]]
2019-05-09 15:48:29 +02:00
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
2015-11-16 05:50:12 +01:00
nagios-plugins.org/doc/guidelines.html Additional
2015-11-19 05:07:50 +01:00
formats for this parameter are: (key[>alias]),
(key[>alias],UnitOfMeasure),
2019-05-09 15:48:29 +02:00
(key[>alias],UnitOfMeasure,WarnRange, CriticalRange).
2014-03-10 16:36:17 +01:00
```
2015-11-19 19:49:24 +01:00
## Examples
2015-05-05 13:58:09 +02:00
2015-11-19 19:49:24 +01:00
### Key Naming
2015-05-06 18:17:00 +02:00
2015-11-19 19:52:54 +01:00
**Data for key** `value` :
2015-05-06 18:17:00 +02:00
2015-11-19 19:49:24 +01:00
{ "value": 1000 }
2015-05-06 18:17:00 +02:00
2015-11-19 19:52:54 +01:00
**Data for key** `capacity.value` :
2014-03-10 16:36:17 +01:00
2015-11-19 19:49:24 +01:00
{
"capacity": {
"value": 1000
}
}
2014-03-10 16:36:17 +01:00
2015-11-19 19:52:54 +01:00
**Data for key** `(0).capacity.value` :
2014-03-10 16:36:17 +01:00
2015-11-19 19:49:24 +01:00
[
{
"capacity": {
"value": 1000
}
}
]
2014-03-10 16:36:17 +01:00
2020-02-01 21:47:08 +01:00
**Data for keys of all items in a list** `(*).capacity.value` :
[
{
"capacity": {
"value": 1000
}
},
{
"capacity": {
"value": 2200
}
}
]
2015-11-19 19:52:54 +01:00
**Data for separator** `-f _` **and key** `(0)_gauges_jvm.buffers.direct.capacity_value` :
2014-03-10 16:36:17 +01:00
2015-11-19 19:49:24 +01:00
[
{
"gauges": {
"jvm.buffers.direct.capacity":
"value": 1000
}
}
}
]
2014-03-10 16:36:17 +01:00
2015-11-19 19:52:54 +01:00
**Data for keys** `ring_members(0)` , `ring_members(1)` , `ring_members(2)` :
2014-03-10 16:36:17 +01:00
2015-11-19 19:49:24 +01:00
{
"ring_members": [
"riak1@127.0.0.1",
"riak2@127.0.0.1",
"riak3@127.0.0.1"
]
}
2014-03-10 16:36:17 +01:00
2015-11-19 19:49:24 +01:00
### Thresholds and Ranges
2014-03-10 16:36:17 +01:00
2015-11-19 19:49:24 +01:00
**Data**:
2014-03-10 16:36:17 +01:00
2015-11-19 19:49:24 +01:00
{ "metric": 1000 }
2014-03-10 16:36:17 +01:00
2015-11-19 19:49:24 +01:00
#### Relevant Commands
2014-03-10 16:36:17 +01:00
2015-11-19 19:54:25 +01:00
* **Warning:** `./check_http_json.py -H <host>:<port> -p <path> -w "metric,RANGE"`
* **Critical:** `./check_http_json.py -H <host>:<port> -p <path> -c "metric,RANGE"`
* **Metrics with Warning:** `./check_http_json.py -H <host>:<port> -p <path> -w "metric,RANGE"`
2019-05-09 15:48:29 +02:00
* **Metrics with Critical:**
2015-11-19 19:55:16 +01:00
2015-11-19 19:55:07 +01:00
./check_http_json.py -H < host > :< port > -p < path > -w "metric,,,RANGE"
./check_http_json.py -H < host > :< port > -p < path > -w "metric,,,,MIN,MAX"
2014-03-10 19:15:11 +01:00
2015-11-19 19:49:24 +01:00
#### Range Definitions
2014-03-10 19:15:11 +01:00
2015-11-19 19:54:25 +01:00
* **Format:** [@]START:END
* **Generates a Warning or Critical if...**
* **Value is less than 0 or greater than 1000:** `1000` or `0:1000`
* **Value is greater than or equal to 1000, or less than or equal to 0:** `@1000` or `@0:1000`
* **Value is less than 1000:** `1000:`
* **Value is greater than 1000:** `~:1000`
* **Value is greater than or equal to 1000:** `@1000:`
2014-03-10 19:15:11 +01:00
2015-11-19 19:49:24 +01:00
More info about Nagios Range format and Units of Measure can be found at [https://nagios-plugins.org/doc/guidelines.html ](https://nagios-plugins.org/doc/guidelines.html ).
2014-03-10 19:15:11 +01:00
2019-05-09 15:48:29 +02:00
#### Using Headers
2016-01-08 16:21:00 +01:00
* `./check_http_json.py -H <host>:<port> -p <path> -A '{"content-type": "application/json"}' -w "metric,RANGE"`
2015-11-19 19:49:24 +01:00
## Nagios Installation
2014-03-10 19:15:11 +01:00
2015-11-19 19:49:24 +01:00
### Requirements
2014-03-10 19:15:11 +01:00
2020-01-28 12:10:42 +01:00
* Python 3
2014-03-10 19:15:11 +01:00
2015-11-19 19:49:24 +01:00
### Configuration
2014-03-10 19:15:11 +01:00
2015-11-19 19:49:24 +01:00
Assuming a standard installation of Nagios, the plugin can be executed from the machine that Nagios is running on.
2014-03-10 19:15:11 +01:00
2015-11-19 19:49:24 +01:00
```bash
cp check_http_json.py /usr/local/nagios/libexec/plugins/check_http_json.py
chmod +x /usr/local/nagios/libexec/plugins/check_http_json.py
2014-03-10 19:15:11 +01:00
```
2015-11-19 19:49:24 +01:00
Add the following service definition to your server config (`localhost.cfg`):
2014-03-10 19:15:11 +01:00
```
2015-11-19 19:49:24 +01:00
define service {
use local-service
host_name localhost
service_description < command_description >
check_command < command_name >
}
2014-03-10 19:15:11 +01:00
```
2015-11-19 19:49:24 +01:00
Add the following command definition to your commands config (`commands.config`):
2014-03-10 19:15:11 +01:00
```
2015-04-24 17:32:03 +02:00
2015-11-19 19:49:24 +01:00
define command{
command_name < command_name >
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 > ]
}
2015-04-24 17:32:03 +02:00
```
2015-11-19 19:49:24 +01:00
More info about options in Usage.
2015-04-24 17:32:03 +02:00
2015-04-24 16:23:02 +02:00
## License
Copyright 2014-2015 Drew Kerrigan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
2015-05-08 00:16:58 +02:00
limitations under the License.