From 3058176ba1951c1570dc73be6d05f47f2a810bd6 Mon Sep 17 00:00:00 2001 From: Bill Moritz Date: Sat, 22 Aug 2015 09:42:06 -0400 Subject: [PATCH 1/2] Add data argument Add an option to HTTP POST data to the host. --- check_http_json.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/check_http_json.py b/check_http_json.py index eb1227e..090fafe 100755 --- a/check_http_json.py +++ b/check_http_json.py @@ -190,6 +190,7 @@ def parseArgs(): parser.add_argument('-P', '--port', dest='port', required=False, help='TCP port') parser.add_argument('-B', '--basic-auth', dest='auth', required=False, help='Basic auth string "username:password"') parser.add_argument('-p', '--path', dest='path', help='Path.') + parser.add_argument('-D', '--data', dest='data', help='The http payload to send as a POST') parser.add_argument('-e', '--key_exists', dest='key_list', nargs='*', help='Checks existence of these keys to determine status.') parser.add_argument('-q', '--key_equals', dest='key_value_list', nargs='*', @@ -239,8 +240,12 @@ if __name__ == "__main__": if args.auth: base64str = base64.encodestring(args.auth).replace('\n', '') req.add_header('Authorization', 'Basic %s' % base64str) - if args.timeout: + if args.timeout and args.data: + response = urllib2.urlopen(req, timeout=args.timeout, data=args.data) + elif args.timeout: response = urllib2.urlopen(req, timeout=args.timeout) + elif args.data: + response = urllib2.urlopen(req, data=args.data) else: response = urllib2.urlopen(req) except HTTPError as e: From 42e75abcad8b8451689f99d158dd19b31a11ca49 Mon Sep 17 00:00:00 2001 From: Bill Moritz Date: Sat, 22 Aug 2015 09:47:25 -0400 Subject: [PATCH 2/2] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ba66438..3152c7e 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ More info about options in Usage. Executing `./check_http_json.py -h` will yield the following details: ``` -usage: check_http_json.py [-h] -H HOST [-P PORT] [-B AUTH] [-p PATH] +usage: check_http_json.py [-h] -H HOST [-P PORT] [-B AUTH] [-p PATH] [-D DATA] [-e [KEY_LIST [KEY_LIST ...]]] [-q [KEY_VALUE_LIST [KEY_VALUE_LIST ...]]] [-l [KEY_LTE_LIST [KEY_LTE_LIST ...]]] @@ -66,6 +66,7 @@ optional arguments: -B AUTH, --basic-auth AUTH Basic auth string "username:password" -p PATH, --path PATH Path. + -D DATA, --data DATA The http payload to send as an POST. -e [KEY_LIST [KEY_LIST ...]], --key_exists [KEY_LIST [KEY_LIST ...]] Checks existence of these keys to determine status. Multiple key values can be delimited with colon (key,value1:value2).