Skip to content

Commit

Permalink
updated marshmallow dependency, changed schema treatment accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
manuhortet committed Oct 10, 2018
1 parent 90dbc56 commit a0c7047
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a ch

## [Unreleased](https://github.com/idealista/prom2teams/tree/develop)

## Changed
- *[#99](https://github.com/idealista/prom2teams/pull/99 ) Marshmallow update @manuhortet*

## [2.2.2](https://github.com/idealista/prom2teams/tree/2.2.2)
[Full Changelog](https://github.com/idealista/prom2teams/compare/2.2.1...2.2.2)
## Added
- *[#94](https://github.com/idealista/prom2teams/pull/94) Always group by status @manuhortet*

Expand Down
2 changes: 1 addition & 1 deletion prom2teams/app/versions/v1/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, *args, **kwargs):
def post(self):
_show_deprecated_warning("Call to deprecated function. It will be removed in future versions. "
"Please view the README file.")
alerts = self.schema.load(request.get_json()).data
alerts = self.schema.load(request.get_json())
self.sender.send_alarms(alerts, app.config['MICROSOFT_TEAMS']['Connector'])
return 'OK', 201

Expand Down
2 changes: 1 addition & 1 deletion prom2teams/app/versions/v2/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ def __init__(self, *args, **kwargs):

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


Expand Down
6 changes: 3 additions & 3 deletions prom2teams/teams/alarm_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def map_alarm_to_json(alarm):
schema = TeamsAlarmSchema()
result = schema.dump(alarm)
return result.data
return result


def map_prom_alerts_to_teams_alarms(alerts):
Expand All @@ -16,7 +16,7 @@ def map_prom_alerts_to_teams_alarms(alerts):
for alert in alerts[same_status_alerts]:
alarm = TeamsAlarm(alert.name, alert.status.lower(), alert.severity,
alert.summary, alert.instance, alert.description)
json_alarm = schema.dump(alarm).data
json_alarm = schema.dump(alarm)
teams_alarms.append(json_alarm)
return teams_alarms

Expand All @@ -36,7 +36,7 @@ def map_and_group(alerts, group_alerts_by):
teams_visualization(features["status"]),
teams_visualization(features["summary"]))
alarm = TeamsAlarm(name, status.lower(), severity, summary, instance, description)
json_alarm = schema.dump(alarm).data
json_alarm = schema.dump(alarm)
teams_alarms.append(json_alarm)
return teams_alarms

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ requests==2.9.1
Jinja2==2.10
Flask==1.0.2
flask-restplus==0.10.1
marshmallow==2.15.0
marshmallow==3.0.0b16
pyyaml==3.12
uwsgi==2.0.16
12 changes: 6 additions & 6 deletions tests/test_json_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ class TestJSONFields(unittest.TestCase):
def test_json_with_all_fields(self):
with open(self.TEST_CONFIG_FILES_PATH + 'all_ok.json') as json_data:
json_received = json.load(json_data)
alerts = MessageSchema().load(json_received).data
alerts = MessageSchema().load(json_received)
alarm = map_prom_alerts_to_teams_alarms(alerts)[0]
self.assertNotIn('unknown', str(alarm))

def test_json_without_mandatory_field(self):
with open(self.TEST_CONFIG_FILES_PATH + 'without_mandatory_field.json') as json_data:
json_received = json.load(json_data)
alerts = MessageSchema().load(json_received).data
alerts = MessageSchema().load(json_received)
alarm = map_prom_alerts_to_teams_alarms(alerts)[0]
self.assertIn('unknown', str(alarm))

def test_json_without_optional_field(self):
with open(self.TEST_CONFIG_FILES_PATH + 'without_optional_field.json') as json_data:
json_received = json.load(json_data)
alerts = MessageSchema().load(json_received).data
alerts = MessageSchema().load(json_received)
alarm = map_prom_alerts_to_teams_alarms(alerts)[0]
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:
json_received = json.load(json_data)
alerts = MessageSchema().load(json_received).data
alerts = MessageSchema().load(json_received)
alarm = map_prom_alerts_to_teams_alarms(alerts)[0]
self.assertEqual('unknown', str(alarm['instance']))

Expand All @@ -44,7 +44,7 @@ def test_compose_all(self):
json_received = json.load(json_data)
json_expected = json.load(expected_data)

alerts = MessageSchema().load(json_received).data
alerts = MessageSchema().load(json_received)
rendered_data = AlarmSender()._create_alarms(alerts)[0]
json_rendered = json.loads(rendered_data)

Expand All @@ -56,7 +56,7 @@ def test_grouping_multiple_alerts(self):
json_received = json.load(json_data)
json_expected = json.load(expected_data)

alerts = MessageSchema().load(json_received).data
alerts = MessageSchema().load(json_received)
rendered_data = AlarmSender(group_alerts_by='name')._create_alarms(alerts)[0].replace("\n\n\n", " ")
json_rendered = json.loads(rendered_data)

Expand Down

0 comments on commit a0c7047

Please sign in to comment.