blob: d2c713b2059ff17d1c86e0936dccdd4380a49b26 [file] [log] [blame]
import os
RESOLVED_STATUSES = ('UP', 'OK', 'resolved')
def create_file(file_path):
if not os.path.exists(file_path):
with open(file_path, 'w+'):
return file_path
def _format_subject(alert):
subject = alert['annotations']['summary']
host = alert['labels'].get('host')
if host is not None:
return '[{}] {}'.format(host, subject)
return subject
def _remove_advice(description):
return description.split(' Modify the')[0]
def _format_description(alert):
return _remove_advice(alert['annotations']['description'])
def alert_fields_and_action(alert):
fields = []
if alert['status'] in RESOLVED_STATUSES:
action = 'close_case'
fields.append(alert['labels'])
else:
action = 'create_case'
# Order of keys matters
fields.append(_format_subject(alert))
fields.append(_format_description(alert))
fields.append(alert['labels'])
return fields, action