Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions grafana_wtf/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
grafana-wtf [options] plugins list [--id=]
grafana-wtf [options] plugins status [--id=]
grafana-wtf [options] channels [--uid=]
grafana-wtf [options] channels [--name=]
grafana-wtf --version
grafana-wtf (-h | --help)

Expand Down Expand Up @@ -352,6 +353,8 @@
if options.channels:
if options.uid:
response = engine.channels_list_by_uid(options.uid)
elif options.name:
response = engine.channels_list_by_name(options.name)

Check warning on line 357 in grafana_wtf/commands.py

View check run for this annotation

Codecov / codecov/patch

grafana_wtf/commands.py#L356-L357

Added lines #L356 - L357 were not covered by tests
else:
response = engine.channels_list()
output_results(output_format, response)
19 changes: 18 additions & 1 deletion grafana_wtf/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,11 @@
return self.grafana.notifications.lookup_channels()

def channels_list_by_uid(self, channel_uid):
channel = self.grafana.notifications.get_channel_by_uid(channel_uid)
try:
channel = self.grafana.notifications.get_channel_by_uid(channel_uid)
except GrafanaClientError as ex:
log.error(f"Error fetching the channel {channel_uid}: {ex}")
raise SystemExit(1)

Check warning on line 623 in grafana_wtf/core.py

View check run for this annotation

Codecov / codecov/patch

grafana_wtf/core.py#L619-L623

Added lines #L619 - L623 were not covered by tests

# Scan dashboards and panels to find where the channel is used
dashboards = self.scan_dashboards()
Expand Down Expand Up @@ -649,6 +653,19 @@
)
return related_information

def channels_list_by_name(self, name):
channel_list = self.channels_list()
channel_uid = ""
for channel in channel_list:
if channel["name"] == name:
channel_uid = channel["uid"]
break
if channel_uid:
return self.channels_list_by_uid(channel_uid)

Check warning on line 664 in grafana_wtf/core.py

View check run for this annotation

Codecov / codecov/patch

grafana_wtf/core.py#L657-L664

Added lines #L657 - L664 were not covered by tests
else:
log.info(f"Channel with the name {name} doesn't exist")
raise SystemExit(0)

Check warning on line 667 in grafana_wtf/core.py

View check run for this annotation

Codecov / codecov/patch

grafana_wtf/core.py#L666-L667

Added lines #L666 - L667 were not covered by tests


class Indexer:
def __init__(self, engine: GrafanaWtf):
Expand Down