]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: point alertmanager at all mgr/dashboard URLs 34154/head
authorSage Weil <sage@redhat.com>
Fri, 20 Mar 2020 16:12:06 +0000 (11:12 -0500)
committerSage Weil <sage@redhat.com>
Tue, 24 Mar 2020 20:37:09 +0000 (15:37 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit 41d0966b72b52a78aa63cb8776b07d23668526d9)

src/pybind/mgr/cephadm/module.py

index 2ebf9d29bfdcf122cbaedcb16cf83e120a09489c..4afb41c2e3aac346e5257706f6ea16de648dae17 100644 (file)
@@ -2168,7 +2168,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
         need = {
             'prometheus': ['mgr', 'alertmanager', 'node-exporter'],
             'grafana': ['prometheus'],
-            'alertmanager': ['alertmanager'],
+            'alertmanager': ['mgr', 'alertmanager'],
         }
         deps = []
         for dep_type in need.get(daemon_type, []):
@@ -2916,6 +2916,32 @@ datasources:
     def _generate_alertmanager_config(self):
         # type: () -> Tuple[Dict[str, Any], List[str]]
         deps = [] # type: List[str]
+
+        # dashboard(s)
+        dashboard_urls = []
+        mgr_map = self.get('mgr_map')
+        port = None
+        proto = None  # http: or https:
+        url = mgr_map.get('services', {}).get('dashboard', None)
+        if url:
+            dashboard_urls.append(url)
+            proto = url.split('/')[0]
+            port = url.split('/')[2].split(':')[1]
+        # scan all mgrs to generate deps and to get standbys too.
+        # assume that they are all on the same port as the active mgr.
+        for dd in self.cache.get_daemons_by_service('mgr'):
+            # we consider mgr a dep even if the dashboard is disabled
+            # in order to be consistent with _calc_daemon_deps().
+            deps.append(dd.name())
+            if not port:
+                continue
+            if dd.daemon_id == self.get_mgr_id():
+                continue
+            hi = self.inventory.get(dd.hostname, {})
+            addr = hi.get('addr', dd.hostname)
+            dashboard_urls.append('%s//%s:%s/' % (proto, addr.split(':')[0],
+                                                 port))
+
         yml = """# generated by cephadm
 # See https://prometheus.io/docs/alerting/configuration/ for documentation.
 
@@ -2931,8 +2957,12 @@ route:
 receivers:
 - name: 'ceph-dashboard'
   webhook_configs:
-  - url: '{url}/api/prometheus_receiver'
-        """.format(url=self._get_dashboard_url())
+{urls}
+""".format(
+    urls='\n'.join(
+        ["  - url: '{}api/prometheus_receiver'".format(u)
+         for u in dashboard_urls]
+    ))
         peers = []
         port = '9094'
         for dd in self.cache.get_daemons_by_service('alertmanager'):