blob: 8a5bf8d14ae6e8c548e2ff51bfbc84c44c109f59 [file] [log] [blame]
# Copyright 2018: Mirantis Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
RESOLVED_STATUSES = ('UP', 'OK', 'resolved')
SUBJECT_FMT = '[{}][{}] {}'
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 matters
subject = SUBJECT_FMT.format(alert['labels']['environment'],
alert['labels'].get('host', 'none'),
alert['annotations']['summary'])
fields.append(subject)
fields.append(alert['annotations']['description'])
fields.append(alert['status'])
fields.append(alert['labels'])
return fields, action