From: Wido den Hollander Date: Wed, 29 Nov 2017 09:25:01 +0000 (+0100) Subject: mgr/zabbix: Use fsid as identifier with Zabbix if none is set X-Git-Tag: v12.2.5~94^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=24f6ba439b2417a53c544f39cb84bfeb15525ded;p=ceph.git mgr/zabbix: Use fsid as identifier with Zabbix if none is set 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 (cherry picked from commit 2281bfd54d2df8dc0df4a4a49684ea2a0174e474) Signed-off-by: Wido den Hollander --- diff --git a/doc/mgr/zabbix.rst b/doc/mgr/zabbix.rst index d98540e86969..7f4f2d89c882 100644 --- a/doc/mgr/zabbix.rst +++ b/doc/mgr/zabbix.rst @@ -52,10 +52,10 @@ Restart the ceph-mgr daemon after modifying the setting to load the module. Configuration ------------- -Two configuration keys are mandatory for the module to work: +Two configuration keys are vital for the module to work: -- mgr/zabbix/zabbix_host -- mgr/zabbix/identifier +- zabbix_host +- 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 @@ -65,6 +65,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- 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: - mgr/zabbix/zabbix_port: 10051 diff --git a/src/pybind/mgr/zabbix/module.py b/src/pybind/mgr/zabbix/module.py index 5bb871afe58d..263cd746a7a2 100644 --- a/src/pybind/mgr/zabbix/module.py +++ b/src/pybind/mgr/zabbix/module.py @@ -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} ' - '"'.format(key)) + 'zabbix config-set {0} "'.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)