Merge pull request #79 from drewkerrigan/feature/http-method

Add CLI Flag to change HTTP method
This commit is contained in:
Markus Opolka 2022-09-15 15:22:48 +02:00 committed by GitHub
commit 49b338bdb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
@ -587,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()