Skip to content

Commit

Permalink
remaining calls to GROUP_ALERTS changed to point to new GROUP_ALERTS_…
Browse files Browse the repository at this point in the history
…BY + management of empty alerts fields
  • Loading branch information
manuhortet committed Sep 13, 2018
1 parent cde0675 commit 5db7ba2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions prom2teams/app/versions/v2/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class AlertReceiver(Resource):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.schema = MessageSchema()
if 'TEMPLATE_PATH' in app.config:
self.sender = AlarmSender(app.config['TEMPLATE_PATH'], app.config['GROUP_ALERTS'])
if app.config['TEMPLATE_PATH']:
self.sender = AlarmSender(app.config['TEMPLATE_PATH'], app.config['GROUP_ALERTS_BY'])
else:
self.sender = AlarmSender(group_alerts=app.config['GROUP_ALERTS'])
self.sender = AlarmSender(group_alerts_by=app.config['GROUP_ALERTS_BY'])

@api_v2.expect(message)
def post(self, connector):
alerts = self.schema.load(request.get_json()).data
self.sender.send_alarms(alerts, app.config['MICROSOFT_TEAMS'])
self.sender.send_alarms(alerts, app.config['MICROSOFT_TEAMS'][connector])
return 'OK', 201
4 changes: 2 additions & 2 deletions prom2teams/prometheus/message_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class LabelSchema(Schema):
instance = fields.Str(default='unknown', missing='unknown')
job = fields.Str()
mountpoint = fields.Str()
severity = fields.Str(default=None, missing=None)
severity = fields.Str(default='unknown', missing='unknown')


class AnnotationSchema(Schema):
description = fields.Str(default=None, missing=None)
description = fields.Str(default='unknown', missing='unknown')
summary = fields.Str(default='unknown', missing='unknown')


Expand Down
2 changes: 1 addition & 1 deletion prom2teams/teams/alarm_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def map_and_group(alerts, group_alerts_by):
def teams_visualization(feature):
feature.sort()
# Teams won't print just one new line
return ',\n\n\n'.join(feature)
return ',\n\n\n'.join(feature) if feature else 'unknown'


def group_alerts(alerts, group_alerts_by):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_json_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_json_without_optional_field(self):
json_received = json.load(json_data)
alerts = MessageSchema().load(json_received).data
alarm = map_prom_alerts_to_teams_alarms(alerts)[0]
self.assertNotIn('unknown', str(alarm))
self.assertIn("'description': 'unknown'", str(alarm))

def test_json_without_instance_field(self):
with open(self.TEST_CONFIG_FILES_PATH + 'without_instance_field.json') as json_data:
Expand Down

0 comments on commit 5db7ba2

Please sign in to comment.