Zabbix inventory improvement (#42669)
* Add validate_certs option to zabbix inventory * Add validation option * Fix pep8 * Add changelogpull/4420/head
parent
106e4b374a
commit
5864871fc1
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
minor_changes:
|
||||||
|
- Added capability to skip ssl verification
|
||||||
|
on zabbix host with dynamic inventory
|
|
@ -9,3 +9,6 @@ server = http://zabbix.example.com/zabbix
|
||||||
# Login
|
# Login
|
||||||
username = admin
|
username = admin
|
||||||
password = zabbix
|
password = zabbix
|
||||||
|
|
||||||
|
# Verify the server's SSL certificate
|
||||||
|
validate_certs = True
|
|
@ -73,6 +73,10 @@ class ZabbixInventory(object):
|
||||||
self.zabbix_username = config.get('zabbix', 'username')
|
self.zabbix_username = config.get('zabbix', 'username')
|
||||||
if config.has_option('zabbix', 'password'):
|
if config.has_option('zabbix', 'password'):
|
||||||
self.zabbix_password = config.get('zabbix', 'password')
|
self.zabbix_password = config.get('zabbix', 'password')
|
||||||
|
# ssl certs
|
||||||
|
if config.has_option('zabbix', 'validate_certs'):
|
||||||
|
if config.get('zabbix', 'validate_certs') in ['false', 'False', False]:
|
||||||
|
self.validate_certs = False
|
||||||
|
|
||||||
def read_cli(self):
|
def read_cli(self):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
@ -118,6 +122,7 @@ class ZabbixInventory(object):
|
||||||
self.zabbix_server = None
|
self.zabbix_server = None
|
||||||
self.zabbix_username = None
|
self.zabbix_username = None
|
||||||
self.zabbix_password = None
|
self.zabbix_password = None
|
||||||
|
self.validate_certs = True
|
||||||
self.meta = {}
|
self.meta = {}
|
||||||
|
|
||||||
self.read_settings()
|
self.read_settings()
|
||||||
|
@ -125,7 +130,7 @@ class ZabbixInventory(object):
|
||||||
|
|
||||||
if self.zabbix_server and self.zabbix_username:
|
if self.zabbix_server and self.zabbix_username:
|
||||||
try:
|
try:
|
||||||
api = ZabbixAPI(server=self.zabbix_server)
|
api = ZabbixAPI(server=self.zabbix_server, validate_certs=self.validate_certs)
|
||||||
api.login(user=self.zabbix_username, password=self.zabbix_password)
|
api.login(user=self.zabbix_username, password=self.zabbix_password)
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
print("Error: Could not login to Zabbix server. Check your zabbix.ini.", file=sys.stderr)
|
print("Error: Could not login to Zabbix server. Check your zabbix.ini.", file=sys.stderr)
|
||||||
|
|
Loading…
Reference in New Issue