@@ -34,6 +34,8 @@ class PrometheusConnect:
34
34
:param disable_ssl: (bool) If set to True, will disable ssl certificate verification
35
35
for the http requests made to the prometheus host
36
36
:param retry: (Retry) Retry adapter to retry on HTTP errors
37
+ :param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth. See python
38
+ requests library auth parameter for further explanation.
37
39
"""
38
40
39
41
def __init__ (
@@ -42,6 +44,7 @@ def __init__(
42
44
headers : dict = None ,
43
45
disable_ssl : bool = False ,
44
46
retry : Retry = None ,
47
+ auth : tuple = None
45
48
):
46
49
"""Functions as a Constructor for the class PrometheusConnect."""
47
50
if url is None :
@@ -60,6 +63,8 @@ def __init__(
60
63
status_forcelist = RETRY_ON_STATUS ,
61
64
)
62
65
66
+ self .auth = auth
67
+
63
68
self ._session = requests .Session ()
64
69
self ._session .mount (self .url , HTTPAdapter (max_retries = retry ))
65
70
@@ -76,6 +81,7 @@ def check_prometheus_connection(self, params: dict = None) -> bool:
76
81
verify = self .ssl_verification ,
77
82
headers = self .headers ,
78
83
params = params ,
84
+ auth = self .auth ,
79
85
)
80
86
return response .ok
81
87
@@ -112,6 +118,7 @@ def get_label_values(self, label_name: str, params: dict = None):
112
118
verify = self .ssl_verification ,
113
119
headers = self .headers ,
114
120
params = params ,
121
+ auth = self .auth ,
115
122
)
116
123
117
124
if response .status_code == 200 :
@@ -161,6 +168,7 @@ def get_current_metric_value(
161
168
params = {** {"query" : query }, ** params },
162
169
verify = self .ssl_verification ,
163
170
headers = self .headers ,
171
+ auth = self .auth ,
164
172
)
165
173
166
174
if response .status_code == 200 :
@@ -251,6 +259,7 @@ def get_metric_range_data(
251
259
},
252
260
verify = self .ssl_verification ,
253
261
headers = self .headers ,
262
+ auth = self .auth ,
254
263
)
255
264
if response .status_code == 200 :
256
265
data += response .json ()["data" ]["result" ]
@@ -348,6 +357,7 @@ def custom_query(self, query: str, params: dict = None):
348
357
params = {** {"query" : query }, ** params },
349
358
verify = self .ssl_verification ,
350
359
headers = self .headers ,
360
+ auth = self .auth ,
351
361
)
352
362
if response .status_code == 200 :
353
363
data = response .json ()["data" ]["result" ]
@@ -390,6 +400,7 @@ def custom_query_range(
390
400
params = {** {"query" : query , "start" : start , "end" : end , "step" : step }, ** params },
391
401
verify = self .ssl_verification ,
392
402
headers = self .headers ,
403
+ auth = self .auth ,
393
404
)
394
405
if response .status_code == 200 :
395
406
data = response .json ()["data" ]["result" ]
0 commit comments