Skip to content

Commit

Permalink
mgr/zabbix: Use fsid as identifier with Zabbix if none is set
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
wido committed Dec 19, 2017
1 parent dc23676 commit 2281bfd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
9 changes: 7 additions & 2 deletions doc/mgr/zabbix.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 12 additions & 6 deletions src/pybind/mgr/zabbix/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -86,12 +87,12 @@ def __init__(self, *args, **kwargs):
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)

Expand Down Expand Up @@ -210,15 +211,20 @@ def get_data(self):
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)

Expand Down

0 comments on commit 2281bfd

Please sign in to comment.