Skip to content

Commit 2cbd97b

Browse files
Equinix improvements (#112)
* Add example of reduced-redundancy Equinix notification, fix a corner case with email subject matching and long subjects, add include_filter for Equinix * Add CHANGELOG for #112
1 parent ce2c5b1 commit 2cbd97b

File tree

10 files changed

+643
-76
lines changed

10 files changed

+643
-76
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- #109 - Improve handling of Zayo notifications.
88
- #110 - Improve handling of Telstra notifications.
99
- #111 - Improve handling of EXA (GTT) notifications.
10+
- #112 - Improve handling of Equinix notifications.
1011

1112
## v2.0.4 - 2021-11-04
1213

circuit_maintenance_parser/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class EmailSubjectParser(Parser):
197197
def parser_hook(self, raw: bytes):
198198
"""Execute parsing."""
199199
result = []
200-
for data in self.parse_subject(self.bytes_to_string(raw).replace("\r\n", "")):
200+
for data in self.parse_subject(self.bytes_to_string(raw).replace("\r", "").replace("\n", "")):
201201
result.append(data)
202202
return result
203203

circuit_maintenance_parser/parsers/equinix.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def _parse_b(self, b_elements, data):
5353
Returns:
5454
impact (Status object): impact of the maintenance notification (used in the parse table function to assign an impact for each circuit).
5555
"""
56+
impact = None
5657
for b_elem in b_elements:
5758
if "UTC:" in b_elem:
5859
raw_time = b_elem.next_sibling
@@ -72,6 +73,8 @@ def _parse_b(self, b_elements, data):
7273
impact = Impact.NO_IMPACT
7374
elif "There will be service interruptions" in impact_line.next_sibling.text:
7475
impact = Impact.OUTAGE
76+
elif "Loss of redundancy" in impact_line:
77+
impact = Impact.REDUCED_REDUNDANCY
7578
return impact
7679

7780
def _parse_table(self, theader_elements, data, impact): # pylint: disable=no-self-use
@@ -105,7 +108,7 @@ def parse_subject(self, subject: str) -> List[Dict]:
105108
List[Dict]: Returns the data object with summary and status fields.
106109
"""
107110
data = {}
108-
maintenance_id = re.search(r"\[(.*)\]$", subject)
111+
maintenance_id = re.search(r"\[([^[]*)\]$", subject)
109112
if maintenance_id:
110113
data["maintenance_id"] = maintenance_id[1]
111114
data["summary"] = subject.strip().replace("\n", "")

circuit_maintenance_parser/provider.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def filter_check(filter_dict: Dict, data: NotificationData, filter_type: str) ->
9494
if filter_data_type not in filter_dict:
9595
continue
9696

97-
data_part_content = data_part.content.decode()
97+
data_part_content = data_part.content.decode().replace("\r", "").replace("\n", "")
9898
if any(re.search(filter_re, data_part_content) for filter_re in filter_dict[filter_data_type]):
9999
logger.debug("Matching %s filter expression for %s.", filter_type, data_part_content)
100100
return True
@@ -201,6 +201,8 @@ class Colt(GenericProvider):
201201
class Equinix(GenericProvider):
202202
"""Equinix provider custom class."""
203203

204+
_include_filter = {EMAIL_HEADER_SUBJECT: ["Network Maintenance"]}
205+
204206
_processors: List[GenericProcessor] = [
205207
CombinedProcessor(data_parsers=[HtmlParserEquinix, SubjectParserEquinix, EmailDateParser]),
206208
]
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
[
2+
{
3+
"account": "009999",
4+
"circuits": [
5+
{
6+
"circuit_id": "10101",
7+
"impact": "NO-IMPACT"
8+
},
9+
{
10+
"circuit_id": "10108",
11+
"impact": "NO-IMPACT"
12+
},
13+
{
14+
"circuit_id": "10001",
15+
"impact": "NO-IMPACT"
16+
},
17+
{
18+
"circuit_id": "09999000-B",
19+
"impact": "NO-IMPACT"
20+
},
21+
{
22+
"circuit_id": "09999020-B",
23+
"impact": "NO-IMPACT"
24+
},
25+
{
26+
"circuit_id": "09999045-B",
27+
"impact": "NO-IMPACT"
28+
},
29+
{
30+
"circuit_id": "09999063-B",
31+
"impact": "NO-IMPACT"
32+
},
33+
{
34+
"circuit_id": "09999022-B",
35+
"impact": "NO-IMPACT"
36+
},
37+
{
38+
"circuit_id": "09999022-B",
39+
"impact": "NO-IMPACT"
40+
},
41+
{
42+
"circuit_id": "09999064-B",
43+
"impact": "NO-IMPACT"
44+
},
45+
{
46+
"circuit_id": "09999063-B",
47+
"impact": "NO-IMPACT"
48+
},
49+
{
50+
"circuit_id": "09999069-B",
51+
"impact": "NO-IMPACT"
52+
},
53+
{
54+
"circuit_id": "09999057-B",
55+
"impact": "NO-IMPACT"
56+
},
57+
{
58+
"circuit_id": "09999058-B",
59+
"impact": "NO-IMPACT"
60+
},
61+
{
62+
"circuit_id": "09999052-B",
63+
"impact": "NO-IMPACT"
64+
}
65+
],
66+
"end": 1625238000,
67+
"maintenance_id": "K-293030438574",
68+
"organizer": "[email protected]",
69+
"provider": "equinix",
70+
"sequence": 1,
71+
"stamp": 1634658948,
72+
"start": 1625220000,
73+
"status": "CONFIRMED",
74+
"summary": "Fwd: REMINDER - 3rd Party Equinix Network Device Maintenance-TY Metro Area Network Maintenance -02-JUL-2021 [K-293030438574]",
75+
"uid": "0"
76+
}
77+
]

0 commit comments

Comments
 (0)