mirror of
https://github.com/drewkerrigan/nagios-http-json.git
synced 2026-02-12 01:51:01 +01:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46271c961b | ||
|
|
49b338bdb6 | ||
|
|
9f41fc491e | ||
|
|
3a22b712ab | ||
|
|
9626fc4464 | ||
|
|
c54a0040a0 | ||
|
|
ffd96dd59f | ||
|
|
0572c2f494 | ||
|
|
2e6eaeea59 | ||
|
|
428a5a6d3a | ||
|
|
e3ac06864d | ||
|
|
63542f3226 | ||
|
|
cdb2474ee0 | ||
|
|
2821a1ae66 | ||
|
|
831bfdf97b | ||
|
|
f612277772 | ||
|
|
1f440e0ff5 |
15
.github/workflows/unittest.yml
vendored
15
.github/workflows/unittest.yml
vendored
@@ -7,21 +7,20 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version: [3.6, 3.7, 3.8]
|
python-version: [3.8, 3,9]
|
||||||
name: GitHub Action
|
name: GitHub Action
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
python -m pip install -r requirements-dev.txt
|
||||||
- name: Lint
|
- name: Lint
|
||||||
run: |
|
run: |
|
||||||
pip3 install --upgrade pip wheel setuptools
|
make lint
|
||||||
pip3 install pylint
|
|
||||||
python3 -m pylint check_http_json.py
|
|
||||||
- name: Unit Test
|
- name: Unit Test
|
||||||
run: |
|
run: |
|
||||||
python3 -m unittest discover
|
make test
|
||||||
- name: Coverage
|
- name: Coverage
|
||||||
run: |
|
run: |
|
||||||
pip3 install coverage
|
make coverage
|
||||||
python3 -m coverage run -m unittest discover
|
|
||||||
python3 -m coverage report -m --include check_http_json.py
|
|
||||||
|
|||||||
20
.pylintrc
20
.pylintrc
@@ -1,5 +1,21 @@
|
|||||||
# pylint config
|
# pylint config
|
||||||
[MESSAGES CONTROL]
|
|
||||||
disable=line-too-long, redefined-outer-name, too-many-arguments, too-many-instance-attributes, fixme, invalid-name, superfluous-parens, missing-function-docstring, missing-module-docstring, multiple-imports, no-else-return, too-many-return-statements, too-many-branches, too-many-statements
|
|
||||||
[MASTER]
|
[MASTER]
|
||||||
ignore-patterns=^test.*
|
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
|
||||||
|
|||||||
9
Makefile
Normal file
9
Makefile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
.PHONY: lint test coverage
|
||||||
|
|
||||||
|
lint:
|
||||||
|
python -m pylint check_http_json.py
|
||||||
|
test:
|
||||||
|
python -m unittest discover
|
||||||
|
coverage:
|
||||||
|
python -m coverage run -m unittest discover
|
||||||
|
python -m coverage report -m --include check_http_json.py
|
||||||
@@ -38,7 +38,7 @@ Generic Nagios plugin which checks json values from a given endpoint against
|
|||||||
argument specified rules and determines the status and performance data for
|
argument specified rules and determines the status and performance data for
|
||||||
that service.
|
that service.
|
||||||
|
|
||||||
Version: 2.0.0 (2020-03-22)
|
Version: 2.1.2 (2022-09-15)
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
@@ -46,6 +46,8 @@ optional arguments:
|
|||||||
-s, --ssl use TLS to connect to remote host
|
-s, --ssl use TLS to connect to remote host
|
||||||
-H HOST, --host HOST remote host to query
|
-H HOST, --host HOST remote host to query
|
||||||
-k, --insecure do not check server SSL certificate
|
-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
|
-V, --version print version of this plugin
|
||||||
--cacert CACERT SSL CA certificate
|
--cacert CACERT SSL CA certificate
|
||||||
--cert CERT SSL client certificate
|
--cert CERT SSL client certificate
|
||||||
@@ -210,7 +212,7 @@ More info about Nagios Range format and Units of Measure can be found at [https:
|
|||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
|
|
||||||
* Python 3
|
* Python 3.6+
|
||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ WARNING_CODE = 1
|
|||||||
CRITICAL_CODE = 2
|
CRITICAL_CODE = 2
|
||||||
UNKNOWN_CODE = 3
|
UNKNOWN_CODE = 3
|
||||||
|
|
||||||
__version__ = '2.0.0'
|
__version__ = '2.1.2'
|
||||||
__version_date__ = '2020-03-22'
|
__version_date__ = '2022-09-15'
|
||||||
|
|
||||||
class NagiosHelper:
|
class NagiosHelper:
|
||||||
"""
|
"""
|
||||||
@@ -152,7 +152,7 @@ class JsonHelper:
|
|||||||
(Element.Key.NestedKey). Returns (None, 'not_found') if not found
|
(Element.Key.NestedKey). Returns (None, 'not_found') if not found
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if temp_data:
|
if temp_data != '':
|
||||||
data = temp_data
|
data = temp_data
|
||||||
else:
|
else:
|
||||||
data = self.data
|
data = self.data
|
||||||
@@ -430,6 +430,8 @@ def parseArgs(args):
|
|||||||
help='remote host to query')
|
help='remote host to query')
|
||||||
parser.add_argument('-k', '--insecure', action='store_true',
|
parser.add_argument('-k', '--insecure', action='store_true',
|
||||||
help='do not check server SSL certificate')
|
help='do not check server SSL certificate')
|
||||||
|
parser.add_argument('-X', '--request', dest='method', default='GET', choices=['GET', 'POST'],
|
||||||
|
help='Specifies a custom request method to use when communicating with the HTTP server')
|
||||||
parser.add_argument('-V', '--version', action='store_true',
|
parser.add_argument('-V', '--version', action='store_true',
|
||||||
help='print version of this plugin')
|
help='print version of this plugin')
|
||||||
parser.add_argument('--cacert',
|
parser.add_argument('--cacert',
|
||||||
@@ -542,7 +544,7 @@ def main(cliargs):
|
|||||||
if args.ssl:
|
if args.ssl:
|
||||||
url = "https://%s" % args.host
|
url = "https://%s" % args.host
|
||||||
|
|
||||||
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
|
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
||||||
context.options |= ssl.OP_NO_SSLv2
|
context.options |= ssl.OP_NO_SSLv2
|
||||||
context.options |= ssl.OP_NO_SSLv3
|
context.options |= ssl.OP_NO_SSLv3
|
||||||
|
|
||||||
@@ -550,6 +552,7 @@ def main(cliargs):
|
|||||||
context.verify_mode = ssl.CERT_NONE
|
context.verify_mode = ssl.CERT_NONE
|
||||||
else:
|
else:
|
||||||
context.verify_mode = ssl.CERT_OPTIONAL
|
context.verify_mode = ssl.CERT_OPTIONAL
|
||||||
|
context.load_default_certs()
|
||||||
if args.cacert:
|
if args.cacert:
|
||||||
try:
|
try:
|
||||||
context.load_verify_locations(args.cacert)
|
context.load_verify_locations(args.cacert)
|
||||||
@@ -586,7 +589,7 @@ def main(cliargs):
|
|||||||
json_data = ''
|
json_data = ''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
req = urllib.request.Request(url)
|
req = urllib.request.Request(url, method=args.method)
|
||||||
req.add_header("User-Agent", "check_http_json")
|
req.add_header("User-Agent", "check_http_json")
|
||||||
if args.auth:
|
if args.auth:
|
||||||
authbytes = str(args.auth).encode()
|
authbytes = str(args.auth).encode()
|
||||||
@@ -598,14 +601,17 @@ def main(cliargs):
|
|||||||
for header in headers:
|
for header in headers:
|
||||||
req.add_header(header, headers[header])
|
req.add_header(header, headers[header])
|
||||||
if args.timeout and args.data:
|
if args.timeout and args.data:
|
||||||
|
databytes = str(args.data).encode()
|
||||||
response = urllib.request.urlopen(req, timeout=args.timeout,
|
response = urllib.request.urlopen(req, timeout=args.timeout,
|
||||||
data=args.data, context=context)
|
data=databytes, context=context)
|
||||||
elif args.timeout:
|
elif args.timeout:
|
||||||
response = urllib.request.urlopen(req, timeout=args.timeout,
|
response = urllib.request.urlopen(req, timeout=args.timeout,
|
||||||
context=context)
|
context=context)
|
||||||
elif args.data:
|
elif args.data:
|
||||||
response = urllib.request.urlopen(req, data=args.data, context=context)
|
databytes = str(args.data).encode()
|
||||||
|
response = urllib.request.urlopen(req, data=databytes, context=context)
|
||||||
else:
|
else:
|
||||||
|
# pylint: disable=consider-using-with
|
||||||
response = urllib.request.urlopen(req, context=context)
|
response = urllib.request.urlopen(req, context=context)
|
||||||
|
|
||||||
json_data = response.read()
|
json_data = response.read()
|
||||||
|
|||||||
@@ -97,8 +97,8 @@ object CheckCommand "http_json" {
|
|||||||
value = "$http_json_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."
|
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_metrics" = {
|
"--key_metric" = {
|
||||||
value = "$http_json_key_metrics$"
|
value = "$http_json_key_metric$"
|
||||||
description = "Gathers the values of these keys"
|
description = "Gathers the values of these keys"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9
makefile
9
makefile
@@ -1,9 +0,0 @@
|
|||||||
.PHONY: lint test coverage
|
|
||||||
|
|
||||||
lint:
|
|
||||||
python3 -m pylint check_http_json.py
|
|
||||||
test:
|
|
||||||
python3 -m unittest discover
|
|
||||||
coverage:
|
|
||||||
python3 -m coverage run -m unittest discover
|
|
||||||
python3 -m coverage report -m --include check_http_json.py
|
|
||||||
2
requirements-dev.txt
Normal file
2
requirements-dev.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
coverage==6.4.4
|
||||||
|
pylint==2.15.2
|
||||||
Reference in New Issue
Block a user