Skip to content

Commit

Permalink
Improve EXA (GTT) parser (#111)
Browse files Browse the repository at this point in the history
* Add support for re-scheduled EXA/GTT notifications

* Add support for new and completed GTT/EXA notifications

* Cleanup

* Add subject include_filter for GTT/EXA

* Review comment
  • Loading branch information
glennmatthews authored Nov 17, 2021
1 parent b5306a1 commit 39a5dcb
Show file tree
Hide file tree
Showing 17 changed files with 587 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ By default, there is a `GenericProvider` that support a `SimpleProcessor` using
- Cogent
- Colt
- Equinix
- GTT
- EXA (formerly GTT)
- HGC
- Lumen
- Megaport
Expand Down
26 changes: 21 additions & 5 deletions circuit_maintenance_parser/parsers/gtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


class HtmlParserGTT1(Html):
"""Notifications Parser for GTT notifications."""
"""Notifications Parser for EXA (formerly GTT) notifications."""

def parse_html(self, soup):
"""Execute parsing."""
Expand All @@ -33,21 +33,37 @@ def parse_tables(self, tables, data):
if groups:
data["maintenance_id"] = groups.groups()[0]
status = groups.groups()[1]
if status == "Reminder":
if status in ("New", "Reminder"):
data["status"] = Status["CONFIRMED"]
elif status == "Update":
elif status in ("Update", "Rescheduled"):
data["status"] = Status["RE_SCHEDULED"]
elif status == "Cancelled":
data["status"] = Status["CANCELLED"]
# When a email is cancelled there is no start or end time specificed
# Setting this to 0 and 1 stops any errors from pydantic
data["start"] = 0
data["end"] = 1
elif status == "Completed":
data["status"] = Status["COMPLETED"]
elif "Start" in td_element.text:
start = parser.parse(td_element.next_sibling.next_sibling.text)
# In the case of a normal notification, we have:
# <td> <strong>TIME</strong></td>
# But in the case of a reschedule, we have:
# <td> <strong><strike>OLD TIME</strike><font>NEW TIME</font></strong></td>
next_td = td_element.next_sibling.next_sibling
strong = next_td.contents[1]
if strong.string:
start = parser.parse(strong.string)
else:
start = parser.parse(strong.contents[1].string)
data["start"] = self.dt2ts(start)
elif "End" in td_element.text:
end = parser.parse(td_element.next_sibling.next_sibling.text)
next_td = td_element.next_sibling.next_sibling
strong = next_td.contents[1]
if strong.string:
end = parser.parse(strong.string)
else:
end = parser.parse(strong.contents[1].string)
data["end"] = self.dt2ts(end)
num_columns = len(table.find_all("th"))
if num_columns:
Expand Down
7 changes: 5 additions & 2 deletions circuit_maintenance_parser/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,15 @@ class EUNetworks(GenericProvider):


class GTT(GenericProvider):
"""GTT provider custom class."""
"""EXA (formerly GTT) provider custom class."""

# "Planned Work Notification", "Emergency Work Notification"
_include_filter = {EMAIL_HEADER_SUBJECT: ["Work Notification"]}

_processors: List[GenericProcessor] = [
CombinedProcessor(data_parsers=[EmailDateParser, HtmlParserGTT1]),
]
_default_organizer = "InfraCo.CM@gttcorp.org"
_default_organizer = "InfraCo.CM@exainfra.net"


class HGC(GenericProvider):
Expand Down
1 change: 1 addition & 0 deletions tests/unit/data/gtt/gtt1_email_subject
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GTT Emergency Work Notification TT 11111111 – Update
1 change: 1 addition & 0 deletions tests/unit/data/gtt/gtt2_email_subject
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GTT Emergency Work Notification TT 11111111 – Reminder
1 change: 1 addition & 0 deletions tests/unit/data/gtt/gtt3_email_subject
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GTT Emergency Work Notification TT 11111111 – Cancelled
127 changes: 127 additions & 0 deletions tests/unit/data/gtt/gtt4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<!DOCTYPE html>
<html lang=3D"en">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8">
<meta charset=3D"utf-8">
=20
</head>
<body>
<div style=3D"width: 740px; font-family: Verdana, Arial, Helvetica, sans-se=
rif; font-size: 10pt; margin: 0 auto;">
<table border=3D"0" cellpadding=3D"0" cellspacing=3D"0" width=3D"740" s=
tyle=3D"border-collapse: collapse; padding-left: 5px; border: 1px none blac=
k;">
<tr>
<td width=3D"30%" style=3D"border-collapse: collapse; padding-l=
eft: 5px; border: 1px none black;"><img src=3D"https://myportal.exainfra.ne=
t/assets/img/logos/exa-logo-small.png" border=3D"0"></td>
<td width=3D"70%" align=3D"center" style=3D"border-collapse: co=
llapse; padding-left: 5px; border: 1px none black;"><strong><i>Planned Work=
Notification: 60543210 - Rescheduled</i></strong></td>
</tr>
</table>
<p>Please note that the Planned Work is rescheduled.=E2=80=AFPlease see=
details of the work and impact on your service below. </p>
<p>
<strong>Reschedule Reason:</strong><br>
rescheduled by supplier
</p>
<strong>Details:</strong><br>
<table border=3D"1" cellpadding=3D"4" cellspacing=3D"0" style=3D"width:=
100%; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 8pt; bor=
der-collapse: collapse; padding-left: 5px; border: 1px solid black;">
<tr>
<td width=3D"15%" style=3D"border-collapse: collapse; padding-left:=
5px; color: white; font-weight: bold; border: 1px solid black;" bgcolor=3D=
"#2B3C8A">
<strong>Start</strong>
</td>
<td width=3D"85%" style=3D"border-collapse: collapse; padding-left: 5px; bo=
rder: 1px solid black;">
<strong><strike>2021-11-10 03:00:00 GMT </strike><font color=3D'red'>2021-1=
2-08 03:00 GMT</font></strong>
</td>
</tr>
<tr>
<td style=3D"border-collapse: collapse; padding-left: 5px; color: w=
hite; font-weight: bold; border: 1px solid black;" bgcolor=3D"#2B3C8A">
<strong>End</strong>
</td>
<td style=3D"border-collapse: collapse; padding-left: 5px; border: 1px soli=
d black;">
<strong><strike>2021-11-10 11:00:00 GMT </strike><font color=3D'red'>2021-1=
2-08 11:00 GMT</font></strong>
</td>
</tr>
=20
=20
<tr>
<td style=3D"border-collapse: collapse; padding-left: 5px; color: w=
hite; font-weight: bold; border: 1px solid black;" bgcolor=3D"#2B3C8A">
<strong>Location</strong>
</td>
<td style=3D"border-collapse: collapse; padding-left: 5px; border: 1px soli=
d black;">
<strong>Vaden Dr & Country Creek Rd in Oakton, VA</strong>
</td>
</tr>
</table>

<p>
<strong>Planned work Reason:</strong><br>
Network optimization on our partner network
</p>
<table border=3D"1" cellpadding=3D"4" cellspacing=3D"0" style=3D"width:=
100%; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 8pt; bor=
der-collapse: collapse; padding-left: 5px; border: 1px solid black;">
<thead>
<tr>
<th style=3D"border-collapse: collapse; padding-left: 5px; color: w=
hite; font-weight: bold; border: 1px solid black;" width=3D"15%" align=3D"c=
enter" bgcolor=3D"#2B3C8A"><strong>Services Affected</strong></th>
<th style=3D"border-collapse: collapse; padding-left: 5px; color: w=
hite; font-weight: bold; border: 1px solid black;" width=3D"15%" align=3D"c=
enter" bgcolor=3D"#2B3C8A"><strong>SLID/CCSD</strong></th>
<th style=3D"border-collapse: collapse; padding-left: 5px; color: w=
hite; font-weight: bold; border: 1px solid black;" width=3D"10%" align=3D"c=
enter" bgcolor=3D"#2B3C8A"><strong>Customer PON</strong></th>
<th style=3D"border-collapse: collapse; padding-left: 5px; color: w=
hite; font-weight: bold; border: 1px solid black;" width=3D"10%" align=3D"c=
enter" bgcolor=3D"#2B3C8A"><strong>Service Type</strong></th>
<th style=3D"border-collapse: collapse; padding-left: 5px; color: w=
hite; font-weight: bold; border: 1px solid black;" width=3D"15%" align=3D"c=
enter" bgcolor=3D"#2B3C8A"><strong>Expected Impact to your Service</strong>=
</th>
<th style=3D"border-collapse: collapse; padding-left: 5px; color: w=
hite; font-weight: bold; border: 1px solid black;" width=3D"35%" align=3D"c=
enter" bgcolor=3D"#2B3C8A"><strong>Site Address</strong></th>
</tr>
</thead>
=20
<tr>
<td style=3D"border-collapse: collapse; padding-left: 5px; border: =
1px solid black;" align=3D"center">HI/Wavelength/00696969</td>
<td style=3D"border-collapse: collapse; padding-left: 5px; border: =
1px solid black;" align=3D"center">1234567-10987654</td>
<td style=3D"border-collapse: collapse; padding-left: 5px; border: =
1px solid black;" align=3D"center">PO # RGB00012345</td>
<td style=3D"border-collapse: collapse; padding-left: 5px; border: =
1px solid black;" align=3D"center">Wavelength</td>
<td style=3D"border-collapse: collapse; padding-left: 5px; border: =
1px solid black;" align=3D"center">180 min</td>
<td style=3D"border-collapse: collapse; padding-left: 5px; border: =
1px solid black;" align=3D"center">12345 Some St, Ashburn, VA 20147, USA</td>
</tr>
=20
</table>
=20
<p>If you have any questions regarding the planned work, please login t=
o <a href=3D"https://myportal.exainfra.net/sign-in">MyPortal</a> or contact=
our Change Management Team using the email below.</p>

<br>Kind Regards,
<br>EXA Network Operations
<br>[email protected]
</div>
</body>
</html>
1 change: 1 addition & 0 deletions tests/unit/data/gtt/gtt4_email_subject
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXA Emergency Work Notification TT 60543210 – Reschedule
15 changes: 15 additions & 0 deletions tests/unit/data/gtt/gtt4_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"account": "PO # RGB00012345",
"circuits": [
{
"circuit_id": "1234567-10987654",
"impact": "OUTAGE"
}
],
"end": 1638961200,
"maintenance_id": "60543210",
"start": 1638932400,
"status": "RE-SCHEDULED"
}
]
125 changes: 125 additions & 0 deletions tests/unit/data/gtt/gtt5.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<!DOCTYPE html>
<html lang=3D"en">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8">
<meta charset=3D"utf-8">
=20
</head>
<body>
<div style=3D"width: 740px; font-family: Verdana, Arial, Helvetica, sans-se=
rif; font-size: 10pt; margin: 0 auto;">
<table border=3D"0" cellpadding=3D"0" cellspacing=3D"0" width=3D"740" s=
tyle=3D"border-collapse: collapse; padding-left: 5px; border: 1px none blac=
k;">
<tr>
<td width=3D"30%" style=3D"border-collapse: collapse; padding-l=
eft: 5px; border: 1px none black;"><img src=3D"https://myportal.exainfra.ne=
t/assets/img/logos/exa-logo-small.png" border=3D"0"></td>
<td width=3D"70%" align=3D"center" style=3D"border-collapse: co=
llapse; padding-left: 5px; border: 1px none black;"><strong><i>Planned Work=
Notification: 60543210 - Completed</i></strong></td>
</tr>
</table>

