Skip to content

Commit

Permalink
Checking channel information is returned by function before updating (#…
Browse files Browse the repository at this point in the history
…68)

* Checking channel information is returned by function before updating

* Added No channel found if config missing in alertmanager
  • Loading branch information
Sandhya1874 authored Feb 17, 2025
1 parent a0feb4b commit 6239623
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions github_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,16 @@ def get_alertmanager_data():
json_config_data = json.loads(json.dumps(yaml_config_data))
return json_config_data
else:
log.error(f"Error: {response.status_code}")
log.error(f"Alertmanager Error: {response.status_code}")
return None
except requests.exceptions.SSLError as e:
log.error(f"SSL Error: {e}")
log.error(f"Alertmanager SSL Error: {e}")
return None
except requests.exceptions.RequestException as e:
log.error(f"Request Error: {e}")
log.error(f"Alertmanager Request Error: {e}")
return None
except json.JSONDecodeError as e:
log.error(f"JSON Decode Error: {e}")
log.error(f"Alertmanager JSON Decode Error: {e}")
return None

def find_channel_by_severity_label(alert_severity_label):
Expand All @@ -382,7 +382,8 @@ def find_channel_by_severity_label(alert_severity_label):
if slack_configs:
return slack_configs[0].get('channel')
else :
return ''
log.info(f"ERROR - No slack_configs found for alert severity label {alert_severity_label}, receiver {receiver_name}")
return 'NO_CHANNEL_FOUND'

def process_components(data):
log.info(f'Processing batch of {len(data)} components...')
Expand Down Expand Up @@ -792,8 +793,11 @@ def process_repo(**component):

if alert_severity_label:
channel = find_channel_by_severity_label(alert_severity_label)
e.update({'alert_severity_label': alert_severity_label})
e.update({'alerts_slack_channel': channel})
if channel is not None:
e.update({'alert_severity_label': alert_severity_label})
e.update({'alerts_slack_channel': channel})
else:
log.info(f"ERROR - For Alert severity label {alert_severity_label} channel not found for {c_name} in {env}")
else:
log.info(f"ERROR - Alert severity label not found for {c_name} in {env}")

Expand Down

0 comments on commit 6239623

Please sign in to comment.