mirror of
https://github.com/drewkerrigan/nagios-http-json.git
synced 2024-11-22 02:13:47 +01:00
Merge pull request #20 from berosek/master
Support for custom HTTP Headers added using -A parameter.
This commit is contained in:
commit
ed7bc7175b
@ -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]
|
||||
[-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 ...]]]
|
||||
[-c [KEY_THRESHOLD_CRITICAL [KEY_THRESHOLD_CRITICAL ...]]]
|
||||
[-e [KEY_LIST [KEY_LIST ...]]]
|
||||
@ -41,6 +42,8 @@ optional arguments:
|
||||
-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 "(" ")"
|
||||
@ -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).
|
||||
|
||||
#### Using Headers
|
||||
|
||||
* `./check_http_json.py -H <host>:<port> -p <path> -A '{"content-type": "application/json"}' -w "metric,RANGE"`
|
||||
|
||||
## Nagios Installation
|
||||
|
||||
### Requirements
|
||||
|
@ -275,6 +275,7 @@ def parseArgs():
|
||||
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('-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',
|
||||
help='Json Field separator, defaults to "." ; Select element in an array with "(" ")"')
|
||||
parser.add_argument('-w', '--warning', dest='key_threshold_warning', nargs='*',
|
||||
@ -409,6 +410,11 @@ if __name__ == "__main__":
|
||||
if args.auth:
|
||||
base64str = base64.encodestring(args.auth).replace('\n', '')
|
||||
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:
|
||||
response = urllib2.urlopen(req, timeout=args.timeout, data=args.data)
|
||||
elif args.timeout:
|
||||
|
Loading…
Reference in New Issue
Block a user