mirror of
https://github.com/drewkerrigan/nagios-http-json.git
synced 2026-02-12 01:51:01 +01:00
Compare commits
136 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e0d4e873b | ||
|
|
186f081cd7 | ||
|
|
e15f0f01ed | ||
|
|
b61789e4a4 | ||
|
|
c6daa09ba2 | ||
|
|
3a1e7d90d0 | ||
|
|
afb2ef7b88 | ||
|
|
2a6d88bc39 | ||
|
|
2dbb38512f | ||
|
|
9ff11308be | ||
|
|
c634ae8bb5 | ||
|
|
d3a2f3ed9e | ||
|
|
9d344f5a7a | ||
|
|
5c4a955abd | ||
|
|
b920a65afd | ||
|
|
d9efd1d858 | ||
|
|
e72030a087 | ||
|
|
6b51e1bb06 | ||
|
|
3f73984f6b | ||
|
|
09a7ec080c | ||
|
|
1f52898d10 | ||
|
|
27936784c4 | ||
|
|
fa157753ce | ||
|
|
0aceabfe91 | ||
|
|
4fbb0c828a | ||
|
|
e96bba0eb8 | ||
|
|
d9ee817dfc | ||
|
|
ce9c5fdada | ||
|
|
27c710b2ea | ||
|
|
dddf8432d6 | ||
|
|
739c093702 | ||
|
|
46271c961b | ||
|
|
49b338bdb6 | ||
|
|
9f41fc491e | ||
|
|
3a22b712ab | ||
|
|
9626fc4464 | ||
|
|
c54a0040a0 | ||
|
|
ffd96dd59f | ||
|
|
0572c2f494 | ||
|
|
2e6eaeea59 | ||
|
|
428a5a6d3a | ||
|
|
e3ac06864d | ||
|
|
63542f3226 | ||
|
|
cdb2474ee0 | ||
|
|
2821a1ae66 | ||
|
|
831bfdf97b | ||
|
|
f612277772 | ||
|
|
1f440e0ff5 | ||
|
|
c23ebac77a | ||
|
|
a014944981 | ||
|
|
47a37556ba | ||
|
|
41279cad2c | ||
|
|
f7c0472cdc | ||
|
|
25fb340bbb | ||
|
|
47bdea7fc5 | ||
|
|
866a12ea07 | ||
|
|
d1e585b2dd | ||
|
|
941afeed89 | ||
|
|
b9a583f281 | ||
|
|
4c89a8a93d | ||
|
|
73557b3657 | ||
|
|
aad2376ac0 | ||
|
|
219e99386c | ||
|
|
0cbbf41b9c | ||
|
|
dd952fd571 | ||
|
|
83ee5062f5 | ||
|
|
c90b0323f5 | ||
|
|
1ac160e8c2 | ||
|
|
6fc41612c4 | ||
|
|
f567c1ca0c | ||
|
|
2c98e840e8 | ||
|
|
1a9e1e9048 | ||
|
|
4f1d29dc7e | ||
|
|
404890d918 | ||
|
|
e7cf7ca8fb | ||
|
|
71cbd98e79 | ||
|
|
5c416cd0c0 | ||
|
|
e4801227bf | ||
|
|
b7c0b0595e | ||
|
|
375da5d605 | ||
|
|
95912246a2 | ||
|
|
ba9d9b1c39 | ||
|
|
3f81e32b29 | ||
|
|
f97759f1bd | ||
|
|
e95daad8ff | ||
|
|
174686a980 | ||
|
|
24889384b0 | ||
|
|
21f48681c9 | ||
|
|
2196dba761 | ||
|
|
c2435a8cbf | ||
|
|
2289fb2af3 | ||
|
|
2541223cde | ||
|
|
209aaef041 | ||
|
|
65c3bd2a25 | ||
|
|
9c0c59d6c1 | ||
|
|
e2fce71d5a | ||
|
|
26a1b3dbe8 | ||
|
|
47547951cf | ||
|
|
7858382bbe | ||
|
|
1173420803 | ||
|
|
bcc36a6e95 | ||
|
|
d98d0396b2 | ||
|
|
8437c464e5 | ||
|
|
df2bbdbf51 | ||
|
|
823fc275c9 | ||
|
|
18b0898e72 | ||
|
|
95318954bf | ||
|
|
8e469e3d98 | ||
|
|
29f8d892ee | ||
|
|
cbdb884dc7 | ||
|
|
3a108aef5e | ||
|
|
81522fa9ab | ||
|
|
27eaaf0842 | ||
|
|
9dd6323b85 | ||
|
|
67136a4a2b | ||
|
|
d164a1250c | ||
|
|
89f42c15a0 | ||
|
|
1e707a4b6a | ||
|
|
9656265439 | ||
|
|
e463369671 | ||
|
|
357c2240ba | ||
|
|
42d1e08037 | ||
|
|
4950225393 | ||
|
|
9be6a709a2 | ||
|
|
06fab10fe2 | ||
|
|
7bdc802c2d | ||
|
|
ed7bc7175b | ||
|
|
4180ec2066 | ||
|
|
a0d0773d1a | ||
|
|
fbebf05f76 | ||
|
|
6f9048fc75 | ||
|
|
5bb09cd362 | ||
|
|
568fa6e4d0 | ||
|
|
f63ac180b6 | ||
|
|
070047cf55 | ||
|
|
8adcf2ff07 |
26
.github/workflows/unittest.yml
vendored
Normal file
26
.github/workflows/unittest.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
name: CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
gitHubActionForPytest:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: [3.8, 3.11, 3.12]
|
||||
name: GitHub Action
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install -r requirements-dev.txt
|
||||
- name: Lint
|
||||
run: |
|
||||
make lint
|
||||
- name: Unit Test
|
||||
run: |
|
||||
make test
|
||||
- name: Coverage
|
||||
run: |
|
||||
make coverage
|
||||
65
.gitignore
vendored
Normal file
65
.gitignore
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
#Emacs
|
||||
\#*
|
||||
.\#*
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
env/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
.venv/
|
||||
venv/
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*,cover
|
||||
.hypothesis/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
#Ipython Notebook
|
||||
.ipynb_checkpoints
|
||||
21
.pylintrc
Normal file
21
.pylintrc
Normal file
@@ -0,0 +1,21 @@
|
||||
# pylint config
|
||||
[MASTER]
|
||||
ignore-patterns=^test.*
|
||||
|
||||
[MESSAGES CONTROL]
|
||||
disable=fixme,
|
||||
consider-using-f-string,
|
||||
invalid-name,
|
||||
line-too-long,
|
||||
missing-function-docstring,
|
||||
missing-module-docstring,
|
||||
multiple-imports,
|
||||
no-else-return,
|
||||
redefined-outer-name,
|
||||
superfluous-parens,
|
||||
too-many-locals,
|
||||
too-many-arguments,
|
||||
too-many-branches,
|
||||
too-many-instance-attributes,
|
||||
too-many-return-statements,
|
||||
too-many-statements
|
||||
11
Makefile
Normal file
11
Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
.PHONY: lint test coverage
|
||||
|
||||
PYTHON_PATH?=python3
|
||||
|
||||
lint:
|
||||
$(PYTHON_PATH) -m pylint check_http_json.py
|
||||
test:
|
||||
$(PYTHON_PATH) -m unittest discover
|
||||
coverage:
|
||||
$(PYTHON_PATH) -m coverage run -m unittest discover
|
||||
$(PYTHON_PATH) -m coverage report -m --include check_http_json.py
|
||||
391
README.md
391
README.md
@@ -1,15 +1,16 @@
|
||||

