Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle yet more Zayo variants #120

Merged
merged 2 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v2.0.7 - 2021-MM-DD

### Fixed

- #120 - Improve handling of Zayo notifications.

## v2.0.6 - 2021-11-30

### Added
Expand Down
11 changes: 8 additions & 3 deletions circuit_maintenance_parser/parsers/zayo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Zayo parser."""
import logging
import re
from typing import Dict

import bs4 # type: ignore
Expand All @@ -22,15 +23,19 @@ class SubjectParserZayo1(EmailSubjectParser):
END OF WINDOW NOTIFICATION***Customer Inc.***ZAYO TTN-0000123456 Planned***
***Customer Inc***ZAYO TTN-0001234567 Emergency MAINTENANCE NOTIFICATION***
RESCHEDULE NOTIFICATION***Customer Inc***ZAYO TTN-0005423873 Planned***

Some degenerate examples have been seen as well:
[notices] CANCELLED NOTIFICATION***Customer,inc***ZAYO TTN-0005432100 Planned**
[notices] Rescheduled Maintenance***ZAYO TTN-0005471719 MAINTENANCE NOTIFICATION***
"""

def parse_subject(self, subject):
"""Parse subject of email message."""
data = {}
tokens = subject.split("***")
tokens = re.split(r"\*+", subject)
if len(tokens) == 4:
data["account"] = tokens[1]
data["maintenance_id"] = tokens[2].split(" ")[1]
data["maintenance_id"] = tokens[-2].split(" ")[1]
return [data]


Expand All @@ -48,7 +53,7 @@ def parse_html(self, soup):
text = soup.get_text()
if "will be commencing momentarily" in text:
data["status"] = Status("IN-PROCESS")
elif "has been completed" in text:
elif "has been completed" in text or "has closed" in text:
data["status"] = Status("COMPLETED")

return [data]
Expand Down
5 changes: 5 additions & 0 deletions circuit_maintenance_parser/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ class Verizon(GenericProvider):
class Zayo(GenericProvider):
"""Zayo provider custom class."""

_include_filter = {
"text/html": ["Maintenance Ticket #"],
"html": ["Maintenance Ticket #"],
}

