@@ -588,10 +588,34 @@ def plugins_status_by_id(self, plugin_id):
588588 def channels_list (self ):
589589 return self .grafana .notifications .lookup_channels ()
590590
591- def channels_list_by_id (self , channel_id ):
592- channel = self .grafana .notifications .get_channel_by_id (channel_id )
591+ def channels_list_by_uid (self , channel_uid ):
592+ channel = self .grafana .notifications .get_channel_by_uid (channel_uid )
593+
594+ # Scan dashboards and panels to find where the channel is used
595+ dashboards = self .scan_dashboards ()
596+ related_panels = []
597+ for dashboard in dashboards :
598+ for panel in dashboard ["dashboard" ].get ("panels" , []):
599+ if "alert" in panel and panel ["alert" ]["notifications" ]:
600+ related_panels += self .extract_channel_related_information (channel_uid , dashboard , panel )
601+
602+ # Some dashboards have a deeper nested structure
603+ elif "panels" in panel :
604+ for subpanel in panel ["panels" ]:
605+ if "alert" in subpanel and subpanel ["alert" ]["notifications" ]:
606+ related_panels += self .extract_channel_related_information (channel_uid , dashboard , subpanel )
607+ if related_panels :
608+ channel ["related_panels" ] = related_panels
593609 return channel
594610
611+ @staticmethod
612+ def extract_channel_related_information (channel_uid , dashboard , panel ):
613+ related_information = []
614+ for notification in panel ["alert" ]["notifications" ]:
615+ if "uid" in notification and notification ["uid" ] == channel_uid :
616+ related_information .append ({"dashboard" : dashboard ["dashboard" ]["title" ], "panel" : panel ["title" ]})
617+ return related_information
618+
595619
596620class Indexer :
597621 def __init__ (self , engine : GrafanaWtf ):
0 commit comments