From 7032e597549423f0d0d8ef43d441100516222885 Mon Sep 17 00:00:00 2001 From: sametd Date: Wed, 20 Dec 2023 18:06:12 +0100 Subject: [PATCH] metric token support added for retrieve metrics function --- .../aviso_monitoring/reporter/opsview_reporter.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/aviso-server/monitoring/aviso_monitoring/reporter/opsview_reporter.py b/aviso-server/monitoring/aviso_monitoring/reporter/opsview_reporter.py index 09ba543..4dd81c9 100644 --- a/aviso-server/monitoring/aviso_monitoring/reporter/opsview_reporter.py +++ b/aviso-server/monitoring/aviso_monitoring/reporter/opsview_reporter.py @@ -24,6 +24,9 @@ def __init__(self, config: Config, msg_receiver=None): self.monitor_servers = config.monitor_servers self.msg_receiver = msg_receiver self.token = {} + if config.kube_state_metrics["ssl_enabled"]: + self.metric_ssl_enabled = True + self.metric_token = config.kube_state_metrics["token"] def ms_authenticate(self, m_server): """ @@ -199,7 +202,7 @@ def aggregate_unique_counter_tlms(tlms): } return agg_tlm - def retrieve_metrics(metric_servers, req_timeout): + def retrieve_metrics(self, metric_servers, req_timeout): """ This methods retrieves the metrics provided by specific metric servers using a Prometheus interface. """ @@ -207,8 +210,11 @@ def retrieve_metrics(metric_servers, req_timeout): for u in metric_servers: url = u + "/metrics" logger.debug(f"Retrieving metrics from {url}...") + headers = {} try: - resp = requests.get(url, verify=False, timeout=req_timeout) + if self.metric_ssl_enabled: + headers["Authorization"] = f"Bearer {self.metric_token}" + resp = requests.get(url, verify=False, timeout=req_timeout, headers=headers) except Exception as e: logger.exception(f"Not able to get metrics from {url}, error {e}") raw_tlms[u] = None