4141from urllib .parse import urljoin
4242
4343
44- VERSION = '0.1.0 '
44+ VERSION = '0.1.1 '
4545
4646OK = 0
4747WARNING = 1
@@ -89,12 +89,13 @@ class Client:
8989
9090 API_PREFIX = '/api/v1/'
9191
92- def __init__ (self , api , username , password , logger = None ):
92+ def __init__ (self , api , username , password , logger = None , verify = True ):
9393 # TODO: parse and validate url?
9494
9595 self .api = api
9696 self .username = username
9797 self .password = password
98+ self .verify = verify
9899
99100 if logger is None :
100101 logger = logging .getLogger ()
@@ -115,7 +116,7 @@ def request(self, url, method='GET', **kwargs):
115116 self .logger .debug ("starting API %s request from: %s" , method , url )
116117
117118 try :
118- response = requests .request (method , request_url , auth = HTTPBasicAuth (self .username , self .password ))
119+ response = requests .request (method , request_url , auth = HTTPBasicAuth (self .username , self .password ), verify = self . verify )
119120 except requests .exceptions .RequestException as e :
120121 raise CriticalException (e )
121122
@@ -398,19 +399,24 @@ def parse_args():
398399
399400 args .add_argument ('--version' , '-V' , help = 'Print version' , action = 'store_true' )
400401
402+ args .add_argument ('--insecure' , help = 'Do not verify TLS certificate. Be careful with this option, please' , action = 'store_true' , required = False )
403+
401404 return args .parse_args ()
402405
403406
404407def main ():
405408 fix_tls_cert_store ()
406409
407410 args = parse_args ()
411+ if args .insecure :
412+ import urllib3
413+ urllib3 .disable_warnings ()
408414
409415 if args .version :
410416 print ("check_vmware_nsxt version %s" % VERSION )
411417 return 0
412418
413- client = Client (args .api , args .username , args .password )
419+ client = Client (args .api , args .username , args .password , verify = ( not args . insecure ) )
414420
415421 if args .mode == 'cluster-status' :
416422 return client .get_cluster_status ().print_and_return ()
0 commit comments