From a0c7047c627ea203e4284bbb477f1f0dc964fe7b Mon Sep 17 00:00:00 2001 From: Manu Hortet Date: Wed, 10 Oct 2018 20:17:47 +0200 Subject: [PATCH] updated marshmallow dependency, changed schema treatment accordingly --- CHANGELOG.md | 5 +++++ prom2teams/app/versions/v1/namespace.py | 2 +- prom2teams/app/versions/v2/namespace.py | 2 +- prom2teams/prometheus/message_schema.py | 2 +- prom2teams/teams/alarm_mapper.py | 6 +++--- requirements.txt | 2 +- tests/test_json_fields.py | 12 ++++++------ 7 files changed, 18 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8ca051..99ccdea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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* diff --git a/prom2teams/app/versions/v1/namespace.py b/prom2teams/app/versions/v1/namespace.py index f91d656..2a00169 100644 --- a/prom2teams/app/versions/v1/namespace.py +++ b/prom2teams/app/versions/v1/namespace.py @@ -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 diff --git a/prom2teams/app/versions/v2/namespace.py b/prom2teams/app/versions/v2/namespace.py index 0629152..a98746c 100644 --- a/prom2teams/app/versions/v2/namespace.py +++ b/prom2teams/app/versions/v2/namespace.py @@ -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 diff --git a/prom2teams/prometheus/message_schema.py b/prom2teams/prometheus/message_schema.py index 6873b84..243ec39 100644 --- a/prom2teams/prometheus/message_schema.py +++ b/prom2teams/prometheus/message_schema.py @@ -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') diff --git a/prom2teams/teams/alarm_mapper.py b/prom2teams/teams/alarm_mapper.py index 7d7f54d..84c6805 100644 --- a/prom2teams/teams/alarm_mapper.py +++ b/prom2teams/teams/alarm_mapper.py @@ -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): @@ -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 @@ -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 diff --git a/requirements.txt b/requirements.txt index 5d4b5e3..9165351 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/tests/test_json_fields.py b/tests/test_json_fields.py index f14f3a1..3a9cd37 100644 --- a/tests/test_json_fields.py +++ b/tests/test_json_fields.py @@ -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'])) @@ -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) @@ -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)