})
return
- try:
+ result = True
+
+ for server in self._zabbix_hosts:
self.log.info(
- 'Sending data to Zabbix server %s as host/identifier %s',
- self.config['zabbix_host'], identifier)
+ 'Sending data to Zabbix server %s, port %s as host/identifier %s',
+ server['zabbix_host'], server['zabbix_port'], 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)
- self.set_health_checks(dict())
- return True
- except Exception as exc:
- self.log.error('Exception when sending: %s', exc)
- self.set_health_checks({
- 'MGR_ZABBIX_SEND_FAILED': {
- 'severity': 'warning',
- 'summary': 'Failed to send data to Zabbix',
- 'detail': [str(exc)]
- }
- })
-
- return False
+ try:
+ zabbix = ZabbixSender(self.config['zabbix_sender'],
+ server['zabbix_host'],
+ server['zabbix_port'], self.log)
+ zabbix.send(identifier, data)
+ except Exception as exc:
+ self.log.exception('Failed to send.')
+ self.set_health_checks({
+ 'MGR_ZABBIX_SEND_FAILED': {
+ 'severity': 'warning',
+ 'summary': 'Failed to send data to Zabbix',
+ 'detail': [str(exc)]
+ }
+ })
+ result = False
+
+ self.set_health_checks(dict())
+ return result
+ def discovery(self):
+ osd_map = self.get('osd_map')
+ osd_map_crush = self.get('osd_map_crush')
+
+ # Discovering ceph pools
+ pool_discovery = {
+ pool['pool_name']: step['item_name']
+ for pool in osd_map['pools']
+ for rule in osd_map_crush['rules'] if rule['rule_id'] == pool['crush_rule']
+ for step in rule['steps'] if step['op'] == "take"
+ }
+ pools_discovery_data = {"data": [
+ {
+ "{#POOL}": pool,
+ "{#CRUSH_RULE}": rule
+ }
+ for pool, rule in pool_discovery.items()
+ ]}
+
+ # Discovering OSDs
+ # Getting hosts for found crush rules
+ osd_roots = {
+ step['item_name']: [
+ item['id']
+ for item in root_bucket['items']
+ ]
+ for rule in osd_map_crush['rules']
+ for step in rule['steps'] if step['op'] == "take"
+ for root_bucket in osd_map_crush['buckets']
+ if root_bucket['id'] == step['item']
+ }
+ # Getting osds for hosts with map to crush_rule
+ osd_discovery = {
+ item['id']: crush_rule
+ for crush_rule, roots in osd_roots.items()
+ for root in roots
+ for bucket in osd_map_crush['buckets']
+ if bucket['id'] == root
+ for item in bucket['items']
+ }
+ osd_discovery_data = {"data": [
+ {
+ "{#OSD}": osd,
+ "{#CRUSH_RULE}": rule
+ }
+ for osd, rule in osd_discovery.items()
+ ]}
+ # Preparing recieved data for sending
+ data = {
+ "zabbix.pool.discovery": json.dumps(pools_discovery_data),
+ "zabbix.osd.discovery": json.dumps(osd_discovery_data)
+ }
+ return bool(self.send(data))
+
def handle_command(self, inbuf, command):
if command['prefix'] == 'zabbix config-show':
return 0, json.dumps(self.config), ''