From 7cb63a53e2487eaa899c7079a0afb3e4f318ffbf Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 20 Mar 2020 11:12:06 -0500 Subject: [PATCH] mgr/cephadm: point alertmanager at all mgr/dashboard URLs Signed-off-by: Sage Weil (cherry picked from commit 41d0966b72b52a78aa63cb8776b07d23668526d9) --- src/pybind/mgr/cephadm/module.py | 36 +++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 2ebf9d29bfdcf..4afb41c2e3aac 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -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'): -- 2.39.5