]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/zabbix: Use fsid as identifier with Zabbix if none is set
authorWido den Hollander <wido@42on.com>
Wed, 29 Nov 2017 09:25:01 +0000 (10:25 +0100)
committerWido den Hollander <wido@42on.com>
Tue, 19 Dec 2017 12:53:48 +0000 (13:53 +0100)
Users can still override this parameter, but by default the fsid
of the cluster will be used to send data to Zabbix.

This makes it even easier to use the Zabbix module.

Signed-off-by: Wido den Hollander <wido@42on.com>
doc/mgr/zabbix.rst
src/pybind/mgr/zabbix/module.py

index e1de5c8eb5745e32eef167ee466f81c323dddc0c..582fdd85e7fb52b5ad742f320d31f121228eda8f 100644 (file)
@@ -45,10 +45,10 @@ You can enable the *zabbix* module with:
 Configuration
 -------------
 
-Two configuration keys are mandatory for the module to work:
+Two configuration keys are vital for the module to work:
 
 - zabbix_host
-- identifier
+- identifier (optional)
 
 The parameter *zabbix_host* controls the hostname of the Zabbix server to which
 *zabbix_sender* will send the items. This can be a IP-Address if required by
@@ -58,6 +58,11 @@ The *identifier* parameter controls the identifier/hostname to use as source
 when sending items to Zabbix. This should match the name of the *Host* in
 your Zabbix server.
 
+When the *identifier* parameter is not configured the ceph-<fsid> of the cluster
+will be used when sending data to Zabbix.
+
+This would for example be *ceph-c4d32a99-9e80-490f-bd3a-1d22d8a7d354*
+
 Additional configuration keys which can be configured and their default values:
 
 - zabbix_port: 10051
index 5bb871afe58d41db6906288b5e5229ff592384fa..263cd746a7a25548eccb5f5681826c1845dd2631 100644 (file)
@@ -54,7 +54,8 @@ class Module(MgrModule):
         'zabbix_sender': '/usr/bin/zabbix_sender',
         'zabbix_host': None,
         'zabbix_port': 10051,
-        'identifier': None, 'interval': 60
+        'identifier': "",
+        'interval': 60
     }
 
     COMMANDS = [
@@ -86,12 +87,12 @@ class Module(MgrModule):
         self.event = Event()
 
     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 '
-                                   'config-key set mgr/zabbix/{0} '
-                                   '<value>"'.format(key))
+                                   'zabbix config-set {0} <value>"'.format(key))
 
             self.set_config_option(key, value)
 
@@ -210,15 +211,20 @@ class Module(MgrModule):
     def send(self):
         data = self.get_data()
 
-        self.log.debug('Sending data to Zabbix server %s',
-                       self.config['zabbix_host'])
+        identifier = self.config['identifier']
+        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)
 
         try:
             zabbix = ZabbixSender(self.config['zabbix_sender'],
                                   self.config['zabbix_host'],
                                   self.config['zabbix_port'], self.log)
-            zabbix.send(self.config['identifier'], data)
+
+            zabbix.send(identifier, data)
         except Exception as exc:
             self.log.error('Exception when sending: %s', exc)