]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/zabbix: Optimize configuration of Zabbix module
authorWido den Hollander <wido@42on.com>
Wed, 29 Nov 2017 13:23:39 +0000 (14:23 +0100)
committerWido den Hollander <wido@42on.com>
Wed, 7 Mar 2018 14:31:17 +0000 (15:31 +0100)
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 <wido@42on.com>
(cherry picked from commit c9bb2f023de1d649d9d6256b83df128cfa9c4a9a)

src/pybind/mgr/zabbix/module.py

index 263cd746a7a25548eccb5f5681826c1845dd2631..6088f7c30e415bbab2408c4675eeb6d79ee69aa2 100644 (file)
@@ -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} <value>"'.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 <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', ''