<br>
<strong>Final Update:</strong><br>
***Completed*** This notice is to inform you that the Planned Maintenan=
ce has concluded.
<br><br>
<strong>Details:</strong><br>
<table border=3D"1" cellpadding=3D"4" cellspacing=3D"0" style=3D"width:=
100%; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 8pt; bor=
der-collapse: collapse; padding-left: 5px; border: 1px solid black;">
<tr>
<td width=3D"15%" style=3D"border-collapse: collapse; padding-left:=
5px; color: white; font-weight: bold; border: 1px solid black;" bgcolor=3D=
"#2B3C8A">
<strong>Start</strong>
</td>
<td width=3D"85%" style=3D"border-collapse: collapse; padding-left: 5px; bo=
rder: 1px solid black;">
<strong>2021-11-13 04:00:00 GMT</strong>
</td>
</tr>
<tr>
<td style=3D"border-collapse: collapse; padding-left: 5px; color: w=
hite; font-weight: bold; border: 1px solid black;" bgcolor=3D"#2B3C8A">
<strong>End</strong>
</td>
<td style=3D"border-collapse: collapse; padding-left: 5px; border: 1px soli=
d black;">
<strong>2021-11-13 10:00:00 GMT</strong>
</td>
</tr>
=20
<tr>
<td style=3D"border-collapse: collapse; padding-left: 5px; color: w=
hite; font-weight: bold; border: 1px solid black;" bgcolor=3D"#2B3C8A">
<strong>Location</strong>
</td>
<td style=3D"border-collapse: collapse; padding-left: 5px; border: 1px soli=
d black;">
<strong>165 Some Street, New Jersey</strong>
</td>
</tr>
</table>

