@@ -46,9 +46,9 @@ def alert_proxy(self, method, path, params=None, payload=None):
4646 # type (str, str, dict, dict)
4747 user , password , cert_file = self .get_access_info ('alertmanager' )
4848 verify = cert_file .name if cert_file else Settings .ALERTMANAGER_API_SSL_VERIFY
49- response = self ._proxy (self ._get_api_url (Settings .ALERTMANAGER_API_HOST ),
49+ response = self ._proxy (self ._get_api_url (Settings .ALERTMANAGER_API_HOST , version = 'v2' ),
5050 method , path , 'Alertmanager' , params , payload ,
51- user = user , password = password , verify = verify )
51+ user = user , password = password , verify = verify , is_alertmanager = True )
5252 if cert_file :
5353 cert_file .close ()
5454 os .unlink (cert_file .name )
@@ -81,15 +81,16 @@ def get_access_info(self, module_name):
8181
8282 return user , password , cert_file
8383
84- def _get_api_url (self , host ):
85- return host .rstrip ('/' ) + ' /api/v1 '
84+ def _get_api_url (self , host , version = 'v1' ):
85+ return f' { host .rstrip ("/" ) } /api/{ version } '
8686
8787 def balancer_status (self ):
8888 return ceph_service .CephService .send_command ('mon' , 'balancer status' )
8989
9090 def _proxy (self , base_url , method , path , api_name , params = None , payload = None , verify = True ,
91- user = None , password = None ):
91+ user = None , password = None , is_alertmanager = False ):
9292 # type (str, str, str, str, dict, dict, bool)
93+ content = None
9394 try :
9495 from requests .auth import HTTPBasicAuth
9596 auth = HTTPBasicAuth (user , password ) if user and password else None
@@ -102,11 +103,14 @@ def _proxy(self, base_url, method, path, api_name, params=None, payload=None, ve
102103 http_status_code = 404 ,
103104 component = 'prometheus' )
104105 try :
105- content = json .loads (response .content , strict = False )
106+ if response .content :
107+ content = json .loads (response .content , strict = False )
106108 except json .JSONDecodeError as e :
107109 raise DashboardException (
108110 "Error parsing Prometheus Alertmanager response: {}" .format (e .msg ),
109111 component = 'prometheus' )
112+ if is_alertmanager :
113+ return content
110114 balancer_status = self .balancer_status ()
111115 if content ['status' ] == 'success' : # pylint: disable=R1702
112116 alerts_info = []
@@ -146,6 +150,10 @@ def create_silence(self, **params):
146150 def delete_silence (self , s_id ):
147151 return self .alert_proxy ('DELETE' , '/silence/' + s_id ) if s_id else None
148152
153+ @RESTController .Collection (method = 'GET' , path = '/alertgroup' )
154+ def get_alertgroup (self , ** params ):
155+ return self .alert_proxy ('GET' , '/alerts/groups' , params )
156+
149157 @RESTController .Collection (method = 'GET' , path = '/prometheus_query_data' )
150158 def get_prometeus_query_data (self , ** params ):
151159 params ['query' ] = params .pop ('params' )
0 commit comments