mirror of
https://github.com/drewkerrigan/nagios-http-json.git
synced 2024-11-22 10:23:50 +01:00
Support for custom HTTP Headers added using -A parameter.
This commit is contained in:
parent
6f9048fc75
commit
fbebf05f76
@ -16,7 +16,8 @@ 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_json.py [-h] [-d] [-s] -H HOST [-P PORT] [-p PATH]
|
||||||
[-t TIMEOUT] [-B AUTH] [-D DATA] [-f SEPARATOR]
|
[-t TIMEOUT] [-B AUTH] [-D DATA] [-A HEADERS]
|
||||||
|
[-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 ...]]]
|
||||||
@ -41,6 +42,8 @@ optional arguments:
|
|||||||
-B AUTH, --basic-auth AUTH
|
-B AUTH, --basic-auth AUTH
|
||||||
Basic auth string "username:password"
|
Basic auth string "username:password"
|
||||||
-D DATA, --data DATA The http payload to send as a POST
|
-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
|
-f SEPARATOR, --field_separator SEPARATOR
|
||||||
Json Field separator, defaults to "." ; Select element
|
Json Field separator, defaults to "." ; Select element
|
||||||
in an array with "(" ")"
|
in an array with "(" ")"
|
||||||
@ -156,6 +159,10 @@ optional arguments:
|
|||||||
|
|
||||||
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).
|
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).
|
||||||
|
|
||||||
|
#### Using Headers
|
||||||
|
|
||||||
|
* `./check_http_json.py -H <host>:<port> -p <path> -A '{"content-type": "application/json"}' -w "metric,RANGE"`
|
||||||
|
|
||||||
## Nagios Installation
|
## Nagios Installation
|
||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
|
@ -56,7 +56,7 @@ class NagiosHelper:
|
|||||||
def append_critical(self, critical_message):
|
def append_critical(self, critical_message):
|
||||||
self.critical_message += critical_message
|
self.critical_message += critical_message
|
||||||
def append_unknown(self, unknown_message):
|
def append_unknown(self, unknown_message):
|
||||||
self.critical_message += critical_message
|
self.critical_message += unknown_message
|
||||||
def append_metrics(self, (performance_data, warning_message, critical_message)):
|
def append_metrics(self, (performance_data, warning_message, critical_message)):
|
||||||
self.performance_data += performance_data
|
self.performance_data += performance_data
|
||||||
self.append_warning(warning_message)
|
self.append_warning(warning_message)
|
||||||
@ -275,6 +275,7 @@ def parseArgs():
|
|||||||
parser.add_argument('-t', '--timeout', type=int, help='Connection timeout (seconds)')
|
parser.add_argument('-t', '--timeout', type=int, help='Connection timeout (seconds)')
|
||||||
parser.add_argument('-B', '--basic-auth', dest='auth', help='Basic auth string "username:password"')
|
parser.add_argument('-B', '--basic-auth', dest='auth', help='Basic auth string "username:password"')
|
||||||
parser.add_argument('-D', '--data', dest='data', help='The http payload to send as a POST')
|
parser.add_argument('-D', '--data', dest='data', help='The http payload to send as a POST')
|
||||||
|
parser.add_argument('-A', '--headers', dest='headers', help='The http headers in JSON format.')
|
||||||
parser.add_argument('-f', '--field_separator', dest='separator',
|
parser.add_argument('-f', '--field_separator', dest='separator',
|
||||||
help='Json Field separator, defaults to "." ; Select element in an array with "(" ")"')
|
help='Json Field separator, defaults to "." ; Select element in an array with "(" ")"')
|
||||||
parser.add_argument('-w', '--warning', dest='key_threshold_warning', nargs='*',
|
parser.add_argument('-w', '--warning', dest='key_threshold_warning', nargs='*',
|
||||||
@ -409,6 +410,11 @@ if __name__ == "__main__":
|
|||||||
if args.auth:
|
if args.auth:
|
||||||
base64str = base64.encodestring(args.auth).replace('\n', '')
|
base64str = base64.encodestring(args.auth).replace('\n', '')
|
||||||
req.add_header('Authorization', 'Basic %s' % base64str)
|
req.add_header('Authorization', 'Basic %s' % base64str)
|
||||||
|
if args.headers:
|
||||||
|
headers=json.loads(args.headers)
|
||||||
|
debugPrint(args.debug, "Headers:\n %s" % headers)
|
||||||
|
for header in headers:
|
||||||
|
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)
|
||||||
elif args.timeout:
|
elif args.timeout:
|
||||||
|
Loading…
Reference in New Issue
Block a user