Skip to content

Commit

Permalink
Add two options to the zabbix-cli.conf file. One to control the use o…
Browse files Browse the repository at this point in the history
…f colors when showing alarm information, and the other to control the generation of the auth_token file
  • Loading branch information
rafaelma committed Sep 19, 2015
1 parent 8e190e1 commit 6d471f0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
13 changes: 13 additions & 0 deletions etc/zabbix-cli.conf
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ default_export_format=JSON
; Default: ON
include_timestamp_export_filename=ON

; Use colors when showing alarm information
; use_colors: ON, OFF
; Default: ON
use_colors=ON

; Generate a file $HOME/.zabbix-cli_auth_token with the API-token
; delivered by the API after the last authentication of a user. If
; this file exists and the token is still active, the user would not
; have to write the username/password to login
; use_auth_token_file: ON,OFF
; Default: OFF
use_auth_token_file=OFF


; ######################
; Logging section
Expand Down
7 changes: 4 additions & 3 deletions zabbix_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def __init__(self,logs,conf,username='',password='',auth_token=''):
self.api_password = password
self.api_auth_token = auth_token
self.output_format = 'table'
self.color_support = 'off'
self.use_colors = self.conf.use_colors
self.use_auth_token_file = self.conf.use_auth_token_file

self.system_id = self.conf.system_id

Expand Down Expand Up @@ -112,7 +113,7 @@ def __init__(self,logs,conf,username='',password='',auth_token=''):
# USERNAME::API-auth-token returned after the las login.
#

if os.path.isfile(zabbix_auth_token_file) == False:
if self.use_auth_token_file == 'ON' and os.path.isfile(zabbix_auth_token_file) == False:

with open(zabbix_auth_token_file,'w') as auth_token_file:
auth_token_file.write(self.api_username + '::' + self.api_auth_token)
Expand Down Expand Up @@ -1183,7 +1184,7 @@ def do_show_alarms(self,args):

else:

if self.color_support == 'on':
if self.use_colors == 'ON':

if int(trigger['priority']) == 1:
ansi_code = "\033[38;5;158m"
Expand Down
34 changes: 10 additions & 24 deletions zabbix_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Authors:
# rafael@postgresql.org.es / http://www.postgresql.org.es/
#
# Copyright (c) 2014 USIT-University of Oslo
# Copyright (c) 2014-2015 USIT-University of Oslo
#
# This file is part of Zabbix-CLI
# https://github.com/rafaelma/zabbix-cli
Expand Down Expand Up @@ -40,12 +40,6 @@ def __init__(self,config_file):
# Zabbix API section
self.zabbix_api_url = ''

# LDAP section
self.ldap_uri = ''
self.ldap_users_tree = ''
self.ldap_usergroups_tree = ''
self.usergroups_to_sync = ''

# Zabbix_config section
self.system_id = 'zabbix-ID'
self.default_hostgroup = 'All-hosts'
Expand All @@ -55,6 +49,8 @@ def __init__(self,config_file):
self.default_directory_exports = os.getenv('HOME') + '/zabbix_exports'
self.default_export_format = 'JSON'
self.include_timestamp_export_filename = 'ON'
self.use_colors = 'ON'
self.use_auth_token_file = 'OFF'

# Logging section
self.logging = 'OFF'
Expand Down Expand Up @@ -103,23 +99,7 @@ def set_configuration_parameters(self):

if config.has_option('zabbix_api','zabbix_api_url'):
self.zabbix_api_url = config.get('zabbix_api','zabbix_api_url')

#
# LDAP section
#

if config.has_option('ldap','ldap_uri'):
self.ldap_uri = config.get('ldap','ldap_uri')

if config.has_option('ldap','ldap_users_tree'):
self.ldap_users_tree = config.get('ldap','ldap_users_tree')

if config.has_option('ldap','ldap_usergroups_tree'):
self.ldap_usergroups_tree = config.get('ldap','ldap_usergroups_tree')

if config.has_option('ldap','usergroups_to_sync'):
self.usergroups_to_sync = config.get('ldap','usergroups_to_sync')


#
# Zabbix configuration
#
Expand Down Expand Up @@ -148,6 +128,12 @@ def set_configuration_parameters(self):
if config.has_option('zabbix_config','include_timestamp_export_filename'):
self.include_timestamp_export_filename = config.get('zabbix_config','include_timestamp_export_filename')

if config.has_option('zabbix_config','use_colors'):
self.use_colors = config.get('zabbix_config','use_colors')

if config.has_option('zabbix_config','use_auth_token_file'):
self.use_auth_token_file = config.get('zabbix_config','use_auth_token_file')

#
# Logging section
#
Expand Down

0 comments on commit 6d471f0

Please sign in to comment.