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: v13.0.2~679^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2281bfd54d2df8dc0df4a4a49684ea2a0174e474;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 --- diff --git a/doc/mgr/zabbix.rst b/doc/mgr/zabbix.rst index e1de5c8eb57..582fdd85e7f 100644 --- a/doc/mgr/zabbix.rst +++ b/doc/mgr/zabbix.rst @@ -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- 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 diff --git a/src/pybind/mgr/zabbix/module.py b/src/pybind/mgr/zabbix/module.py index 5bb871afe58..263cd746a7a 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)