forked from unioslo/zabbix-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multilevel configuration [Issue: unioslo#8]
- Loading branch information
Showing
4 changed files
with
52 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ | |
if sys.version_info < (2, 6): | ||
raise SystemExit('ERROR: zabbix-cli needs at least python 2.6 to work') | ||
else: | ||
install_requires = ['psycopg2','argparse'] | ||
install_requires = ['argparse','requests'] | ||
|
||
|
||
# | ||
|
@@ -50,13 +50,15 @@ | |
|
||
setup(name='zabbix_cli', | ||
version=zabbix_cli['__version__'], | ||
description='ZABBIX-CLI - PostgreSQL Backup Manager', | ||
description='ZABBIX-CLI - Zabbix terminal client', | ||
author='Rafael Martinez Guerrero', | ||
author_email='[email protected]', | ||
url='http://www.zabbix-cli.org/', | ||
url='https://github.com/usit-gd/zabbix-cli', | ||
packages=['zabbix_cli',], | ||
scripts=['bin/zabbix-cli','bin/zabbix-cli-bulk-execution','bin/zabbix-cli-init'], | ||
data_files=[('/etc/zabbix-cli', ['etc/zabbix-cli.conf'])], | ||
data_files=[('/etc/zabbix-cli', ['etc/zabbix-cli.conf']), | ||
('/usr/share/zabbix-cli', ['etc/zabbix-cli.conf'])], | ||
install_requires=install_requires, | ||
platforms=['Linux'], | ||
classifiers=[ | ||
'Environment :: Console', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
# Authors: | ||
# [email protected] / http://www.postgresql.org.es/ | ||
# | ||
# Copyright (c) 2014-2015 USIT-University of Oslo | ||
# Copyright (c) 2014-2016 USIT-University of Oslo | ||
# | ||
# This file is part of Zabbix-CLI | ||
# https://github.com/rafaelma/zabbix-cli | ||
|
@@ -32,10 +32,11 @@ class configuration(): | |
# Constructor | ||
# ############################################ | ||
|
||
def __init__(self,config_file): | ||
def __init__(self,config_file_from_parameter): | ||
""" The Constructor.""" | ||
|
||
self.config_file = config_file | ||
self.config_file_from_parameter = config_file_from_parameter | ||
self.config_file_list = [] | ||
|
||
# Zabbix API section | ||
self.zabbix_api_url = '' | ||
|
@@ -68,14 +69,30 @@ def __init__(self,config_file): | |
def set_configuration_file(self): | ||
"""Set the zabbix-cli configuration file""" | ||
|
||
config_file_list = [self.config_file] + [os.getenv('HOME') + '/.zabbix-cli/zabbix-cli.conf','/etc/zabbix-cli/zabbix-cli.conf','/etc/zabbix-cli.conf'] | ||
# This list defines the priority list of configuration files | ||
# that can exist in the system. Files close to the top of the | ||
# list will have priority to define configuration parameters | ||
# in the system. | ||
# | ||
# 1. /usr/share/zabbix-cli/zabbix-cli.fixed.conf | ||
# 2. /etc/zabbix-cli/zabbix-cli.fixed.conf | ||
# 3. Configuration file defined with the parameter -c / --config when executing zabbix-cli | ||
# 4. $HOME/.zabbix-cli/zabbix-cli.conf | ||
# 5. /etc/zabbix-cli/zabbix-cli.conf | ||
# 6. /usr/share/zabbix-cli/zabbix-cli.conf | ||
# | ||
|
||
config_file_priority_list = ['/usr/share/zabbix-cli/zabbix-cli.conf', '/etc/zabbix-cli/zabbix-cli.conf', os.getenv('HOME') + '/.zabbix-cli/zabbix-cli.conf'] + [self.config_file_from_parameter] + ['/etc/zabbix-cli/zabbix-cli.fixed.conf','/usr/share/zabbix-cli/zabbix-cli.fixed.conf'] | ||
|
||
# We check if the configuration files defined in | ||
# config_file_priority_list exist before we start reading | ||
# them. | ||
|
||
for file in config_file_list: | ||
for file in config_file_priority_list: | ||
if os.path.isfile(file): | ||
self.config_file = file | ||
break | ||
self.config_file_list.append(file) | ||
|
||
if self.config_file == '': | ||
if not self.config_file_list: | ||
|
||
print '\n[ERROR]: No config file found. Exiting.\n' | ||
sys.exit(1) | ||
|
@@ -88,10 +105,10 @@ def set_configuration_file(self): | |
def set_configuration_parameters(self): | ||
"""Set configuration parameters""" | ||
|
||
if self.config_file: | ||
for config_file in self.config_file_list: | ||
|
||
config = ConfigParser.RawConfigParser() | ||
config.read(self.config_file) | ||
config.read(config_file) | ||
|
||
# | ||
# Zabbix APIsection | ||
|
@@ -152,4 +169,3 @@ def set_configuration_parameters(self): | |
if config.has_option('logging','log_file'): | ||
self.log_file = config.get('logging','log_file') | ||
|
||
|