From: Wido den Hollander Date: Wed, 29 Nov 2017 13:23:39 +0000 (+0100) Subject: mgr/zabbix: Optimize configuration of Zabbix module X-Git-Tag: v12.2.5~94^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f634246124591b83ca8e7055f5a1cc188751cc49;p=ceph.git mgr/zabbix: Optimize configuration of Zabbix module The module refused to run/start if not all configuration was properly set This commit makes sure the module is initialized properly and allows it to run much more smoothly. Signed-off-by: Wido den Hollander (cherry picked from commit c9bb2f023de1d649d9d6256b83df128cfa9c4a9a) --- diff --git a/src/pybind/mgr/zabbix/module.py b/src/pybind/mgr/zabbix/module.py index 263cd746a7a2..6088f7c30e41 100644 --- a/src/pybind/mgr/zabbix/module.py +++ b/src/pybind/mgr/zabbix/module.py @@ -89,12 +89,7 @@ class Module(MgrModule): def init_module_config(self): self.fsid = self.get('mon_map')['fsid'] for key, default in self.config_keys.items(): - value = self.get_localized_config(key, default) - if value is None: - raise RuntimeError('Configuration key {0} not set; "ceph ' - 'zabbix config-set {0} "'.format(key)) - - self.set_config_option(key, value) + self.set_config_option(key, self.get_config(key, default)) def set_config_option(self, option, value): if option not in self.config_keys.keys(): @@ -112,6 +107,7 @@ class Module(MgrModule): raise RuntimeError('interval should be set to at least 10 seconds') self.config[option] = value + return True def get_data(self): data = dict() @@ -215,19 +211,28 @@ class Module(MgrModule): if identifier is None or len(identifier) == 0: identifier = 'ceph-{0}'.format(self.fsid) - self.log.debug('Sending data to Zabbix server %s as host/identifier %s', - self.config['zabbix_host'], identifier) - self.log.debug(data) + if not self.config['zabbix_host']: + self.log.error('Zabbix server not set, please configure using: ' + 'ceph zabbix config-set zabbix_host ') + return try: + self.log.debug( + 'Sending data to Zabbix server %s as host/identifier %s', + self.config['zabbix_host'], identifier) + self.log.debug(data) + zabbix = ZabbixSender(self.config['zabbix_sender'], self.config['zabbix_host'], self.config['zabbix_port'], self.log) zabbix.send(identifier, data) + return True except Exception as exc: self.log.error('Exception when sending: %s', exc) + return False + def handle_command(self, command): if command['prefix'] == 'zabbix config-show': return 0, json.dumps(self.config), '' @@ -238,12 +243,18 @@ class Module(MgrModule): return -errno.EINVAL, '', 'Value should not be empty or None' self.log.debug('Setting configuration option %s to %s', key, value) - self.set_config_option(key, value) - self.set_localized_config(key, value) - return 0, 'Configuration option {0} updated'.format(key), '' + if self.set_config_option(key, value): + self.set_config(key, value) + return 0, 'Configuration option {0} updated'.format(key), '' + + return 1,\ + 'Failed to update configuration option {0}'.format(key), '' + elif command['prefix'] == 'zabbix send': - self.send() - return 0, 'Sending data to Zabbix', '' + if self.send(): + return 0, 'Sending data to Zabbix', '' + + return 1, 'Failed to send data to Zabbix', '' elif command['prefix'] == 'zabbix self-test': self.self_test() return 0, 'Self-test succeeded', ''