_processors: List[GenericProcessor] = [
CombinedProcessor(data_parsers=[EmailDateParser, SubjectParserZayo1, HtmlParserZayo1]),
]
Expand Down
567 changes: 567 additions & 0 deletions tests/unit/data/zayo/zayo7.eml

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions tests/unit/data/zayo/zayo7_html_parser_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"circuits": [
{
"circuit_id": "/IPYX/100722/ /ZYO /",
"impact": "OUTAGE"
}
],
"end": 1637067600,
"maintenance_id": "TTN-0005432100",
"start": 1636876860,
"status": "COMPLETED",
"summary": "Zayo will implement maintenance to repair damaged fiber splice case, to prevent unplanned outages"
}
]
17 changes: 17 additions & 0 deletions tests/unit/data/zayo/zayo7_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"account": "Example Inc.",
"circuits": [
{
"circuit_id": "/IPYX/100722/ /ZYO /",
"impact": "OUTAGE"
}
],
"end": 1637067600,
"maintenance_id": "TTN-0005432100",
"stamp": 1637068032,
"start": 1636876860,
"status": "COMPLETED",
"summary": "Zayo will implement maintenance to repair damaged fiber splice case, to prevent unplanned outages"
}
]
6 changes: 6 additions & 0 deletions tests/unit/data/zayo/zayo7_subject_parser_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"account": "Example Inc.",
"maintenance_id": "TTN-0005432100"
}
]
2 changes: 1 addition & 1 deletion tests/unit/data/zayo/zayo_bad_html.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
aaa
Maintenance Ticket #: aaa
7 changes: 6 additions & 1 deletion tests/unit/data/zayo/zayo_missing_maintenance_id.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
0=C2=A0</span><br style=3D"color:rgb(0,0,0)"><br style=3D"color:rgb(0,0,0)"=
><b style=3D"color:rgb(0,0,0)">Customer:=C2=A0</b><span style=3D"color:rgb(=
0,0,0)">clientX=C2=A0</span><br style=3D"color:rgb(0,0,0)"><br style=3D"colo=
r:rgb(0,0,0)"><b style=3D"color:rgb(0,0,0)">Maintenance Window=C2=A0</b><br=
r:rgb(0,0,0)">
<b sty=
le=3D"color:rgb(0,0,0)">Maintenance Ticket #:=C2=A0</b><span style=3D"co=
lor:rgb(0,0,0)"></span><br style=3D"c=
olor:rgb(0,0,0)"><br style=3D"color:rgb(0,0,0)">
<b style=3D"color:rgb(0,0,0)">Maintenance Window=C2=A0</b><br=
style=3D"color:rgb(0,0,0)"><br style=3D"color:rgb(0,0,0)"><b style=3D"colo=
r:rgb(0,0,0)">1<sup>st</sup>=C2=A0Activity Date=C2=A0</b><br style=3D"color=
:rgb(0,0,0)"><span style=3D"color:rgb(0,0,0)">25-Sep-2020 00:01 to 25-Sep-2=
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/data/zayo/zayo_subject_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Subject: [maint-notices] CANCELLED NOTIFICATION***Some Customer,inc***ZAYO
TTN-0005432100 Planned**
6 changes: 6 additions & 0 deletions tests/unit/data/zayo/zayo_subject_1_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"account": "Some Customer,inc",
"maintenance_id": "TTN-0005432100"
}
]
2 changes: 2 additions & 0 deletions tests/unit/data/zayo/zayo_subject_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Subject: [maint-notices] Rescheduled Maintenance***ZAYO TTN-0005432100
MAINTENANCE NOTIFICATION***
5 changes: 5 additions & 0 deletions tests/unit/data/zayo/zayo_subject_2_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{
"maintenance_id": "TTN-0005432100"
}
]
9 changes: 7 additions & 2 deletions tests/unit/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@
Zayo,
[("email", Path(dir_path, "data", "zayo", "zayo6.eml")),],
[Path(dir_path, "data", "zayo", "zayo6_result.json"),],
),
(
Zayo,
[("email", Path(dir_path, "data", "zayo", "zayo7.eml")),],
[Path(dir_path, "data", "zayo", "zayo7_result.json"),],
), # pylint: disable=too-many-locals
],
)
Expand Down Expand Up @@ -596,7 +601,7 @@ def test_provider_get_maintenances(provider_class, test_data_files, result_parse
Details:
- Processor CombinedProcessor from Zayo failed due to: 1 validation error for Maintenance
maintenance_id
field required (type=value_error.missing)
String is empty or 'None' (type=value_error)
""",
),
(
Expand All @@ -608,7 +613,7 @@ def test_provider_get_maintenances(provider_class, test_data_files, result_parse
Failed creating Maintenance notification for Zayo.
Details:
- Processor CombinedProcessor from Zayo failed due to: HtmlParserZayo1 parser was not able to extract the expected data for each maintenance.
- Raw content: b'aaa'
- Raw content: b'Maintenance Ticket #: aaa\\n'
- Result: [{}]
""",
),
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,16 @@
Path(dir_path, "data", "verizon", "verizon3_result.json"),
),
# Zayo
(
SubjectParserZayo1,
Path(dir_path, "data", "zayo", "zayo_subject_1.txt"),
Path(dir_path, "data", "zayo", "zayo_subject_1_result.json"),
),
(
SubjectParserZayo1,
Path(dir_path, "data", "zayo", "zayo_subject_2.txt"),
Path(dir_path, "data", "zayo", "zayo_subject_2_result.json"),
),
(
HtmlParserZayo1,
Path(dir_path, "data", "zayo", "zayo1.html"),
Expand Down Expand Up @@ -341,6 +351,16 @@
Path(dir_path, "data", "zayo", "zayo6.eml"),
Path(dir_path, "data", "zayo", "zayo6_subject_parser_result.json"),
),
(
HtmlParserZayo1,
Path(dir_path, "data", "zayo", "zayo7.eml"),
Path(dir_path, "data", "zayo", "zayo7_html_parser_result.json"),
),
(
SubjectParserZayo1,
Path(dir_path, "data", "zayo", "zayo7.eml"),
Path(dir_path, "data", "zayo", "zayo7_subject_parser_result.json"),
),
# Email Date
(
EmailDateParser,
Expand Down