|
||||
|
||||
# Nagios Json Plugin
|
||||
|
||||
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.
|
||||
|
||||
### Installation
|
||||
## Installation
|
||||
|
||||
#### Requirements
|
||||
Requirements:
|
||||
|
||||
* Nagios
|
||||
* Python
|
||||
* Python 3.6+
|
||||
|
||||
### Nagios Configuration
|
||||
### Nagios
|
||||
|
||||
Assuming a standard installation of Nagios, the plugin can be executed from the machine that Nagios is running on.
|
||||
|
||||
@@ -42,226 +43,260 @@ define command{
|
||||
|
||||
```
|
||||
|
||||
More info about options in Usage.
|
||||
### Icinga2
|
||||
|
||||
### CLI Usage
|
||||
An example Icinga2 command definition can be found here: (`contrib/icinga2_check_command_definition.conf`)
|
||||
|
||||
## Usage
|
||||
|
||||
Executing `./check_http_json.py -h` will yield the following details:
|
||||
|
||||
```
|
||||
usage: check_http_json.py [-h] [-d] [-s] -H HOST [-P PORT] [-p PATH]
|
||||
[-t TIMEOUT] [-B AUTH] [-D DATA] [-f SEPARATOR]
|
||||
usage: check_http_json.py [-h] [-d] [-s] -H HOST [-k] [-V] [--cacert CACERT]
|
||||
[--cert CERT] [--key KEY] [-P PORT] [-p PATH]
|
||||
[-t TIMEOUT] [-B AUTH] [-D DATA] [-A HEADERS]
|
||||
[-f FIELD_SEPARATOR] [-F VALUE_SEPARATOR]
|
||||
[-w [KEY_THRESHOLD_WARNING [KEY_THRESHOLD_WARNING ...]]]
|
||||
[-c [KEY_THRESHOLD_CRITICAL [KEY_THRESHOLD_CRITICAL ...]]]
|
||||
[-e [KEY_LIST [KEY_LIST ...]]]
|
||||
[-E [KEY_LIST_CRITICAL [KEY_LIST_CRITICAL ...]]]
|
||||
[-q [KEY_VALUE_LIST [KEY_VALUE_LIST ...]]]
|
||||
[-Q [KEY_VALUE_LIST_CRITICAL [KEY_VALUE_LIST_CRITICAL ...]]]
|
||||
[-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 ...]]]
|
||||
[-m [METRIC_LIST [METRIC_LIST ...]]]
|
||||
|
||||
Nagios plugin which checks json values from a given endpoint against argument
|
||||
specified rules and determines the status and performance data for that
|
||||
service
|
||||
Check HTTP JSON Nagios Plugin
|
||||
|
||||
optional arguments:
|
||||
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: 2.2.0 (2024-05-14)
|
||||
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
-d, --debug Debug mode.
|
||||
-s, --ssl HTTPS mode.
|
||||
-H HOST, --host HOST Host.
|
||||
-d, --debug debug mode
|
||||
-v, --verbose Verbose mode. Multiple -v options increase the verbosity
|
||||
-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
|
||||
-X {GET,POST}, --request {GET,POST}
|
||||
Specifies a custom request method to use when communicating with the HTTP server
|
||||
-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 )
|
||||
-P PORT, --port PORT TCP port
|
||||
-p PATH, --path PATH Path.
|
||||
-p PATH, --path PATH Path
|
||||
-t TIMEOUT, --timeout TIMEOUT
|
||||
Connection timeout (seconds)
|
||||
--unreachable-state UNREACHABLE_STATE
|
||||
Exit with specified code when the URL is unreachable. Examples: 1 for Warning, 2 for Critical, 3 for Unknown (default: 3)
|
||||
--invalid-json-state INVALID_JSON_STATE
|
||||
Exit with specified code when no valid JSON is returned. Examples: 1 for Warning, 2 for Critical, 3 for Unknown (default: 3)
|
||||
-B AUTH, --basic-auth AUTH
|
||||
Basic auth string "username:password"
|
||||
-D DATA, --data DATA The http payload to send as a POST
|
||||
-A HEADERS, --headers HEADERS
|
||||
The http headers in JSON format.
|
||||
-f SEPARATOR, --field_separator SEPARATOR
|
||||
Json Field separator, defaults to "." ; Select element
|
||||
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.
|
||||
-e [KEY_LIST [KEY_LIST ...]], --key_exists [KEY_LIST [KEY_LIST ...]]
|
||||
Checks existence of these keys to determine status.
|
||||
Return warning if key is not present.
|
||||
-E [KEY_LIST_CRITICAL [KEY_LIST_CRITICAL ...]], --key_exists_critical [KEY_LIST_CRITICAL [KEY_LIST_CRITICAL ...]]
|
||||
JSON Field separator, defaults to "."; Select element in an array with "(" ")"
|
||||
-F VALUE_SEPARATOR, --value_separator VALUE_SEPARATOR
|
||||
JSON Value separator, defaults to ":"
|
||||
-w [KEY_THRESHOLD_WARNING ...], --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 ...], --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.
|
||||
-e [KEY_LIST ...], --key_exists [KEY_LIST ...]
|
||||
Checks existence of these keys to determine status. Return warning if key is not present.
|
||||
-E [KEY_LIST_CRITICAL ...], --key_exists_critical [KEY_LIST_CRITICAL ...]
|
||||
Same as -e but return critical if key is not present.
|
||||
-q [KEY_VALUE_LIST [KEY_VALUE_LIST ...]], --key_equals [KEY_VALUE_LIST [KEY_VALUE_LIST ...]]
|
||||
Checks equality of these keys and values
|
||||
-q [KEY_VALUE_LIST ...], --key_equals [KEY_VALUE_LIST ...]
|
||||
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 fails
|
||||
-Q [KEY_VALUE_LIST_CRITICAL ...], --key_equals_critical [KEY_VALUE_LIST_CRITICAL ...]
|
||||
Same as -q but return critical if equality check fails.
|
||||
--key_time [KEY_TIME_LIST ...],
|
||||
Checks a Timestamp 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
|
||||
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.
|
||||
-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
|
||||
performance data. More information about Range format
|
||||
and units of measure for nagios can be found at
|
||||
nagios-plugins.org/doc/guidelines.html Additional
|
||||
formats for this parameter are: (key[>alias]),
|
||||
(key[>alias],UnitOfMeasure),
|
||||
(key[>alias],UnitOfMeasure,WarnRange,CriticalRange).
|
||||
(key,value1:value2). Return warning if the key is older
|
||||
than the value (ex.: 30s,10m,2h,3d,...).
|
||||
With at it return warning if the key is jounger
|
||||
than the value (ex.: @30s,@10m,@2h,@3d,...).
|
||||
With Minus you can shift the time in the future.
|
||||
--key_time_critical [KEY_TIME_LIST_CRITICAL ...],
|
||||
Same as --key_time but return critical if
|
||||
Timestamp age fails.
|
||||
-u [KEY_VALUE_LIST_UNKNOWN ...], --key_equals_unknown [KEY_VALUE_LIST_UNKNOWN ...]
|
||||
Same as -q but return unknown if equality check fails.
|
||||
-y [KEY_VALUE_LIST_NOT ...], --key_not_equals [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_not_equals_critical [KEY_VALUE_LIST_NOT_CRITICAL ...]
|
||||
Same as -q but return critical if equality check succeeds.
|
||||
-m [METRIC_LIST ...], --key_metric [METRIC_LIST ...]
|
||||
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 Additional formats for this parameter are: (key[>alias]),
|
||||
(key[>alias],UnitOfMeasure), (key[>alias],UnitOfMeasure,WarnRange, CriticalRange).
|
||||
```
|
||||
|
||||
Access a specific JSON field by following this syntax: `alpha.beta.gamma(3).theta.omega(0)`
|
||||
Dots are field separators (changeable), parentheses are for entering arrays.
|
||||
The check plugin respects the environment variables `HTTP_PROXY`, `HTTPS_PROXY`.
|
||||
|
||||
If the root of the JSON data is itself an array like the following:
|
||||
## Examples
|
||||
|
||||
```
|
||||
[
|
||||
{ "gauges": { "jvm.buffers.direct.capacity": {"value": 215415}}}
|
||||
]
|
||||
```
|
||||
### Key Naming
|
||||
|
||||
The beginning of the key should start with ($index) as in this example:
|
||||
**Data for key** `value`:
|
||||
|
||||
```
|
||||
./check_http_json.py -H localhost:8081 -p metrics --key_exists "(0)_gauges_jvm.buffers.direct.capacity_value" -f _
|
||||
```
|
||||
{ "value": 1000 }
|
||||
|
||||
**Data for key** `capacity.value`:
|
||||
|
||||
{
|
||||
"capacity": {
|
||||
"value": 1000
|
||||
}
|
||||
}
|
||||
|
||||
**Data for key** `(0).capacity.value`:
|
||||
|
||||
[
|
||||
{
|
||||
"capacity": {
|
||||
"value": 1000
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
**Data for keys of all items in a list** `(*).capacity.value`:
|
||||
|
||||
[
|
||||
{
|
||||
"capacity": {
|
||||
"value": 1000
|
||||
}
|
||||
},
|
||||
{
|
||||
"capacity": {
|
||||
"value": 2200
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
**Data for separator** `-f _` **and key** `(0)_gauges_jvm.buffers.direct.capacity_value`:
|
||||
|
||||
[
|
||||
{
|
||||
"gauges": {
|
||||
"jvm.buffers.direct.capacity":
|
||||
"value": 1000
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
**Data for keys** `ring_members(0)`, `ring_members(1)`, `ring_members(2)`:
|
||||
|
||||
{
|
||||
"ring_members": [
|
||||
"riak1@127.0.0.1",
|
||||
"riak2@127.0.0.1",
|
||||
"riak3@127.0.0.1"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
**Data for multiple keys for an object** `-q capacity1.value,True capacity2.value,True capacity3.value,True`
|
||||
|
||||
{
|
||||
"capacity1": {
|
||||
"value": true
|
||||
},
|
||||
"capacity2": {
|
||||
"value": true
|
||||
},
|
||||
"capacity3": {
|
||||
"value": true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
### Thresholds and Ranges
|
||||
|
||||
**Data**:
|
||||
|
||||
{ "metric": 1000 }
|
||||
|
||||
#### Relevant Commands
|
||||
|
||||
* **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"`
|
||||
* **Metrics with Critical:**
|
||||
|
||||
./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"
|
||||
|
||||
#### Range Definitions
|
||||
|
||||
* **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:`
|
||||
|
||||
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).
|
||||
|
||||
### Docker Info Example Plugin
|
||||
### Timestamp
|
||||
|
||||
#### Description
|
||||
**Data**:
|
||||
|
||||
Let's say we want to use `check_http_json.py` to read from Docker's `/info` HTTP API endpoint with the following parameters:
|
||||
{ "metric": "2020-01-01 10:10:00.000000+00:00" }
|
||||
|
||||
##### Connection information
|
||||
#### Relevant Commands
|
||||
|
||||
* Host = 127.0.0.1:4243
|
||||
* Path = /info
|
||||
* **Warning:** `./check_http_json.py -H <host>:<port> -p <path> --key_time "metric,TIME"`
|
||||
* **Critical:** `./check_http_json.py -H <host>:<port> -p <path> --key_time_critical "metric,TIME"`
|
||||
|
||||
##### Rules for "aliveness"
|
||||
#### TIME Definitions
|
||||
|
||||
* Verify that the key `Containers` exists in the outputted JSON
|
||||
* Verify that the key `IPv4Forwarding` has a value of `1`
|
||||
* Verify that the key `Debug` has a value less than or equal to `2`
|
||||
* Verify that the key `Images` has a value greater than or equal to `1`
|
||||
* If any of these criteria are not met, report a WARNING to Nagios
|
||||
* **Format:** [@][-]TIME
|
||||
* **Generates a Warning or Critical if...**
|
||||
* **Timestamp is more than 30 seconds in the past:** `30s`
|
||||
* **Timestamp is more than 5 minutes in the past:** `5m`
|
||||
* **Timestamp is more than 12 hours in the past:** `12h`
|
||||
* **Timestamp is more than 2 days in the past:** `2d`
|
||||
* **Timestamp is more than 30 minutes in the future:** `-30m`
|
||||
* **Timestamp is not more than 30 minutes in the future:** `@-30m`
|
||||
* **Timestamp is not more than 30 minutes in the past:** `@30m`
|
||||
|
||||
##### Gather Metrics
|
||||
##### Timestamp Format
|
||||
|
||||
* Report value of the key `Containers` with a MinValue of 0 and a MaxValue of 1000 as performance data
|
||||
* Report value of the key `Images` as performance data
|
||||
* Report value of the key `NEventsListener` as performance data
|
||||
* Report value of the key `NFd` as performance data
|
||||
* Report value of the key `NGoroutines` as performance data
|
||||
* Report value of the key `SwapLimit` as performance data
|
||||
This plugin uses the Python function 'datetime.fromisoformat'.
|
||||
Since Python 3.11 any valid ISO 8601 format is supported, with the following exceptions:
|
||||
|
||||
#### Service Definition
|
||||
* Time zone offsets may have fractional seconds.
|
||||
* The T separator may be replaced by any single unicode character.
|
||||
* Fractional hours and minutes are not supported.
|
||||
* Reduced precision dates are not currently supported (YYYY-MM, YYYY).
|
||||
* Extended date representations are not currently supported (±YYYYYY-MM-DD).
|
||||
* Ordinal dates are not currently supported (YYYY-OOO).
|
||||
|
||||
`localhost.cfg`
|
||||
Before Python 3.11, this method only supported the format YYYY-MM-DD
|
||||
|
||||
```
|
||||
define service {
|
||||
use local-service
|
||||
host_name localhost
|
||||
service_description Docker info status checker
|
||||
check_command check_docker
|
||||
}
|
||||
```
|
||||
More info and examples the about Timestamp Format can be found at [https://docs.python.org/3/library/datetime.html#datetime.datetime.fromisoformat](https://docs.python.org/3/library/datetime.html#datetime.datetime.fromisoformat).
|
||||
|
||||
#### Command Definition with Arguments
|
||||
#### Using Headers
|
||||
|
||||
`commands.cfg`
|
||||
|
||||
```
|
||||
define command{
|
||||
command_name check_docker
|
||||
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
|
||||
}
|
||||
```
|
||||
|
||||
#### Sample Output
|
||||
|
||||
```
|
||||
OK: Status OK.|'Containers'=1;0;1000 'Images'=11;0;0 'NEventsListener'=3;0;0 'NFd'=10;0;0 'NGoroutines'=14;0;0 'SwapLimit'=1;0;0
|
||||
```
|
||||
|
||||
### Docker Container Monitor Example Plugin
|
||||
|
||||
`check_http_json.py` is generic enough to read and evaluate rules on any HTTP endpoint that returns JSON. In this example we'll get the status of a specific container using it's ID which camn be found by using the list containers endpoint (`curl http://127.0.0.1:4243/containers/json?all=1`).
|
||||
|
||||
##### Connection information
|
||||
|
||||
* Host = 127.0.0.1:4243
|
||||
* Path = /containers/2356e8ccb3de8308ccb16cf8f5d157bc85ded5c3d8327b0dfb11818222b6f615/json
|
||||
|
||||
##### Rules for "aliveness"
|
||||
|
||||
* Verify that the key `ID` exists and is equal to the value `2356e8ccb3de8308ccb16cf8f5d157bc85ded5c3d8327b0dfb11818222b6f615`
|
||||
* Verify that the key `State.Running` has a value of `True`
|
||||
|
||||
#### Service Definition
|
||||
|
||||
`localhost.cfg`
|
||||
|
||||
```
|
||||
define service {
|
||||
use local-service
|
||||
host_name localhost
|
||||
service_description Docker container liveness check
|
||||
check_command check_my_container
|
||||
}
|
||||
```
|
||||
|
||||
#### Command Definition with Arguments
|
||||
|
||||
`commands.cfg`
|
||||
|
||||
```
|
||||
define command{
|
||||
command_name check_my_container
|
||||
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
|
||||
}
|
||||
```
|
||||
|
||||
#### Sample Output
|
||||
|
||||
```
|
||||
WARNING: Status check failed, reason: Value True for key State.Running did not match.
|
||||
```
|
||||
|
||||
The plugin threw a warning because the Container ID I used on my system has the following State object:
|
||||
|
||||
```
|
||||
u'State': {...
|
||||
u'Running': False,
|
||||
...
|
||||
```
|
||||
|
||||
If I change the command to have the parameter -q parameter `State.Running,False`, the output becomes:
|
||||
|
||||
```
|
||||
OK: Status OK.
|
||||
```
|
||||
|
||||
### Dropwizard / Fieldnames Containing '.' Example
|
||||
|
||||
Simply choose a separator to deal with data such as this:
|
||||
|
||||
```
|
||||
{ "gauges": { "jvm.buffers.direct.capacity": {"value": 215415}}}
|
||||
```
|
||||
|
||||
In this example I've chosen `_` to separate `guages` from `jvm` and `capacity` from `value`. The CLI invocation then becomes:
|
||||
|
||||
```
|
||||
./check_http_json.py -H localhost:8081 -p metrics --key_exists gauges_jvm.buffers.direct.capacity_value -f _
|
||||
```
|
||||
* `./check_http_json.py -H <host>:<port> -p <path> -A '{"content-type": "application/json"}' -w "metric,RANGE"`
|
||||
|
||||
## License
|
||||
|
||||
|
||||
1132
check_http_json.py
1132
check_http_json.py
File diff suppressed because it is too large
Load Diff
110
contrib/icinga2_check_command_definition.conf
Normal file
110
contrib/icinga2_check_command_definition.conf
Normal file
@@ -0,0 +1,110 @@
|
||||
object CheckCommand "http_json" {
|
||||
import "plugin-check-command"
|
||||
|
||||
command = [ PluginDir + "/check_http_json.py" ]
|
||||
|
||||
arguments = {
|
||||
"--host" = {
|
||||
value = "$address$"
|
||||
description = "Hostname or address of the interface to query"
|
||||
required = true
|
||||
}
|
||||
"--port" = {
|
||||
value = "$http_json_port$"
|
||||
description = "TCP port number"
|
||||
}
|
||||
"--path" = {
|
||||
value = "$http_json_path$"
|
||||
description = "URL path to query (i.e.: /v1/service/xyz)"
|
||||
}
|
||||
"--timeout" = {
|
||||
value = "$http_json_timeout$"
|
||||
description = "Connection timeout (seconds)"
|
||||
}
|
||||
"--basic-auth" = {
|
||||
value = "$http_json_basic_auth$"
|
||||
description = "Basic auth string 'username:password'"
|
||||
}
|
||||
"--ssl" = {
|
||||
set_if = "$http_json_ssl$"
|
||||
description = "use TLS to connect to remote host"
|
||||
}
|
||||
"--insecure" = {
|
||||
set_if = "$http_json_insecure$"
|
||||
description = "do not check server SSL certificate"
|
||||
}
|
||||
"--cacert" = {
|
||||
value = "$http_json_cacert_file$"
|
||||
description = "path of cacert file to validate server cert"
|
||||
}
|
||||
"--cert" = {
|
||||
value = "$http_json_cert_file$"
|
||||
description = "client certificate in PEM format"
|
||||
}
|
||||
"--key" = {
|
||||
value = "$http_json_key_file$"
|
||||
description = "client certificate key file in PEM format ( if not bundled into the cert )"
|
||||
}
|
||||
"--data" = {
|
||||
value = "$http_json_post_data$"
|
||||
description = "the http payload to send as a POST"
|
||||
}
|
||||
"--headers" = {
|
||||
value = "$http_json_headers$"
|
||||
description = "additional http headers in JSON format to send with the request"
|
||||
}
|
||||
"--field_separator" = {
|
||||
value = "$http_json_field_separator$"
|
||||
description = "JSON Field separator, defaults to '.'; Select element in an array with '(' ')'"
|
||||
}
|
||||
"--value_separator" = {
|
||||
value = "$http_json_value_separator$"
|
||||
description = "JSON Value separator, defaults to ':'"
|
||||
}
|
||||
"--warning" = {
|
||||
value = "$http_json_warning$"
|
||||
description = "Warning threshold for these values, WarningRange is in the format [@]start:end"
|
||||
}
|
||||
"--critical" = {
|
||||
value = "$http_json_critical$"
|
||||
description = "Critical threshold for these values, CriticalRange is in the format [@]start:end"
|
||||
}
|
||||
"--key_exists" = {
|
||||
value = "$http_json_key_exists$"
|
||||
description = "Checks existence of these keys to determine status. Return warning if key is not present."
|
||||
}
|
||||
"--key_exists_critical" = {
|
||||
value = "$http_json_key_exists_critical$"
|
||||
description = "Checks existence of these keys to determine status. Return critical if key is not present."
|
||||
}
|
||||
"--key_equals" = {
|
||||
value = "$http_json_key_equals$"
|
||||
description = "Checks equality of these keys and values. Return warning if equality check fails"
|
||||
}
|
||||
"--key_equals_critical" = {
|
||||
value = "$http_json_key_equals_critical$"
|
||||
description = "Checks equality of these keys and values. Return critical if equality check fails"
|
||||
}
|
||||
"--key_equals_unknown" = {
|
||||
value = "$http_json_key_equals_unknown$"
|
||||
description = "Checks equality of these keys and values. Return unknown if equality check fails"
|
||||
}
|
||||
"--unreachable-state" = {
|
||||
value = "$http_json_unreachable_state$"
|
||||
description = "Exit with specified code if URL unreachable. Examples: 1 for Warning, 2 for Critical, 3 for Unknown (default: 3)"
|
||||
}
|
||||
"--key_not_equals" = {
|
||||
value = "$http_json_key_not_equals$"
|
||||
description = "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."
|
||||
}
|
||||
"--key_not_equals_critical" = {
|
||||
value = "$http_json_key_not_equals_critical$"
|
||||
description = "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 critical if equality check succeeds."
|
||||
}
|
||||
"--key_metric" = {
|
||||
value = "$http_json_key_metric$"
|
||||
description = "Gathers the values of these keys"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
115
docs/DOCKER.md
Normal file
115
docs/DOCKER.md
Normal file
@@ -0,0 +1,115 @@
|
||||
### Docker Info Example Plugin
|
||||
|
||||
#### Description
|
||||
|
||||
Let's say we want to use `check_http_json.py` to read from Docker's `/info` HTTP API endpoint with the following parameters:
|
||||
|
||||
##### Connection information
|
||||
|
||||
* Host = 127.0.0.1:4243
|
||||
* Path = /info
|
||||
|
||||
##### Rules for "aliveness"
|
||||
|
||||
* Verify that the key `Containers` exists in the outputted JSON
|
||||
* Verify that the key `IPv4Forwarding` has a value of `1`
|
||||
* Verify that the key `Debug` has a value less than or equal to `2`
|
||||
* Verify that the key `Images` has a value greater than or equal to `1`
|
||||
* If any of these criteria are not met, report a WARNING to Nagios
|
||||
|
||||
##### Gather Metrics
|
||||
|
||||
* Report value of the key `Containers` with a MinValue of 0 and a MaxValue of 1000 as performance data
|
||||
* Report value of the key `Images` as performance data
|
||||
* Report value of the key `NEventsListener` as performance data
|
||||
* Report value of the key `NFd` as performance data
|
||||
* Report value of the key `NGoroutines` as performance data
|
||||
* Report value of the key `SwapLimit` as performance data
|
||||
|
||||
#### Service Definition
|
||||
|
||||
`localhost.cfg`
|
||||
|
||||
```
|
||||
define service {
|
||||
use local-service
|
||||
host_name localhost
|
||||
service_description Docker info status checker
|
||||
check_command check_docker
|
||||
}
|
||||
```
|
||||
|
||||
#### Command Definition with Arguments
|
||||
|
||||
`commands.cfg`
|
||||
|
||||
```
|
||||
define command{
|
||||
command_name check_docker
|
||||
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
|
||||
}
|
||||
```
|
||||
|
||||
#### Sample Output
|
||||
|
||||
```
|
||||
OK: Status OK.|'Containers'=1;0;1000 'Images'=11;0;0 'NEventsListener'=3;0;0 'NFd'=10;0;0 'NGoroutines'=14;0;0 'SwapLimit'=1;0;0
|
||||
```
|
||||
|
||||
### Docker Container Monitor Example Plugin
|
||||
|
||||
`check_http_json.py` is generic enough to read and evaluate rules on any HTTP endpoint that returns JSON. In this example we'll get the status of a specific container using it's ID which camn be found by using the list containers endpoint (`curl http://127.0.0.1:4243/containers/json?all=1`).
|
||||
|
||||
##### Connection information
|
||||
|
||||
* Host = 127.0.0.1:4243
|
||||
* Path = /containers/2356e8ccb3de8308ccb16cf8f5d157bc85ded5c3d8327b0dfb11818222b6f615/json
|
||||
|
||||
##### Rules for "aliveness"
|
||||
|
||||
* Verify that the key `ID` exists and is equal to the value `2356e8ccb3de8308ccb16cf8f5d157bc85ded5c3d8327b0dfb11818222b6f615`
|
||||
* Verify that the key `State.Running` has a value of `True`
|
||||
|
||||
#### Service Definition
|
||||
|
||||
`localhost.cfg`
|
||||
|
||||
```
|
||||
define service {
|
||||
use local-service
|
||||
host_name localhost
|
||||
service_description Docker container liveness check
|
||||
check_command check_my_container
|
||||
}
|
||||
```
|
||||
|
||||
#### Command Definition with Arguments
|
||||
|
||||
`commands.cfg`
|
||||
|
||||
```
|
||||
define command{
|
||||
command_name check_my_container
|
||||
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
|
||||
}
|
||||
```
|
||||
|
||||
#### Sample Output
|
||||
|
||||
```
|
||||
WARNING: Status check failed, reason: Value True for key State.Running did not match.
|
||||
```
|
||||
|
||||
The plugin threw a warning because the Container ID I used on my system has the following State object:
|
||||
|
||||
```
|
||||
u'State': {...
|
||||
u'Running': False,
|
||||
...
|
||||
```
|
||||
|
||||
If I change the command to have the parameter -q parameter `State.Running,False`, the output becomes:
|
||||
|
||||
```
|
||||
OK: Status OK.
|
||||
```
|
||||
227
docs/RIAK.md
Normal file
227
docs/RIAK.md
Normal file
@@ -0,0 +1,227 @@
|
||||
# Riak Stats Example
|
||||
|
||||
## Description
|
||||
|
||||
For this example we're going to use `check_http_json.py` as a pure CLI tool to read Riak's `/stats` endpoint
|
||||
|
||||
## Connection information
|
||||
|
||||
* Host = 127.0.0.1:8098
|
||||
* Path = /stats
|
||||
|
||||
## JSON Stats Data
|
||||
|
||||
* Full Riak HTTP Stats information can be found here: [http://docs.basho.com/riak/latest/dev/references/http/status/](http://docs.basho.com/riak/latest/dev/references/http/status/)
|
||||
* Information related to specific interesting stats can be found here: [http://docs.basho.com/riak/latest/ops/running/stats-and-monitoring/](http://docs.basho.com/riak/latest/ops/running/stats-and-monitoring/)
|
||||
|
||||
## Connectivity Check
|
||||
|
||||
* `ring_members`: We can use an existence check to monitor the number of ring members
|
||||
* `connected_nodes`: Similarly we can check the number of nodes that are in communication with this node, but this list will be empty in a 1 node cluster
|
||||
|
||||
#### Sample Command
|
||||
|
||||
For a single node dev "cluster", you might have a `ring_members` value like this:
|
||||
|
||||
```
|
||||
"ring_members": [
|
||||
"riak@127.0.0.1"
|
||||
],
|
||||
```
|
||||
|
||||
To validate that we have a single node, we can use this check:
|
||||
|
||||
```
|
||||
$ ./check_http_json.py -H localhost -P 8098 -p stats -E "ring_members(0)"
|
||||
OK: Status OK.
|
||||
```
|
||||
|
||||
If we were expecting at least 2 nodes in the cluster, we would use this check:
|
||||
|
||||
```
|
||||
$ ./check_http_json.py -H localhost -P 8098 -p stats -E "ring_members(1)"
|
||||
CRITICAL: Status CRITICAL. Key ring_members(1) did not exist.
|
||||
```
|
||||
|
||||
Obviously this fails because we only had a single `ring_member`. If we prefer to only get a warning instead of a critical for this check, we just use the correct flag:
|
||||
|
||||
```
|
||||
$ ./check_http_json.py -H localhost -P 8098 -p stats -e "ring_members(1)"
|
||||
WARNING: Status WARNING. Key ring_members(1) did not exist.
|
||||
```
|
||||
|
||||
## Gather Metrics
|
||||
|
||||
The thresholds for acceptable values for these metrics will vary from system to system, following are the stats we'll be checking:
|
||||
|
||||
### Throughput Metrics:
|
||||
|
||||
* `node_gets`
|
||||
* `node_puts`
|
||||
* `vnode_counter_update`
|
||||
* `vnode_set_update`
|
||||
* `vnode_map_update`
|
||||
* `search_query_throughput_one`
|
||||
* `search_index_throughtput_one`
|
||||
* `consistent_gets`
|
||||
* `consistent_puts`
|
||||
* `vnode_index_reads`
|
||||
|
||||
#### Sample Command
|
||||
|
||||
```
|
||||
./check_http_json.py -H localhost -P 8098 -p stats -m \
|
||||
"node_gets" \
|
||||
"node_puts" \
|
||||
"vnode_counter_update" \
|
||||
"vnode_set_update" \
|
||||
"vnode_map_update" \
|
||||
"search_query_throughput_one" \
|
||||
"search_index_throughtput_one" \
|
||||
"consistent_gets" \
|
||||
"consistent_puts" \
|
||||
"vnode_index_reads"
|
||||
```
|
||||
|
||||
#### Sample Output
|
||||
|
||||
```
|
||||
OK: Status OK.|'node_gets'=0 'node_puts'=0 'vnode_counter_update'=0 'vnode_set_update'=0 'vnode_map_update'=0 'search_query_throughput_one'=0 'consistent_gets'=0 'consistent_puts'=0 'vnode_index_reads'=0
|
||||
```
|
||||
|
||||
### Latency Metrics:
|
||||
|
||||
* `node_get_fsm_time_mean,_median,_95,_99,_100`
|
||||
* `node_put_fsm_time_mean,_median,_95,_99,_100`
|
||||
* `object_counter_merge_time_mean,_median,_95,_99,_100`
|
||||
* `object_set_merge_time_mean,_median,_95,_99,_100`
|
||||
* `object_map_merge_time_mean,_median,_95,_99,_100`
|
||||
* `search_query_latency_median,_min,_95,_99,_999`
|
||||
* `search_index_latency_median,_min,_95,_99,_999`
|
||||
* `consistent_get_time_mean,_median,_95,_99,_100`
|
||||
* `consistent_put_time_mean,_median,_95,_99,_100`
|
||||
|
||||
#### Sample Command
|
||||
|
||||
```
|
||||
./check_http_json.py -H localhost -P 8098 -p stats -m \
|
||||
"node_get_fsm_time_mean,,0:100,0:1000" \
|
||||
"node_get_fsm_time_median,,0:100,0:1000" \
|
||||
"node_get_fsm_time_95,,0:100,0:1000" \
|
||||
"node_get_fsm_time_99,,0:100,0:1000" \
|
||||
"node_get_fsm_time_100,,0:100,0:1000" \
|
||||
"node_put_fsm_time_mean,,0:100,0:1000" \
|
||||
"node_put_fsm_time_median,,0:100,0:1000" \
|
||||
"node_put_fsm_time_95,,0:100,0:1000" \
|
||||
"node_put_fsm_time_99,,0:100,0:1000" \
|
||||
"node_put_fsm_time_100,,0:100,0:1000" \
|
||||
"object_counter_merge_time_mean,,0:100,0:1000" \
|
||||
"object_counter_merge_time_median,,0:100,0:1000" \
|
||||
"object_counter_merge_time_95,,0:100,0:1000" \
|
||||
"object_counter_merge_time_99,,0:100,0:1000" \
|
||||
"object_counter_merge_time_100,,0:100,0:1000" \
|
||||
"object_set_merge_time_mean,,0:100,0:1000" \
|
||||
"object_set_merge_time_median,,0:100,0:1000" \
|
||||
"object_set_merge_time_95,,0:100,0:1000" \
|
||||
"object_set_merge_time_99,,0:100,0:1000" \
|
||||
"object_set_merge_time_100,,0:100,0:1000" \
|
||||
"object_map_merge_time_mean,,0:100,0:1000" \
|
||||
"object_map_merge_time_median,,0:100,0:1000" \
|
||||
"object_map_merge_time_95,,0:100,0:1000" \
|
||||
"object_map_merge_time_99,,0:100,0:1000" \
|
||||
"object_map_merge_time_100,,0:100,0:1000" \
|
||||
"consistent_get_time_mean,,0:100,0:1000" \
|
||||
"consistent_get_time_median,,0:100,0:1000" \
|
||||
"consistent_get_time_95,,0:100,0:1000" \
|
||||
"consistent_get_time_99,,0:100,0:1000" \
|
||||
"consistent_get_time_100,,0:100,0:1000" \
|
||||
"consistent_put_time_mean,,0:100,0:1000" \
|
||||
"consistent_put_time_median,,0:100,0:1000" \
|
||||
"consistent_put_time_95,,0:100,0:1000" \
|
||||
"consistent_put_time_99,,0:100,0:1000" \
|
||||
"consistent_put_time_100,,0:100,0:1000" \
|
||||
"search_query_latency_median,,0:100,0:1000" \
|
||||
"search_query_latency_min,,0:100,0:1000" \
|
||||
"search_query_latency_95,,0:100,0:1000" \
|
||||
"search_query_latency_99,,0:100,0:1000" \
|
||||
"search_query_latency_999,,0:100,0:1000" \
|
||||
"search_index_latency_median,,0:100,0:1000" \
|
||||
"search_index_latency_min,,0:100,0:1000" \
|
||||
"search_index_latency_95,,0:100,0:1000" \
|
||||
"search_index_latency_99,,0:100,0:1000" \
|
||||
"search_index_latency_999,,0:100,0:1000"
|
||||
```
|
||||
|
||||
#### Sample Output
|
||||
|
||||
```
|
||||
OK: Status OK.|'node_get_fsm_time_mean'=0;0:100;0:1000 'node_get_fsm_time_median'=0;0:100;0:1000 'node_get_fsm_time_95'=0;0:100;0:1000 'node_get_fsm_time_99'=0;0:100;0:1000 'node_get_fsm_time_100'=0;0:100;0:1000 'node_put_fsm_time_mean'=0;0:100;0:1000 'node_put_fsm_time_median'=0;0:100;0:1000 'node_put_fsm_time_95'=0;0:100;0:1000 'node_put_fsm_time_99'=0;0:100;0:1000 'node_put_fsm_time_100'=0;0:100;0:1000 'object_counter_merge_time_mean'=0;0:100;0:1000 'object_counter_merge_time_median'=0;0:100;0:1000 'object_counter_merge_time_95'=0;0:100;0:1000 'object_counter_merge_time_99'=0;0:100;0:1000 'object_counter_merge_time_100'=0;0:100;0:1000 'object_set_merge_time_mean'=0;0:100;0:1000 'object_set_merge_time_median'=0;0:100;0:1000 'object_set_merge_time_95'=0;0:100;0:1000 'object_set_merge_time_99'=0;0:100;0:1000 'object_set_merge_time_100'=0;0:100;0:1000 'object_map_merge_time_mean'=0;0:100;0:1000 'object_map_merge_time_median'=0;0:100;0:1000 'object_map_merge_time_95'=0;0:100;0:1000 'object_map_merge_time_99'=0;0:100;0:1000 'object_map_merge_time_100'=0;0:100;0:1000 'consistent_get_time_mean'=0;0:100;0:1000 'consistent_get_time_median'=0;0:100;0:1000 'consistent_get_time_95'=0;0:100;0:1000 'consistent_get_time_99'=0;0:100;0:1000 'consistent_get_time_100'=0;0:100;0:1000 'consistent_put_time_mean'=0;0:100;0:1000 'consistent_put_time_median'=0;0:100;0:1000 'consistent_put_time_95'=0;0:100;0:1000 'consistent_put_time_99'=0;0:100;0:1000 'consistent_put_time_100'=0;0:100;0:1000 'search_query_latency_median'=0;0:100;0:1000 'search_query_latency_min'=0;0:100;0:1000 'search_query_latency_95'=0;0:100;0:1000 'search_query_latency_99'=0;0:100;0:1000 'search_query_latency_999'=0;0:100;0:1000 'search_index_latency_median'=0;0:100;0:1000 'search_index_latency_min'=0;0:100;0:1000 'search_index_latency_95'=0;0:100;0:1000 'search_index_latency_99'=0;0:100;0:1000 'search_index_latency_999'=0;0:100;0:1000
|
||||
```
|
||||
|
||||
### Erlang Resource Usage Metrics:
|
||||
|
||||
* `sys_process_count`
|
||||
* `memory_processes`
|
||||
* `memory_processes_used`
|
||||
|
||||
#### Sample Command
|
||||
|
||||
```
|
||||
./check_http_json.py -H localhost -P 8098 -p stats -m \
|
||||
"sys_process_count,,0:5000,0:10000" \
|
||||
"memory_processes,,0:50000000,0:100000000" \
|
||||
"memory_processes_used,,0:50000000,0:100000000"
|
||||
```
|
||||
|
||||
#### Sample Output
|
||||
|
||||
```
|
||||
OK: Status OK.|'sys_process_count'=1637;0:5000;0:10000 'memory_processes'=46481112;0:50000000;0:100000000 'memory_processes_used'=46476880;0:50000000;0:100000000
|
||||
```
|
||||
|
||||
### General Riak Load / Health Metrics:
|
||||
|
||||
* `node_get_fsm_siblings_mean,_median,_95,_99,_100`
|
||||
* `node_get_fsm_objsize_mean,_median,_95,_99,_100`
|
||||
* `riak_search_vnodeq_mean,_median,_95,_99,_100`
|
||||
* `search_index_fail_one`
|
||||
* `pbc_active`
|
||||
* `pbc_connects`
|
||||
* `read_repairs`
|
||||
* `list_fsm_active`
|
||||
* `node_get_fsm_rejected`
|
||||
* `node_put_fsm_rejected`
|
||||
|
||||
#### Sample Command
|
||||
|
||||
```
|
||||
./check_http_json.py -H localhost -P 8098 -p stats -m \
|
||||
"node_get_fsm_siblings_mean,,0:100,0:1000" \
|
||||
"node_get_fsm_siblings_median,,0:100,0:1000" \
|
||||
"node_get_fsm_siblings_95,,0:100,0:1000" \
|
||||
"node_get_fsm_siblings_99,,0:100,0:1000" \
|
||||
"node_get_fsm_siblings_100,,0:100,0:1000" \
|
||||
"node_get_fsm_objsize_mean,,0:100,0:1000" \
|
||||
"node_get_fsm_objsize_median,,0:100,0:1000" \
|
||||
"node_get_fsm_objsize_95,,0:100,0:1000" \
|
||||
"node_get_fsm_objsize_99,,0:100,0:1000" \
|
||||
"node_get_fsm_objsize_100,,0:100,0:1000" \
|
||||
"riak_search_vnodeq_mean,,0:100,0:1000" \
|
||||
"riak_search_vnodeq_median,,0:100,0:1000" \
|
||||
"riak_search_vnodeq_95,,0:100,0:1000" \
|
||||
"riak_search_vnodeq_99,,0:100,0:1000" \
|
||||
"riak_search_vnodeq_100,,0:100,0:1000" \
|
||||
"search_index_fail_one,,0:100,0:1000" \
|
||||
"pbc_active,,0:100,0:1000" \
|
||||
"pbc_connects,,0:100,0:1000" \
|
||||
"read_repairs,,0:100,0:1000" \
|
||||
"list_fsm_active,,0:100,0:1000" \
|
||||
"node_get_fsm_rejected,,0:100,0:1000" \
|
||||
"node_put_fsm_rejected,,0:100,0:1000"
|
||||
```
|
||||
|
||||
#### Sample Output
|
||||
|
||||
```
|
||||
OK: Status OK.|'node_get_fsm_siblings_mean'=0;0:100;0:1000 'node_get_fsm_siblings_median'=0;0:100;0:1000 'node_get_fsm_siblings_95'=0;0:100;0:1000 'node_get_fsm_siblings_99'=0;0:100;0:1000 'node_get_fsm_siblings_100'=0;0:100;0:1000 'node_get_fsm_objsize_mean'=0;0:100;0:1000 'node_get_fsm_objsize_median'=0;0:100;0:1000 'node_get_fsm_objsize_95'=0;0:100;0:1000 'node_get_fsm_objsize_99'=0;0:100;0:1000 'node_get_fsm_objsize_100'=0;0:100;0:1000 'search_index_fail_one'=0;0:100;0:1000 'pbc_active'=0;0:100;0:1000 'pbc_connects'=0;0:100;0:1000 'read_repairs'=0;0:100;0:1000 'list_fsm_active'=0;0:100;0:1000 'node_get_fsm_rejected'=0;0:100;0:1000 'node_put_fsm_rejected'=0;0:100;0:1000
|
||||
```
|
||||
2
requirements-dev.txt
Normal file
2
requirements-dev.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
coverage==6.5.0
|
||||
pylint==2.17.7
|
||||
0
test/__init__.py
Normal file
0
test/__init__.py
Normal file
2
test/requirements.txt
Normal file
2
test/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
coverage==5.0.3
|
||||
pylint==2.4.4
|
||||
34
test/test_args.py
Normal file
34
test/test_args.py
Normal file
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
sys.path.append('..')
|
||||
|
||||
from check_http_json import *
|
||||
|
||||
|
||||
class ArgsTest(unittest.TestCase):
|
||||
"""
|
||||
Tests for argsparse
|
||||
"""
|
||||
|
||||
def test_parser_defaults(self):
|
||||
parser = parseArgs(['-H', 'foobar'])
|
||||
self.assertFalse(parser.debug)
|
||||
self.assertFalse(parser.ssl)
|
||||
self.assertFalse(parser.insecure)
|
||||
|
||||
def test_parser_with_debug(self):
|
||||
parser = parseArgs(['-H', 'foobar', '-d'])
|
||||
self.assertTrue(parser.debug)
|
||||
|
||||
def test_parser_with_port(self):
|
||||
parser = parseArgs(['-H', 'foobar', '-P', '8888'])
|
||||
self.assertEqual(parser.port, '8888')
|
||||
|
||||
def test_parser_with_separator(self):
|
||||
parser = parseArgs(['-H', 'foobar', '-f', '_', '-F', '_'])
|
||||
self.assertEqual(parser.separator, '_')
|
||||
self.assertEqual(parser.value_separator, '_')
|
||||
450
test/test_check_http_json.py
Normal file
450
test/test_check_http_json.py
Normal file
@@ -0,0 +1,450 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
import json
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
import sys
|
||||
|
||||
sys.path.append('..')
|
||||
|
||||
from check_http_json import *
|
||||
|
||||
|
||||
OK_CODE = 0
|
||||
WARNING_CODE = 1
|
||||
CRITICAL_CODE = 2
|
||||
UNKNOWN_CODE = 3
|
||||
|
||||
|
||||
class RulesHelper:
|
||||
separator = '.'
|
||||
value_separator = ':'
|
||||
debug = False
|
||||
key_threshold_warning = None
|
||||
key_value_list = None
|
||||
key_value_list_not = None
|
||||
key_list = None
|
||||
key_threshold_critical = None
|
||||
key_value_list_critical = None
|
||||
key_value_list_not_critical = None
|
||||
key_time_list = None
|
||||
key_time_list_critical = None
|
||||
key_value_list_unknown = None
|
||||
key_list_critical = None
|
||||
metric_list = None
|
||||
|
||||
def dash_m(self, data):
|
||||
self.metric_list = data
|
||||
return self
|
||||
|
||||
def dash_e(self, data):
|
||||
self.key_list = data
|
||||
return self
|
||||
|
||||
def dash_E(self, data):
|
||||
self.key_list_critical = data
|
||||
return self
|
||||
|
||||
def dash_q(self, data):
|
||||
self.key_value_list = data
|
||||
return self
|
||||
|
||||
def dash_Q(self, data):
|
||||
self.key_value_list_critical = data
|
||||
return self
|
||||
|
||||
def dash_y(self, data):
|
||||
self.key_value_list_not = data
|
||||
return self
|
||||
|
||||
def dash_Y(self, data):
|
||||
self.key_value_list_not_critical = data
|
||||
return self
|
||||
|
||||
def dash_U(self, data):
|
||||
self.key_value_list_unknown = data
|
||||
return self
|
||||
|
||||
def dash_w(self, data):
|
||||
self.key_threshold_warning = data
|
||||
return self
|
||||
|
||||
def dash_c(self, data):
|
||||
self.key_threshold_critical = data
|
||||
return self
|
||||
|
||||
def dash_dash_key_time(self, data):
|
||||
self.key_time_list = data
|
||||
return self
|
||||
|
||||
def dash_dash_key_time_critical(self, data):
|
||||
self.key_time_list_critical = data
|
||||
return self
|
||||
|
||||
class UtilTest(unittest.TestCase):
|
||||
"""
|
||||
Tests for the util fucntions
|
||||
"""
|
||||
|
||||
rules = RulesHelper()
|
||||
|
||||
def check_data(self, args, jsondata, code):
|
||||
data = json.loads(jsondata)
|
||||
nagios = NagiosHelper()
|
||||
processor = JsonRuleProcessor(data, args)
|
||||
nagios.append_message(WARNING_CODE, processor.checkWarning())
|
||||
nagios.append_message(CRITICAL_CODE, processor.checkCritical())
|
||||
nagios.append_metrics(processor.checkMetrics())
|
||||
nagios.append_message(UNKNOWN_CODE, processor.checkUnknown())
|
||||
self.assertEqual(code, nagios.getCode())
|
||||
|
||||
def test_metrics(self):
|
||||
self.check_data(RulesHelper().dash_m(['metric,,1:4,1:5']),
|
||||
'{"metric": 5}', WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_m(['metric,,1:5,1:4']),
|
||||
'{"metric": 5}', CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_m(['metric,,1:5,1:5,6,10']),
|
||||
'{"metric": 5}', CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_m(['metric,,1:5,1:5,1,4']),
|
||||
'{"metric": 5}', CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_m(['metric,s,@1:4,@6:10,1,10']),
|
||||
'{"metric": 5}', OK_CODE)
|
||||
self.check_data(RulesHelper().dash_m(['(*).value,s,1:5,1:5']),
|
||||
'[{"value": 5},{"value": 100}]', CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_m(['metric>foobar,,1:4,1:5']),
|
||||
'{"metric": 5}', WARNING_CODE)
|
||||
|
||||
def test_unknown(self):
|
||||
self.check_data(RulesHelper().dash_U(['metric,0']),
|
||||
'{"metric": 3}', UNKNOWN_CODE)
|
||||
|
||||
def test_array(self):
|
||||
self.check_data(RulesHelper().dash_q(['foo(0),bar']),
|
||||
'{"foo": ["bar"]}', OK_CODE)
|
||||
self.check_data(RulesHelper().dash_q(['foo(0),foo']),
|
||||
'{"foo": ["bar"]}', WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_Q(['foo(1),bar']),
|
||||
'{"foo": ["bar"]}', CRITICAL_CODE)
|
||||
|
||||
def test_exists(self):
|
||||
self.check_data(RulesHelper().dash_e(['nothere']),
|
||||
'{"metric": 5}', WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_E(['nothere']),
|
||||
'{"metric": 5}', CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_e(['metric']),
|
||||
'{"metric": 5}', OK_CODE)
|
||||
|
||||
def test_equality(self):
|
||||
self.check_data(RulesHelper().dash_q(['metric,6']),
|
||||
'{"metric": 5}', WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_Q(['metric,6']),
|
||||
'{"metric": 5}', CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_q(['metric,5']),
|
||||
'{"metric": 5}', OK_CODE)
|
||||
|
||||
def test_equality_colon(self):
|
||||
"""
|
||||
See https://github.com/drewkerrigan/nagios-http-json/issues/43
|
||||
"""
|
||||
rules = RulesHelper()
|
||||
rules.value_separator = '_'
|
||||
|
||||
# This should not fail
|
||||
self.check_data(rules.dash_q(['metric,foo:bar']),
|
||||
'{"metric": "foo:bar"}', OK_CODE)
|
||||
|
||||
def test_non_equality(self):
|
||||
self.check_data(RulesHelper().dash_y(['metric,6']),
|
||||
'{"metric": 6}', WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_Y(['metric,6']),
|
||||
'{"metric": 6}', CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_y(['metric,5']),
|
||||
'{"metric": 6}', OK_CODE)
|
||||
|
||||
def test_warning_thresholds(self):
|
||||
self.check_data(RulesHelper().dash_w(['metric,5']),
|
||||
'{"metric": 5}', OK_CODE)
|
||||
self.check_data(RulesHelper().dash_w(['metric,5:']),
|
||||
'{"metric": 5}', OK_CODE)
|
||||
self.check_data(RulesHelper().dash_w(['metric,~:5']),
|
||||
'{"metric": 5}', OK_CODE)
|
||||
self.check_data(RulesHelper().dash_w(['metric,1:5']),
|
||||
'{"metric": 5}', OK_CODE)
|
||||
self.check_data(RulesHelper().dash_w(['metric,@5']),
|
||||
'{"metric": 6}', OK_CODE)
|
||||
self.check_data(RulesHelper().dash_w(['metric,@5:']),
|
||||
'{"metric": 4}', OK_CODE)
|
||||
self.check_data(RulesHelper().dash_w(['metric,@~:5']),
|
||||
'{"metric": 6}', OK_CODE)
|
||||
self.check_data(RulesHelper().dash_w(['metric,@1:5']),
|
||||
'{"metric": 6}', OK_CODE)
|
||||
self.check_data(RulesHelper().dash_w(['metric,5']),
|
||||
'{"metric": 6}', WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_w(['metric,5:']),
|
||||
'{"metric": 4}', WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_w(['metric,~:5']),
|
||||
'{"metric": 6}', WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_w(['metric,1:5']),
|
||||
'{"metric": 6}', WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_w(['metric,@5']),
|
||||
'{"metric": 5}', WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_w(['metric,@5:']),
|
||||
'{"metric": 5}', WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_w(['metric,@~:5']),
|
||||
'{"metric": 5}', WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_w(['metric,@1:5']),
|
||||
'{"metric": 5}', WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_w(['(*).value,@1:5']),
|
||||
'[{"value": 5},{"value": 1000}]', WARNING_CODE)
|
||||
|
||||
def test_critical_thresholds(self):
|
||||
self.check_data(RulesHelper().dash_c(['metric,5']),
|
||||
'{"metric": 5}', OK_CODE)
|
||||
self.check_data(RulesHelper().dash_c(['metric,5:']),
|
||||
'{"metric": 5}', OK_CODE)
|
||||
self.check_data(RulesHelper().dash_c(['metric,~:5']),
|
||||
'{"metric": 5}', OK_CODE)
|
||||
self.check_data(RulesHelper().dash_c(['metric,1:5']),
|
||||
'{"metric": 5}', OK_CODE)
|
||||
self.check_data(RulesHelper().dash_c(['metric,@5']),
|
||||
'{"metric": 6}', OK_CODE)
|
||||
self.check_data(RulesHelper().dash_c(['metric,@5:']),
|
||||
'{"metric": 4}', OK_CODE)
|
||||
self.check_data(RulesHelper().dash_c(['metric,@~:5']),
|
||||
'{"metric": 6}', OK_CODE)
|
||||
self.check_data(RulesHelper().dash_c(['metric,@1:5']),
|
||||
'{"metric": 6}', OK_CODE)
|
||||
self.check_data(RulesHelper().dash_c(['metric,5']),
|
||||
'{"metric": 6}', CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_c(['metric,5:']),
|
||||
'{"metric": 4}', CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_c(['metric,~:5']),
|
||||
'{"metric": 6}', CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_c(['metric,1:5']),
|
||||
'{"metric": 6}', CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_c(['metric,@5']),
|
||||
'{"metric": 5}', CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_c(['metric,@5:']),
|
||||
'{"metric": 5}', CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_c(['metric,@~:5']),
|
||||
'{"metric": 5}', CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_c(['metric,@1:5']),
|
||||
'{"metric": 5}', CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_c(['(*).value,@1:5']),
|
||||
'[{"value": 5},{"value": 1000}]', CRITICAL_CODE)
|
||||
|
||||
def test_separator(self):
|
||||
rules = RulesHelper()
|
||||
rules.separator = '_'
|
||||
self.check_data(
|
||||
rules.dash_q(
|
||||
['(0)_gauges_jvm.buffers.direct.capacity(1)_value,1234']),
|
||||
'''[{ "gauges": { "jvm.buffers.direct.capacity": [
|
||||
{"value": 215415},{"value": 1234}]}}]''',
|
||||
OK_CODE)
|
||||
self.check_data(
|
||||
rules.dash_q(
|
||||
['(*)_gauges_jvm.buffers.direct.capacity(1)_value,1234']),
|
||||
'''[{ "gauges": { "jvm.buffers.direct.capacity": [
|
||||
{"value": 215415},{"value": 1234}]}},
|
||||
{ "gauges": { "jvm.buffers.direct.capacity": [
|
||||
{"value": 215415},{"value": 1235}]}}]''',
|
||||
WARNING_CODE)
|
||||
|
||||
def test_array_with_missing_element(self):
|
||||
"""
|
||||
See https://github.com/drewkerrigan/nagios-http-json/issues/34
|
||||
"""
|
||||
rules = RulesHelper()
|
||||
|
||||
# This should simply work
|
||||
data = '[{"Node": "there"}]'
|
||||
self.check_data(rules.dash_q(['(0).Node,there']), data, OK_CODE)
|
||||
|
||||
# This should warn us
|
||||
data = '[{"Node": "othervalue"}]'
|
||||
self.check_data(rules.dash_q(['(0).Node,there']), data, WARNING_CODE)
|
||||
|
||||
# # This should not throw an IndexError
|
||||
data = '[{"Node": "foobar"}]'
|
||||
self.check_data(rules.dash_q(['(0).Node,foobar', '(1).Node,missing']), data, WARNING_CODE)
|
||||
self.check_data(rules.dash_q(['(0).Node,foobar', '(1).Node,missing', '(2).Node,alsomissing']), data, WARNING_CODE)
|
||||
|
||||
# This should not throw a KeyError
|
||||
data = '{}'
|
||||
self.check_data(rules.dash_q(['(0).Node,foobar', '(1).Node,missing']), data, CRITICAL_CODE)
|
||||
|
||||
def test_subelem(self):
|
||||
|
||||
rules = RulesHelper()
|
||||
data = '{"foo": {"foo": {"foo": "bar"}}}'
|
||||
|
||||
self.check_data(rules.dash_E(['foo.foo.foo.foo.foo']), data, CRITICAL_CODE)
|
||||
|
||||
def test_subarrayelem_missing_elem(self):
|
||||
|
||||
rules = RulesHelper()
|
||||
data = '[{"capacity": {"value": 1000}},{"capacity": {"value": 2200}}]'
|
||||
|
||||
self.check_data(rules.dash_E(['(*).capacity.value']), data, OK_CODE)
|
||||
self.check_data(rules.dash_E(['(*).capacity.value.too_deep']), data, CRITICAL_CODE)
|
||||
# Should not throw keyerror
|
||||
self.check_data(rules.dash_E(['foo']), data, CRITICAL_CODE)
|
||||
|
||||
|
||||
def test_empty_key_value_array(self):
|
||||
"""
|
||||
https://github.com/drewkerrigan/nagios-http-json/issues/61
|
||||
"""
|
||||
|
||||
rules = RulesHelper()
|
||||
|
||||
# This should simply work
|
||||
data = '[{"update_status": "finished"},{"update_status": "finished"}]'
|
||||
self.check_data(rules.dash_q(['(*).update_status,finished']), data, OK_CODE)
|
||||
|
||||
# This should warn us
|
||||
data = '[{"update_status": "finished"},{"update_status": "failure"}]'
|
||||
self.check_data(rules.dash_q(['(*).update_status,finished']), data, WARNING_CODE)
|
||||
|
||||
# This should throw an error
|
||||
data = '[]'
|
||||
self.check_data(rules.dash_q(['(*).update_status,warn_me']), data, CRITICAL_CODE)
|
||||
|
||||
def test_key_time(self):
|
||||
if sys.version_info[1] >= 11:
|
||||
# Test current timestamp.
|
||||
now = datetime.now(timezone.utc)
|
||||
data = "{\"timestamp\": \"%s\",\"timestamp2\": \"%s\"}" % (now, now)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,30s', 'timestamp2,30s']), data, OK_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,30m']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,1h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,3h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,2d']), data, OK_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@30m']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@1h']), data, CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@3h']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@2d']), data, CRITICAL_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,-30m']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,-1h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,-3h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,-2d']), data, OK_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@-30m']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@-1h']), data, CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@-3h']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@-2d']), data, CRITICAL_CODE)
|
||||
|
||||
# Test 31 minute in the past.
|
||||
data = "{\"timestamp\": \"%s\"}" % (now - timedelta(minutes=31))
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,30m']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,1h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,3h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,2d']), data, OK_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@30m']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@1h']), data, CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@3h']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@2d']), data, CRITICAL_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,-30m']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,-1h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,-3h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,-2d']), data, OK_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@-30m']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@-1h']), data, CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@-3h']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@-2d']), data, CRITICAL_CODE)
|
||||
|
||||
# Test two hours and one minute in the past.
|
||||
data = "{\"timestamp\": \"%s\"}" % (now - timedelta(hours=2) - timedelta(minutes=1))
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,30m']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,1h']), data, CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,3h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,2d']), data, OK_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@30m']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@1h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@3h']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@2d']), data, CRITICAL_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,-30m']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,-1h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,-3h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,-2d']), data, OK_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@-30m']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@-1h']), data, CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@-3h']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@-2d']), data, CRITICAL_CODE)
|
||||
|
||||
# Test one day and one minute in the past.
|
||||
data = "{\"timestamp\": \"%s\"}" % (now - timedelta(days=1) - timedelta(minutes=1))
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,30m']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,1h']), data, CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,3h']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,2d']), data, OK_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@30m']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@1h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@3h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@2d']), data, CRITICAL_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,-30m']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,-1h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,-3h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,-2d']), data, OK_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@-30m']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@-1h']), data, CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@-3h']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@-2d']), data, CRITICAL_CODE)
|
||||
|
||||
# Test two hours and one minute in the future.
|
||||
data = "{\"timestamp\": \"%s\"}" % (now + timedelta(hours=2) + timedelta(minutes=1))
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,30m']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,1h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,3h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,2d']), data, OK_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@30m']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@1h']), data, CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@3h']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@2d']), data, CRITICAL_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,-30m']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,-1h']), data, CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,-3h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,-2d']), data, OK_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@-30m']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@-1h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@-3h']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@-2d']), data, CRITICAL_CODE)
|
||||
else:
|
||||
data = "{\"timestamp\": \"2020-01-01\"}"
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,30m']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,1h']), data, CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,3h']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,2d']), data, CRITICAL_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@30m']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@1h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@3h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@2d']), data, OK_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,-30m']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,-1h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,-3h']), data, OK_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,-2d']), data, OK_CODE)
|
||||
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@-30m']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@-1h']), data, CRITICAL_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time(['timestamp,@-3h']), data, WARNING_CODE)
|
||||
self.check_data(RulesHelper().dash_dash_key_time_critical(['timestamp,@-2d']), data, CRITICAL_CODE)
|
||||
48
test/test_cli.py
Normal file
48
test/test_cli.py
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
import unittest
|
||||
import unittest.mock as mock
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.append('..')
|
||||
|
||||
from check_http_json import debugPrint
|
||||
from check_http_json import verbosePrint
|
||||
|
||||
|
||||
class CLITest(unittest.TestCase):
|
||||
"""
|
||||
Tests for CLI
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
"""
|
||||
Defining the exitcodes
|
||||
"""
|
||||
|
||||
self.exit_0 = 0 << 8
|
||||
self.exit_1 = 1 << 8
|
||||
self.exit_2 = 2 << 8
|
||||
self.exit_3 = 3 << 8
|
||||
|
||||
def test_debugprint(self):
|
||||
with mock.patch('builtins.print') as mock_print:
|
||||
debugPrint(True, 'debug')
|
||||
mock_print.assert_called_once_with('debug')
|
||||
|
||||
def test_verbose(self):
|
||||
with mock.patch('builtins.print') as mock_print:
|
||||
verbosePrint(0, 3, 'verbose')
|
||||
mock_print.assert_not_called()
|
||||
|
||||
verbosePrint(3, 3, 'verbose')
|
||||
mock_print.assert_called_once_with('verbose')
|
||||
|
||||
def test_cli_without_params(self):
|
||||
|
||||
command = '/usr/bin/env python3 check_http_json.py > /dev/null 2>&1'
|
||||
status = os.system(command)
|
||||
|
||||
self.assertEqual(status, self.exit_2)
|
||||
131
test/test_main.py
Normal file
131
test/test_main.py
Normal file
@@ -0,0 +1,131 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
import unittest
|
||||
import unittest.mock as mock
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.append('..')
|
||||
|
||||
from check_http_json import main
|
||||
|
||||
|
||||
class MockResponse():
|
||||
def __init__(self, status_code=200, content='{"foo": "bar"}'):
|
||||
self.status_code = status_code
|
||||
self.content = content
|
||||
|
||||
def read(self):
|
||||
return self.content
|
||||
|
||||
|
||||
class MainTest(unittest.TestCase):
|
||||
"""
|
||||
Tests for Main
|
||||
"""
|
||||
|
||||
@mock.patch('builtins.print')
|
||||
def test_main_version(self, mock_print):
|
||||
args = ['--version']
|
||||
|
||||
with self.assertRaises(SystemExit) as test:
|
||||
main(args)
|
||||
|
||||
mock_print.assert_called_once()
|
||||
self.assertEqual(test.exception.code, 0)
|
||||
|
||||
@mock.patch('builtins.print')
|
||||
@mock.patch('urllib.request.urlopen')
|
||||
def test_main_with_ssl(self, mock_request, mock_print):
|
||||
args = '-H localhost --ssl'.split(' ')
|
||||
|
||||
mock_request.return_value = MockResponse()
|
||||
|
||||
with self.assertRaises(SystemExit) as test:
|
||||
main(args)
|
||||
|
||||
self.assertEqual(test.exception.code, 0)
|
||||
|
||||
|
||||
@mock.patch('builtins.print')
|
||||
@mock.patch('urllib.request.urlopen')
|
||||
def test_main_with_parse_error(self, mock_request, mock_print):
|
||||
args = '-H localhost'.split(' ')
|
||||
|
||||
mock_request.return_value = MockResponse(content='not JSON')
|
||||
|
||||
with self.assertRaises(SystemExit) as test:
|
||||
main(args)
|
||||
|
||||
self.assertTrue('Parser error' in str(mock_print.call_args))
|
||||
self.assertEqual(test.exception.code, 3)
|
||||
|
||||
@mock.patch('builtins.print')
|
||||
def test_main_with_url_error(self, mock_print):
|
||||
args = '-H localhost'.split(' ')
|
||||
|
||||
with self.assertRaises(SystemExit) as test:
|
||||
main(args)
|
||||
|
||||
self.assertTrue('URLError' in str(mock_print.call_args))
|
||||
self.assertEqual(test.exception.code, 3)
|
||||
|
||||
@mock.patch('builtins.print')
|
||||
@mock.patch('urllib.request.urlopen')
|
||||
def test_main_with_http_error_no_json(self, mock_request, mock_print):
|
||||
args = '-H localhost'.split(' ')
|
||||
|
||||
mock_request.return_value = MockResponse(content='not JSON', status_code=503)
|
||||
|
||||
with self.assertRaises(SystemExit) as test:
|
||||
main(args)
|
||||
|
||||
self.assertTrue('Parser error' in str(mock_print.call_args))
|
||||
self.assertEqual(test.exception.code, 3)
|
||||
|
||||
@mock.patch('builtins.print')
|
||||
@mock.patch('urllib.request.urlopen')
|
||||
def test_main_with_http_error_valid_json(self, mock_request, mock_print):
|
||||
args = '-H localhost'.split(' ')
|
||||
|
||||
mock_request.return_value = MockResponse(status_code=503)
|
||||
|
||||
with self.assertRaises(SystemExit) as test:
|
||||
main(args)
|
||||
|
||||
self.assertEqual(test.exception.code, 0)
|
||||
|
||||
@mock.patch('builtins.print')
|
||||
def test_main_with_tls(self, mock_print):
|
||||
args = ['-H', 'localhost',
|
||||
'--ssl',
|
||||
'--cacert',
|
||||
'test/tls/ca-root.pem',
|
||||
'--cert',
|
||||
'test/tls/cert.pem',
|
||||
'--key',
|
||||
'test/tls/key.pem']
|
||||
|
||||
with self.assertRaises(SystemExit) as test:
|
||||
main(args)
|
||||
|
||||
self.assertTrue('https://localhost' in str(mock_print.call_args))
|
||||
self.assertEqual(test.exception.code, 3)
|
||||
|
||||
@mock.patch('builtins.print')
|
||||
def test_main_with_tls_wrong_ca(self, mock_print):
|
||||
args = ['-H', 'localhost',
|
||||
'--ssl',
|
||||
'--cacert',
|
||||
'test/tls/key.pem',
|
||||
'--cert',
|
||||
'test/tls/cert.pem',
|
||||
'--key',
|
||||
'test/tls/key.pem']
|
||||
|
||||
with self.assertRaises(SystemExit) as test:
|
||||
main(args)
|
||||
|
||||
self.assertTrue('Error loading SSL CA' in str(mock_print.call_args))
|
||||
self.assertEqual(test.exception.code, 3)
|
||||
51
test/test_nagioshelper.py
Normal file
51
test/test_nagioshelper.py
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
import json
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
import sys
|
||||
|
||||
sys.path.append('..')
|
||||
|
||||
from check_http_json import *
|
||||
|
||||
|
||||
class NagiosHelperTest(unittest.TestCase):
|
||||
"""
|
||||
Tests for the NagiosHelper
|
||||
"""
|
||||
|
||||
def test_getcode_default(self):
|
||||
|
||||
helper = NagiosHelper()
|
||||
self.assertEqual(0, helper.getCode())
|
||||
|
||||
def test_getcode_warning(self):
|
||||
|
||||
helper = NagiosHelper()
|
||||
helper.warning_message = 'foobar'
|
||||
self.assertEqual(1, helper.getCode())
|
||||
|
||||
def test_getcode_critical(self):
|
||||
|
||||
helper = NagiosHelper()
|
||||
helper.critical_message = 'foobar'
|
||||
self.assertEqual(2, helper.getCode())
|
||||
|
||||
def test_getcode_unknown(self):
|
||||
|
||||
helper = NagiosHelper()
|
||||
helper.unknown_message = 'foobar'
|
||||
self.assertEqual(3, helper.getCode())
|
||||
|
||||
def test_getmessage_default(self):
|
||||
|
||||
helper = NagiosHelper()
|
||||
self.assertEqual('OK: Status OK.', helper.getMessage())
|
||||
|
||||
def test_getmessage_perfomance_data(self):
|
||||
|
||||
helper = NagiosHelper()
|
||||
helper.performance_data = 'foobar'
|
||||
self.assertEqual('OK: foobar Status OK. |foobar', helper.getMessage())
|
||||
65
test/testdata/README.md
vendored
Normal file
65
test/testdata/README.md
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
# Example Data for Testing
|
||||
|
||||
Example calls:
|
||||
|
||||
```bash
|
||||
python check_http_json.py -H localhost:8080 -p data0.json -q "age,20"
|
||||
UNKNOWN: Status UNKNOWN. Could not find JSON in HTTP body.
|
||||
```
|
||||
|
||||
```bash
|
||||
python check_http_json.py -H localhost:8080 -p data1.json -e date
|
||||
WARNING: Status WARNING. Key date did not exist.
|
||||
|
||||
python check_http_json.py -H localhost:8080 -p data1.json -E age
|
||||
OK: Status OK.
|
||||
|
||||
python check_http_json.py -H localhost:8080 -p data1.json -w "age,30"
|
||||
OK: Status OK.
|
||||
|
||||
python check_http_json.py -H localhost:8080 -p data1.json -w "age,20"
|
||||
WARNING: Status WARNING. Value (30) for key age was outside the range 0:20.
|
||||
|
||||
python check_http_json.py -H localhost:8080 -p data1.json -q "age,20"
|
||||
WARNING: Status WARNING. Key age mismatch. 20 != 30
|
||||
```
|
||||
|
||||
```bash
|
||||
python check_http_json.py -H localhost:8080 -p data2.json -q "(1).id,123"
|
||||
WARNING: Status WARNING. Key (1).id mismatch. 123 != 2
|
||||
|
||||
python check_http_json.py -H localhost:8080 -p data2.json -Y "(1).id,2"
|
||||
CRITICAL: Status CRITICAL. Key (1).id match found. 2 == 2
|
||||
|
||||
python check_http_json.py -H localhost:8080 -p data2.json -E "(1).author"
|
||||
OK: Status OK.
|
||||
|
||||
python check_http_json.py -H localhost:8080 -p data2.json -E "(1).pages"
|
||||
CRITICAL: Status CRITICAL. Key (1).pages did not exist.
|
||||
```
|
||||
|
||||
```bash
|
||||
python check_http_json.py -H localhost:8080 -p data3.json -q "company.employees.(0).role,Developer"
|
||||
OK: Status OK.
|
||||
|
||||
python check_http_json.py -H localhost:8080 -p data3.json -q "company.employees.(0).role,Dev"
|
||||
WARNING: Status WARNING. Key company.employees.(0).role mismatch. Dev != Developer
|
||||
|
||||
python check_http_json.py -H localhost:8080 -p data3.json -q "company.employees.(0).role,Developer" "company.employees.(1).role,Designer"
|
||||
OK: Status OK.
|
||||
```
|
||||
|
||||
```bash
|
||||
python check_http_json.py -H localhost:8080 -p data4.json -u "ratings(0),4.5"
|
||||
OK: Status OK.
|
||||
|
||||
python check_http_json.py -H localhost:8080 -p data4.json -u "ratings(0),4.1"
|
||||
UNKNOWN: Status UNKNOWN. Key ratings(0) mismatch. 4.1 != 4.5
|
||||
```
|
||||
|
||||
```bash
|
||||
python check_http_json.py -H localhost:8080 -p data5.json -q service1.status,True service2.status,True service3.status,True
|
||||
OK: Status OK.
|
||||
|
||||
python check_http_json.py -H localhost:8080 -p data5.json -q "service1.status,True" -q "service2.status,True" -q "service3.status,False"
|
||||
```
|
||||
1
test/testdata/data0-invalid.json
vendored
Normal file
1
test/testdata/data0-invalid.json
vendored
Normal file
@@ -0,0 +1 @@
|
||||
No JSON
|
||||
5
test/testdata/data1.json
vendored
Normal file
5
test/testdata/data1.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "John Doe",
|
||||
"age": 30,
|
||||
"city": "New York"
|
||||
}
|
||||
17
test/testdata/data2.json
vendored
Normal file
17
test/testdata/data2.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"title": "Book One",
|
||||
"author": "Author One"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"title": "Book Two",
|
||||
"author": "Author Two"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"title": "Book Three",
|
||||
"author": "Author Three"
|
||||
}
|
||||
]
|
||||
18
test/testdata/data3.json
vendored
Normal file
18
test/testdata/data3.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"company": {
|
||||
"name": "Tech Corp",
|
||||
"location": "San Francisco",
|
||||
"employees": [
|
||||
{
|
||||
"name": "Alice",
|
||||
"role": "Developer"
|
||||
},
|
||||
{
|
||||
"name": "Bob",
|
||||
"role": "Designer"
|
||||
}
|
||||
]
|
||||
},
|
||||
"founded": 2010,
|
||||
"industry": "Technology"
|
||||
}
|
||||
13
test/testdata/data4.json
vendored
Normal file
13
test/testdata/data4.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"id": 123,
|
||||
"active": true,
|
||||
"tags": ["tech", "startup", "innovation"],
|
||||
"details": {
|
||||
"website": "https://example.com",
|
||||
"contact": {
|
||||
"email": "info@example.com",
|
||||
"phone": "+1-234-567-890"
|
||||
}
|
||||
},
|
||||
"ratings": [4.5, 4.7, 4.8]
|
||||
}
|
||||
38
test/testdata/data5.json
vendored
Normal file
38
test/testdata/data5.json
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"service1": {
|
||||
"status": true
|
||||
},
|
||||
"service2": {
|
||||
"status": true,
|
||||
"meta": {
|
||||
"res": "PONG"
|
||||
}
|
||||
},
|
||||
"service3": {
|
||||
"status": true,
|
||||
"meta": {
|
||||
"took": 9,
|
||||
"timed_out": false,
|
||||
"_shards": {
|
||||
"total": 0,
|
||||
"successful": 0,
|
||||
"skipped": 0,
|
||||
"failed": 0
|
||||
},
|
||||
"hits": {
|
||||
"total": {
|
||||
"value": 10000,
|
||||
"relation": "gte"
|
||||
},
|
||||
"max_score": null,
|
||||
"hits": []
|
||||
}
|
||||
}
|
||||
},
|
||||
"service4": {
|
||||
"status": true,
|
||||
"meta": {
|
||||
"status": "ok"
|
||||
}
|
||||
}
|
||||
}
|
||||
7
test/testdata/docker-compose.yml
vendored
Normal file
7
test/testdata/docker-compose.yml
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
services:
|
||||
nginx:
|
||||
image: nginx:1-alpine
|
||||
ports:
|
||||
- "8080:80"
|
||||
volumes:
|
||||
- ./:/usr/share/nginx/html
|
||||
21
test/tls/ca-root.pem
Normal file
21
test/tls/ca-root.pem
Normal file
@@ -0,0 +1,21 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDbTCCAlWgAwIBAgIUB6EZDl3ajJgJsoLzyC9DrOQQpKowDQYJKoZIhvcNAQEN
|
||||
BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
|
||||
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAgFw0yNDAzMTgwODE5MDhaGA8yMDUx
|
||||
MDgwMzA4MTkwOFowRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUx
|
||||
ITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDCCASIwDQYJKoZIhvcN
|
||||
AQEBBQADggEPADCCAQoCggEBALVxioj+6zw6Snr+B1JOivC8Of6YptVYym5ICiHX
|
||||
wjpbSVVe+Py/P2LDb/uQ1QkAENlpvChFqSaRBZU5keXYS/DaFb2Evb2/zf5qIdWU
|
||||
2ju8B5V13gXSeaNNetyEn1Ivvk0lOCQo2RwEZXuStpLS4Q32rkRBvkoL+RXDc1NX
|
||||
c3RwcU1p9ybgBqAC7FYdV82sgHGugIrbzkjfFREJXp1AnqvKAdk39b1CnPxfmPZC
|
||||
nzPPetfr3iivH8yVO5rodU/LDtQNph22JR94YvPB89QO+bZ9bw2GHtPdAKFew9HF
|
||||
UxM1fmy381Mq2iS3KUq5vsC1jMe8slUAIFYEDzoPvOz+MpcCAwEAAaNTMFEwHQYD
|
||||
VR0OBBYEFOmCb+JnMzX29hwgtXSzrN+m6mTDMB8GA1UdIwQYMBaAFOmCb+JnMzX2
|
||||
9hwgtXSzrN+m6mTDMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQENBQADggEB
|
||||
AAkTD8K4UO4uO4i6p2BCofbhVm9LYA0ulmLO8Uro0U491TeEDOQpgMFAK+b2gZIU
|
||||
zvDHoCMn3UPVxHKl7XzDgLZVkYYEc2s9vArxk5vSnFmh3XvlDu2SO5gSLB2sf68A
|
||||
2+Jz2x6z9tjWWdZCGJWU/iwMbG2Y3JMHyv1NMF8cyOclJaSDNBAwF5c5sdlGTLKb
|
||||
WHGXzVqHSAFlGcHtQrcEKclHiuzw2G3LZzwghGk0XzxwvyKrnAEy408RY0mfNLtz
|
||||
32KHqYtrip0RYlGWKP7/7q6i0D8muEFW/I4emFI0z0I/1CcYZZS8tQkWaPf/wCN0
|
||||
llTD1kKJACsIMaqkkyy+EZM=
|
||||
-----END CERTIFICATE-----
|
||||
19
test/tls/cert.pem
Normal file
19
test/tls/cert.pem
Normal file
@@ -0,0 +1,19 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDDzCCAfcCFBOrBcHIH2x9xcUyUeDid0cvBxWtMA0GCSqGSIb3DQEBDQUAMEUx
|
||||
CzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRl
|
||||
cm5ldCBXaWRnaXRzIFB0eSBMdGQwIBcNMjQwMzE4MDgxOTM1WhgPMjA1MTA4MDMw
|
||||
ODE5MzVaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYD
|
||||
VQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggEeMA0GCSqGSIb3DQEBAQUA
|
||||
A4IBCwAwggEGAoH+ALuzyIhEATF5YyAOsXKfr2mttF2HyJvEscGcoA7YetT57bjJ
|
||||
5lg944kc3QH/wTEdrGda3cwh3OXdUuyR7Wrm9jPw38hMArx/fWPkiISOShrUSHGd
|
||||
Qyy2bT+zxBaUo+pomyrlqlgwGlbxuwTAlTSFcI+i7yXrckl2HRj40EW4FNsYpPzv
|
||||
maxRXs0kg0J2JLTYF+fHlqlYbSX/hRU9wz2DYfkRSS0+OYJNSmqK0jayUsdZYurG
|
||||
gbPwOCgQ0QxLLh7P8z4sOanRowqUzqTI77cyUugEJRyoi+LJr4r0EwMTBX3STgPh
|
||||
S9B78+LNvwOrLrZFUhr144RfO9QPLnz0uWcCAwEAATANBgkqhkiG9w0BAQ0FAAOC
|
||||
AQEAeIR21PfLzgpL7WDBE2KgwI78nVc1wY9nwoAxSBzHjS0Olve3r9MaVzAKn5ZS
|
||||
xHtv8oroXjhTcczCIzxii6Imp6u0iIr3QVBIceofxrH3aWmICURcC9l+dIiY6sk9
|
||||
Ct8P8gm/Erv2iF/7bnsARwDnw0f41fC9eXtHZ7WLRQrc7tLHpjL0Z7bT77ysQJVK
|
||||
C1SWtBnq3afmwH3R1wVHENn0JVFQpBp+vqWU5KIlvjcz49yPU+aNODk1rJsHMlgS
|
||||
x2iddwF31GNOxNfXtw8fdw4UDUl2wYoZ45w2e2pXt4pbN43m0Wys1eQZdk3tyR6G
|
||||
AZOLP05073mLtbVlFRmcTdXIGg==
|
||||
-----END CERTIFICATE-----
|
||||
27
test/tls/key.pem
Normal file
27
test/tls/key.pem
Normal file
@@ -0,0 +1,27 @@
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIIEqAIBADANBgkqhkiG9w0BAQEFAASCBJIwggSOAgEAAoH+ALuzyIhEATF5YyAO
|
||||
sXKfr2mttF2HyJvEscGcoA7YetT57bjJ5lg944kc3QH/wTEdrGda3cwh3OXdUuyR
|
||||
7Wrm9jPw38hMArx/fWPkiISOShrUSHGdQyy2bT+zxBaUo+pomyrlqlgwGlbxuwTA
|
||||
lTSFcI+i7yXrckl2HRj40EW4FNsYpPzvmaxRXs0kg0J2JLTYF+fHlqlYbSX/hRU9
|
||||
wz2DYfkRSS0+OYJNSmqK0jayUsdZYurGgbPwOCgQ0QxLLh7P8z4sOanRowqUzqTI
|
||||
77cyUugEJRyoi+LJr4r0EwMTBX3STgPhS9B78+LNvwOrLrZFUhr144RfO9QPLnz0
|
||||
uWcCAwEAAQKB/UQAYzMy5/fDkWzoxdLQFV3E56ZG7h+4x+lr0/Ts6rtD/KLIyqHH
|
||||
ciqXgV4bCSPBK1eabOZqkjvYzhUU3R2wpRu2NWy8VPVzfrr07ZyQbDqCE+jNX6vQ
|
||||
P44nk2/W0/e1hBmrcOZYLwK2utmC58tKWLhBAEENpq8EkpAcfF/1y9aRHKYwNnH7
|
||||
vouoQibN5NTs5m8s0VyjRTDwRZja98eWnn5NfU3orqYO8fSlF6CyzDtoyhMco6zR
|
||||
0skBgMzRYCRTuJpV+KekC7XFYyiJ6XZN5DKLbbqP6Y7YR8wjyFEruoGCS0mZH2H0
|
||||
9/rhTsJram1B2zohXHPsHJGGGv12/7kCfw5C7yda+8Yv0NmRp1F+EJYb75SCAWIP
|
||||
kzN/xvjP2bMKa6oSzU0DOga3Wc4ijJHDaND8rqdPqQe3zXFr1nPdBrybLSJ6k5CN
|
||||
4Dd6ENJWVWino0L460kpLtlBG6TsgmB8bkwhjWVE6Vgt4Vila+a3TGRXeniaRzdw
|
||||
icNOtMrjYlUCfw0pWEvO2uFq0DbNZbmzC2j5ClFcU96CAl4AqKG2PiGnuSy9TKVZ
|
||||
c5OiXFmyoig7v4LJzaKLSqVIN4hVBU80/MlhvG+dpeimvLaQKNtlZQethIs5hXlB
|
||||
R1XfaPhq6BQiYmQ3tufyS/0Es2OY+Cs3LU1uDB8qVzonlmnIi69OwMsCfwRPISfJ
|
||||
C+4UIIy8v8uVxbk1c6xxo61Xe2jCIQKo+uRoL6PRzoqIgQ3qdI4eTk70tkT/NF6F
|
||||
aVNVrBOrO78Cd7ihQn/6fX/d/nOExHRpdaELlf70a1NNyEQIsiug8rvonQMP2ENT
|
||||
ERZ9tmssgG/Tzpc6/1xVcVNFA7spmuL61YkCfwnu2zGTc0PO7kd96rkktIbL9YqD
|
||||
6NQ0QH8bdildtjSGNc3bLB5ajUytq48Sryk4NogJr8Vt5K8q+qZMrE4kCmgd+C4w
|
||||
x4b3V9Ncp0k1k/MgdLjyd5aUurbHfpyFapPPg3xpRAR3q/vP8WdIintrECiw1jsr
|
||||
JFvChtVdQnbTM9MCfw41RcjNwCaIG+uXc8bD6Yf+NyXD8zP6ZDywmBlkMWlGSzx4
|
||||
xM8J+wQiQsNWthDBbF7inJc+lbtJiEe4YOPkbjCYVZRHribL65HKJlEUv6M9bvQo
|
||||
3P1DS5tDrwo6z9UPs4tD1SgF9fDu/xA7fwPF1RTvuW07MhFJWlDo4FSWS9c=
|
||||
-----END PRIVATE KEY-----
|
||||
Reference in New Issue
Block a user