From: Sage Weil Date: Mon, 3 Jun 2019 20:45:42 +0000 (-0500) Subject: Merge PR #26547 into master X-Git-Tag: v15.1.0~2577 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=611c8949fadfbbee96cea715d0aac4c4a618ceb0;p=ceph.git Merge PR #26547 into master * refs/pull/26547/head: Added validation of zabbix_host to support hostnames, IPv4 and IPv6. mgr/zabbix: Documentation added. mgr/zabbix: Adds possibility to send data to multiple zabbix servers. Reviewed-by: Wido den Hollander --- 611c8949fadfbbee96cea715d0aac4c4a618ceb0 diff --cc src/pybind/mgr/zabbix/module.py index 3fbe86ec7d47,de4a2e196223..bd7c9c20b13a --- a/src/pybind/mgr/zabbix/module.py +++ b/src/pybind/mgr/zabbix/module.py @@@ -302,85 -288,33 +321,87 @@@ class Module(MgrModule) }) 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), ''