]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Merge PR #26547 into master
authorSage Weil <sage@redhat.com>
Mon, 3 Jun 2019 20:45:42 +0000 (15:45 -0500)
committerSage Weil <sage@redhat.com>
Mon, 3 Jun 2019 20:45:42 +0000 (15:45 -0500)
* 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 <wido@42on.com>
1  2 
doc/mgr/zabbix.rst
src/pybind/mgr/zabbix/module.py

Simple merge
index 3fbe86ec7d476792fa406273b6e15e11c24fd925,de4a2e196223b87f05ba6e6139789678bb7f19ae..bd7c9c20b13a9cc63f8357bea0c92691e1796537
@@@ -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), ''