Skip to content

Commit

Permalink
Equinix improvements (#112)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
glennmatthews authored Nov 18, 2021
1 parent ce2c5b1 commit 2cbd97b
Show file tree
Hide file tree
Showing 10 changed files with 643 additions and 76 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- #109 - Improve handling of Zayo notifications.
- #110 - Improve handling of Telstra notifications.
- #111 - Improve handling of EXA (GTT) notifications.
- #112 - Improve handling of Equinix notifications.

## v2.0.4 - 2021-11-04

Expand Down
2 changes: 1 addition & 1 deletion circuit_maintenance_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class EmailSubjectParser(Parser):
def parser_hook(self, raw: bytes):
"""Execute parsing."""
result = []
for data in self.parse_subject(self.bytes_to_string(raw).replace("\r\n", "")):
for data in self.parse_subject(self.bytes_to_string(raw).replace("\r", "").replace("\n", "")):
result.append(data)
return result

Expand Down
5 changes: 4 additions & 1 deletion circuit_maintenance_parser/parsers/equinix.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def _parse_b(self, b_elements, data):
Returns:
impact (Status object): impact of the maintenance notification (used in the parse table function to assign an impact for each circuit).
"""
impact = None
for b_elem in b_elements:
if "UTC:" in b_elem:
raw_time = b_elem.next_sibling
Expand All @@ -72,6 +73,8 @@ def _parse_b(self, b_elements, data):
impact = Impact.NO_IMPACT
elif "There will be service interruptions" in impact_line.next_sibling.text:
impact = Impact.OUTAGE
elif "Loss of redundancy" in impact_line:
impact = Impact.REDUCED_REDUNDANCY
return impact

def _parse_table(self, theader_elements, data, impact): # pylint: disable=no-self-use
Expand Down Expand Up @@ -105,7 +108,7 @@ def parse_subject(self, subject: str) -> List[Dict]:
List[Dict]: Returns the data object with summary and status fields.
"""
data = {}
maintenance_id = re.search(r"\[(.*)\]$", subject)
maintenance_id = re.search(r"\[([^[]*)\]$", subject)
if maintenance_id:
data["maintenance_id"] = maintenance_id[1]
data["summary"] = subject.strip().replace("\n", "")
Expand Down
4 changes: 3 additions & 1 deletion circuit_maintenance_parser/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def filter_check(filter_dict: Dict, data: NotificationData, filter_type: str) ->
if filter_data_type not in filter_dict:
continue

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

_include_filter = {EMAIL_HEADER_SUBJECT: ["Network Maintenance"]}

_processors: List[GenericProcessor] = [
CombinedProcessor(data_parsers=[HtmlParserEquinix, SubjectParserEquinix, EmailDateParser]),
]
Expand Down
77 changes: 77 additions & 0 deletions tests/unit/data/equinix/equinix1_result_combined.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
[
{
"account": "009999",
"circuits": [
{
"circuit_id": "10101",
"impact": "NO-IMPACT"
},
{
"circuit_id": "10108",
"impact": "NO-IMPACT"
},
{
"circuit_id": "10001",
"impact": "NO-IMPACT"
},
{
"circuit_id": "09999000-B",
"impact": "NO-IMPACT"
},
{
"circuit_id": "09999020-B",
"impact": "NO-IMPACT"
},
{
"circuit_id": "09999045-B",
"impact": "NO-IMPACT"
},
{
"circuit_id": "09999063-B",
"impact": "NO-IMPACT"
},
{
"circuit_id": "09999022-B",
"impact": "NO-IMPACT"
},
{
"circuit_id": "09999022-B",
"impact": "NO-IMPACT"
},
{
"circuit_id": "09999064-B",
"impact": "NO-IMPACT"
},
{
"circuit_id": "09999063-B",
"impact": "NO-IMPACT"
},
{
"circuit_id": "09999069-B",
"impact": "NO-IMPACT"
},
{
"circuit_id": "09999057-B",
"impact": "NO-IMPACT"
},
{
"circuit_id": "09999058-B",
"impact": "NO-IMPACT"
},
{
"circuit_id": "09999052-B",
"impact": "NO-IMPACT"
}
],
"end": 1625238000,
"maintenance_id": "K-293030438574",
"organizer": "[email protected]",
"provider": "equinix",
"sequence": 1,
"stamp": 1634658948,
"start": 1625220000,
"status": "CONFIRMED",
"summary": "Fwd: REMINDER - 3rd Party Equinix Network Device Maintenance-TY Metro Area Network Maintenance -02-JUL-2021 [K-293030438574]",
"uid": "0"
}
]
Loading

0 comments on commit 2cbd97b

Please sign in to comment.