<p>
<strong>Planned work Reason:</strong><br>
Emergency software upgrade on the 165Some Street
</p>
<table border=3D"1" cellpadding=3D"4" cellspacing=3D"0" style=3D"width:=
100%; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 8pt; bor=
der-collapse: collapse; padding-left: 5px; border: 1px solid black;">
<thead>
<tr>
<th style=3D"border-collapse: collapse; padding-left: 5px; color: w=
hite; font-weight: bold; border: 1px solid black;" width=3D"15%" align=3D"c=
enter" bgcolor=3D"#2B3C8A"><strong>Services Affected</strong></th>
<th style=3D"border-collapse: collapse; padding-left: 5px; color: w=
hite; font-weight: bold; border: 1px solid black;" width=3D"15%" align=3D"c=
enter" bgcolor=3D"#2B3C8A"><strong>SLID/CCSD</strong></th>
<th style=3D"border-collapse: collapse; padding-left: 5px; color: w=
hite; font-weight: bold; border: 1px solid black;" width=3D"10%" align=3D"c=
enter" bgcolor=3D"#2B3C8A"><strong>Customer PON</strong></th>
<th style=3D"border-collapse: collapse; padding-left: 5px; color: w=
hite; font-weight: bold; border: 1px solid black;" width=3D"10%" align=3D"c=
enter" bgcolor=3D"#2B3C8A"><strong>Service Type</strong></th>
<th style=3D"border-collapse: collapse; padding-left: 5px; color: w=
hite; font-weight: bold; border: 1px solid black;" width=3D"15%" align=3D"c=
enter" bgcolor=3D"#2B3C8A"><strong>Expected Impact to your Service</strong>=
</th>
<th style=3D"border-collapse: collapse; padding-left: 5px; color: w=
hite; font-weight: bold; border: 1px solid black;" width=3D"35%" align=3D"c=
enter" bgcolor=3D"#2B3C8A"><strong>Site Address</strong></th>
</tr>
</thead>
=20
<tr>
<td style=3D"border-collapse: collapse; padding-left: 5px; border: =
1px solid black;" align=3D"center">HI/Wavelength/00696969</td>
<td style=3D"border-collapse: collapse; padding-left: 5px; border: =
1px solid black;" align=3D"center">1815743-10987654</td>
<td style=3D"border-collapse: collapse; padding-left: 5px; border: =
1px solid black;" align=3D"center">PO # RGD00012345</td>
<td style=3D"border-collapse: collapse; padding-left: 5px; border: =
1px solid black;" align=3D"center">Wavelength</td>
<td style=3D"border-collapse: collapse; padding-left: 5px; border: =
1px solid black;" align=3D"center">90 min</td>
<td style=3D"border-collapse: collapse; padding-left: 5px; border: =
1px solid black;" align=3D"center">23456 Some St, Ashburn, VA 20147, USA</td>
</tr>
=20
</table>
=20
<p>If you have any questions regarding the planned work or if you are s=
till experiencing a service outage, please login to <a href=3D"https://mypo=
rtal.exainfra.net/sign-in">MyPortal</a> or contact our Change Management Te=
am using the email below.</p>

<br>Kind Regards,
<br>EXA Network Operations
<br>[email protected]
</div>
</body>
</html>
1 change: 1 addition & 0 deletions tests/unit/data/gtt/gtt5_email_subject
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXA Emergency Work Notification TT 60543210 – Completed
15 changes: 15 additions & 0 deletions tests/unit/data/gtt/gtt5_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"account": "PO # RGD00012345",
"circuits": [
{
"circuit_id": "1815743-10987654",
"impact": "OUTAGE"
}
],
"end": 1636797600,
"maintenance_id": "60543210",
"start": 1636776000,
"status": "COMPLETED"
}
]
Loading

0 comments on commit 39a5dcb

Please sign in to comment.