Skip to content

Commit

Permalink
Allow certificate verification to be configured.
Browse files Browse the repository at this point in the history
Related to #72
  • Loading branch information
paalbra committed Apr 30, 2019
1 parent ce204f9 commit 09c6095
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions etc/zabbix-cli.conf
Expand Up @@ -46,6 +46,10 @@
; NB: http does not work, and does so in unexpected ways (with json parse error)
;zabbix_api_url=https://zabbix.example.net/zabbix

; Configure certificate verification for the API server.
; ON/OFF is passed as verify=True/False to the requests library.
; Everything else is passed as is and assumed to be a file path to a CA bundle.
;cert_verify=ON

; ############################
; zabbix_config section
Expand Down
7 changes: 6 additions & 1 deletion zabbix_cli/cli.py
Expand Up @@ -88,7 +88,12 @@ def __init__(self, conf, username='', password='', auth_token=''):

try:
self.zapi = ZabbixAPI(self.conf.zabbix_api_url)
self.zapi.session.verify = True
if self.conf.cert_verify.upper() == "ON":
self.zapi.session.verify = True
elif self.conf.cert_verify.upper() == "OFF":
self.zapi.session.verify = False
else:
self.zapi.session.verify = self.conf.cert_verify
zabbix_auth_token_file = os.getenv('HOME') + '/.zabbix-cli_auth_token'
self.api_auth_token = self.zapi.login(self.api_username, self.api_password, self.api_auth_token)
self.zapi.user.get(userids=-1) # Dummy call to verify authentication
Expand Down
4 changes: 4 additions & 0 deletions zabbix_cli/config.py
Expand Up @@ -159,6 +159,10 @@ class Configuration(configparser.RawConfigParser, object):
'zabbix_api', 'zabbix_api_url',
required=True)

cert_verify = _registry.add(
'zabbix_api', 'cert_verify',
default='ON')

system_id = _registry.add(
'zabbix_config', 'system_id',
default='zabbix-ID')
Expand Down

0 comments on commit 09c6095

Please sign in to comment.