Skip to content

Commit 506fdab

Browse files
Merge pull request #3 from NETWAYS/introduce_insecure_option
Introduce insecure option for usage with self-signed certificates
2 parents 09bd3a9 + 194feed commit 506fdab

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ optional arguments:
4343
--password PASSWORD, -p PASSWORD
4444
Password for Basic Auth
4545
--mode MODE, -m MODE Check mode
46+
--insecure Do not verify TLS certificate. Be careful with this option, please
4647
```
4748

4849
```

check_vmware_nsxt.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from urllib.parse import urljoin
4242

4343

44-
VERSION = '0.1.0'
44+
VERSION = '0.1.1'
4545

4646
OK = 0
4747
WARNING = 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

404407
def 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()

icinga2/command.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ object CheckCommand "vmware_nsxt" {
88
"--mode" = "$vmware_nsx_mode$"
99
"--password" = "$vmware_nsx_password$"
1010
"--username" = "$vmware_nsx_username$"
11+
"--insecure" = {
12+
set_if = "$vmware_nsx_insecure$"
13+
}
1114
}
1215

1316
vars.vmware_nsx_api = "https://$host.name$"

0 commit comments

Comments
 (0)