Skip to content

Commit 58418f5

Browse files
committed
Handle yet more Zayo variants
1 parent 1a3e9ea commit 58418f5

14 files changed

+667
-7
lines changed

circuit_maintenance_parser/parsers/zayo.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Zayo parser."""
22
import logging
3+
import re
34
from typing import Dict
45

56
import bs4 # type: ignore
@@ -22,15 +23,19 @@ class SubjectParserZayo1(EmailSubjectParser):
2223
END OF WINDOW NOTIFICATION***Customer Inc.***ZAYO TTN-0000123456 Planned***
2324
***Customer Inc***ZAYO TTN-0001234567 Emergency MAINTENANCE NOTIFICATION***
2425
RESCHEDULE NOTIFICATION***Customer Inc***ZAYO TTN-0005423873 Planned***
26+
27+
Some degenerate examples have been seen as well:
28+
[notices] CANCELLED NOTIFICATION***Customer,inc***ZAYO TTN-0005432100 Planned**
29+
[notices] Rescheduled Maintenance***ZAYO TTN-0005471719 MAINTENANCE NOTIFICATION***
2530
"""
2631

2732
def parse_subject(self, subject):
2833
"""Parse subject of email message."""
2934
data = {}
30-
tokens = subject.split("***")
35+
tokens = re.split(r"\*+", subject)
3136
if len(tokens) == 4:
3237
data["account"] = tokens[1]
33-
data["maintenance_id"] = tokens[2].split(" ")[1]
38+
data["maintenance_id"] = tokens[-2].split(" ")[1]
3439
return [data]
3540

3641

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

5459
return [data]

circuit_maintenance_parser/provider.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ class Verizon(GenericProvider):
335335
class Zayo(GenericProvider):
336336
"""Zayo provider custom class."""
337337

338+
_include_filter = {
339+
"text/html": ["Maintenance Ticket #"],
340+
"html": ["Maintenance Ticket #"],
341+
}
342+
338343
_processors: List[GenericProcessor] = [
339344
CombinedProcessor(data_parsers=[EmailDateParser, SubjectParserZayo1, HtmlParserZayo1]),
340345
]

tests/unit/data/zayo/zayo7.eml

Lines changed: 567 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"circuits": [
4+
{
5+
"circuit_id": "/IPYX/100722/ /ZYO /",
6+
"impact": "OUTAGE"
7+
}
8+
],
9+
"end": 1637067600,
10+
"maintenance_id": "TTN-0005432100",
11+
"start": 1636876860,
12+
"status": "COMPLETED",
13+
"summary": "Zayo will implement maintenance to repair damaged fiber splice case, to prevent unplanned outages"
14+
}
15+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{
3+
"account": "Example Inc.",
4+
"circuits": [
5+
{
6+
"circuit_id": "/IPYX/100722/ /ZYO /",
7+
"impact": "OUTAGE"
8+
}
9+
],
10+
"end": 1637067600,
11+
"maintenance_id": "TTN-0005432100",
12+
"stamp": 1637068032,
13+
"start": 1636876860,
14+
"status": "COMPLETED",
15+
"summary": "Zayo will implement maintenance to repair damaged fiber splice case, to prevent unplanned outages"
16+
}
17+
]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"account": "Example Inc.",
4+
"maintenance_id": "TTN-0005432100"
5+
}
6+
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
aaa
1+
Maintenance Ticket #: aaa

tests/unit/data/zayo/zayo_missing_maintenance_id.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
0=C2=A0</span><br style=3D"color:rgb(0,0,0)"><br style=3D"color:rgb(0,0,0)"=
1313
><b style=3D"color:rgb(0,0,0)">Customer:=C2=A0</b><span style=3D"color:rgb(=
1414
0,0,0)">clientX=C2=A0</span><br style=3D"color:rgb(0,0,0)"><br style=3D"colo=
15-
r:rgb(0,0,0)"><b style=3D"color:rgb(0,0,0)">Maintenance Window=C2=A0</b><br=
15+
r:rgb(0,0,0)">
16+
<b sty=
17+
le=3D"color:rgb(0,0,0)">Maintenance Ticket #:=C2=A0</b><span style=3D"co=
18+
lor:rgb(0,0,0)"></span><br style=3D"c=
19+
olor:rgb(0,0,0)"><br style=3D"color:rgb(0,0,0)">
20+
<b style=3D"color:rgb(0,0,0)">Maintenance Window=C2=A0</b><br=
1621
style=3D"color:rgb(0,0,0)"><br style=3D"color:rgb(0,0,0)"><b style=3D"colo=
1722
r:rgb(0,0,0)">1<sup>st</sup>=C2=A0Activity Date=C2=A0</b><br style=3D"color=
1823
:rgb(0,0,0)"><span style=3D"color:rgb(0,0,0)">25-Sep-2020 00:01 to 25-Sep-2=
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Subject: [maint-notices] CANCELLED NOTIFICATION***Some Customer,inc***ZAYO
2+
TTN-0005432100 Planned**
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"account": "Some Customer,inc",
4+
"maintenance_id": "TTN-0005432100"
5+
}
6+
]

0 commit comments

Comments
 (0)