mirror of
https://github.com/drewkerrigan/nagios-http-json.git
synced 2025-05-10 09:53:44 +02:00
Support Untrusted SSL Certificates
Added support for ssl conections with untrusted certificates
This commit is contained in:
parent
ed7bc7175b
commit
6313f790f2
21
README.md
21
README.md
@ -15,16 +15,16 @@ This is a generic plugin for Nagios which checks json values from a given HTTP e
|
|||||||
Executing `./check_http_json.py -h` will yield the following details:
|
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]
|
usage: check_http_json2.py [-h] [-d] [-s] [-i] -H HOST [-P PORT] [-p PATH]
|
||||||
[-t TIMEOUT] [-B AUTH] [-D DATA] [-A HEADERS]
|
[-t TIMEOUT] [-B AUTH] [-D DATA] [-A HEADERS]
|
||||||
[-f SEPARATOR]
|
[-f SEPARATOR]
|
||||||
[-w [KEY_THRESHOLD_WARNING [KEY_THRESHOLD_WARNING ...]]]
|
[-w [KEY_THRESHOLD_WARNING [KEY_THRESHOLD_WARNING ...]]]
|
||||||
[-c [KEY_THRESHOLD_CRITICAL [KEY_THRESHOLD_CRITICAL ...]]]
|
[-c [KEY_THRESHOLD_CRITICAL [KEY_THRESHOLD_CRITICAL ...]]]
|
||||||
[-e [KEY_LIST [KEY_LIST ...]]]
|
[-e [KEY_LIST [KEY_LIST ...]]]
|
||||||
[-E [KEY_LIST_CRITICAL [KEY_LIST_CRITICAL ...]]]
|
[-E [KEY_LIST_CRITICAL [KEY_LIST_CRITICAL ...]]]
|
||||||
[-q [KEY_VALUE_LIST [KEY_VALUE_LIST ...]]]
|
[-q [KEY_VALUE_LIST [KEY_VALUE_LIST ...]]]
|
||||||
[-Q [KEY_VALUE_LIST_CRITICAL [KEY_VALUE_LIST_CRITICAL ...]]]
|
[-Q [KEY_VALUE_LIST_CRITICAL [KEY_VALUE_LIST_CRITICAL ...]]]
|
||||||
[-m [METRIC_LIST [METRIC_LIST ...]]]
|
[-m [METRIC_LIST [METRIC_LIST ...]]]
|
||||||
|
|
||||||
Nagios plugin which checks json values from a given endpoint against argument
|
Nagios plugin which checks json values from a given endpoint against argument
|
||||||
specified rules and determines the status and performance data for that
|
specified rules and determines the status and performance data for that
|
||||||
@ -34,6 +34,7 @@ optional arguments:
|
|||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-d, --debug Debug mode.
|
-d, --debug Debug mode.
|
||||||
-s, --ssl HTTPS mode.
|
-s, --ssl HTTPS mode.
|
||||||
|
-i, --ignorecerts Ignore SSL Certificates.
|
||||||
-H HOST, --host HOST Host.
|
-H HOST, --host HOST Host.
|
||||||
-P PORT, --port PORT TCP port
|
-P PORT, --port PORT TCP port
|
||||||
-p PATH, --path PATH Path.
|
-p PATH, --path PATH Path.
|
||||||
|
@ -14,10 +14,10 @@ import sys
|
|||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from urllib2 import HTTPError
|
from urllib2 import HTTPError
|
||||||
from urllib2 import URLError
|
from urllib2 import URLError
|
||||||
|
import ssl
|
||||||
|
|
||||||
# TEST = False
|
# TEST = False
|
||||||
|
|
||||||
|
|
||||||
OK_CODE = 0
|
OK_CODE = 0
|
||||||
WARNING_CODE = 1
|
WARNING_CODE = 1
|
||||||
CRITICAL_CODE = 2
|
CRITICAL_CODE = 2
|
||||||
@ -269,6 +269,7 @@ def parseArgs():
|
|||||||
# parser.add_argument('-v', '--verbose', action='store_true', help='Verbose Output')
|
# parser.add_argument('-v', '--verbose', action='store_true', help='Verbose Output')
|
||||||
parser.add_argument('-d', '--debug', action='store_true', help='Debug mode.')
|
parser.add_argument('-d', '--debug', action='store_true', help='Debug mode.')
|
||||||
parser.add_argument('-s', '--ssl', action='store_true', help='HTTPS mode.')
|
parser.add_argument('-s', '--ssl', action='store_true', help='HTTPS mode.')
|
||||||
|
parser.add_argument('-i', '--ignorecerts', action='store_true', help='Ignore Untrusted SSL Certificates.')
|
||||||
parser.add_argument('-H', '--host', dest='host', required=True, help='Host.')
|
parser.add_argument('-H', '--host', dest='host', required=True, help='Host.')
|
||||||
parser.add_argument('-P', '--port', dest='port', help='TCP port')
|
parser.add_argument('-P', '--port', dest='port', help='TCP port')
|
||||||
parser.add_argument('-p', '--path', dest='path', help='Path.')
|
parser.add_argument('-p', '--path', dest='path', help='Path.')
|
||||||
@ -404,6 +405,11 @@ if __name__ == "__main__":
|
|||||||
if args.port: url += ":%s" % args.port
|
if args.port: url += ":%s" % args.port
|
||||||
if args.path: url += "/%s" % args.path
|
if args.path: url += "/%s" % args.path
|
||||||
debugPrint(args.debug, "url:%s" % url)
|
debugPrint(args.debug, "url:%s" % url)
|
||||||
|
# Ignore Untrusted SSL Certificates?
|
||||||
|
if args.ignorecerts:
|
||||||
|
context = ssl._create_unverified_context()
|
||||||
|
else:
|
||||||
|
context = ""
|
||||||
# Attempt to reach the endpoint
|
# Attempt to reach the endpoint
|
||||||
try:
|
try:
|
||||||
req = urllib2.Request(url)
|
req = urllib2.Request(url)
|
||||||
@ -416,13 +422,13 @@ if __name__ == "__main__":
|
|||||||
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:
|
||||||
response = urllib2.urlopen(req, timeout=args.timeout, data=args.data)
|
response = urllib2.urlopen(req, timeout=args.timeout, data=args.data, context=context)
|
||||||
elif args.timeout:
|
elif args.timeout:
|
||||||
response = urllib2.urlopen(req, timeout=args.timeout)
|
response = urllib2.urlopen(req, timeout=args.timeout, context=context)
|
||||||
elif args.data:
|
elif args.data:
|
||||||
response = urllib2.urlopen(req, data=args.data)
|
response = urllib2.urlopen(req, data=args.data, context=context)
|
||||||
else:
|
else:
|
||||||
response = urllib2.urlopen(req)
|
response = urllib2.urlopen(req, context=context)
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
nagios.append_unknown("HTTPError[%s], url:%s" % (str(e.code), url))
|
nagios.append_unknown("HTTPError[%s], url:%s" % (str(e.code), url))
|
||||||
except URLError as e:
|
except URLError as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user