Skip to content

Commit 57ad93d

Browse files
authored
Add Google parser (#260)
1 parent 19279ed commit 57ad93d

10 files changed

Lines changed: 341 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ By default, there is a `GenericProvider` that supports a `SimpleProcessor` using
7575
- Equinix
7676
- EXA (formerly GTT)
7777
- HGC
78+
- Google
7879
- Lumen
7980
- Megaport
8081
- Momentum

circuit_maintenance_parser/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
Equinix,
1717
EUNetworks,
1818
GTT,
19+
Google,
1920
HGC,
2021
Lumen,
2122
Megaport,
@@ -43,6 +44,7 @@
4344
CrownCastle,
4445
Equinix,
4546
EUNetworks,
47+
Google,
4648
GTT,
4749
HGC,
4850
Lumen,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""Google parser."""
2+
import logging
3+
import re
4+
from datetime import datetime
5+
6+
from circuit_maintenance_parser.parser import Html, Impact, CircuitImpact, Status
7+
8+
# pylint: disable=too-many-nested-blocks, too-many-branches
9+
10+
logger = logging.getLogger(__name__)
11+
12+
13+
class HtmlParserGoogle1(Html):
14+
"""Notifications Parser for Google notifications."""
15+
16+
def parse_html(self, soup):
17+
"""Execute parsing."""
18+
data = {}
19+
data["circuits"] = []
20+
data["status"] = Status.CONFIRMED
21+
22+
for span in soup.find_all("span"):
23+
if span.string is None:
24+
continue
25+
if span.string.strip() == "Start Time:":
26+
dt_str = span.next_sibling.string.strip()
27+
data["start"] = self.dt2ts(datetime.strptime(dt_str, "%Y-%m-%d %H:%M:%S %z UTC"))
28+
elif span.string.strip() == "End Time:":
29+
dt_str = span.next_sibling.string.strip()
30+
data["end"] = self.dt2ts(datetime.strptime(dt_str, "%Y-%m-%d %H:%M:%S %z UTC"))
31+
elif span.string.strip() == "Peer ASN:":
32+
data["account"] = span.parent.next_sibling.string.strip()
33+
elif span.string.strip() == "Google Neighbor Address(es):":
34+
googleaddr = span.parent.next_sibling.string.strip()
35+
elif span.string.strip() == "Peer Neighbor Address(es):":
36+
cid = googleaddr + "-" + span.parent.next_sibling.string.strip()
37+
data["circuits"].append(CircuitImpact(circuit_id=cid, impact=Impact.OUTAGE))
38+
39+
summary = list(soup.find("div").find("div").strings)[-1].strip()
40+
match = re.search(r" - Reference (.*)$", summary)
41+
data["summary"] = summary
42+
data["maintenance_id"] = match[1]
43+
44+
return [data]

circuit_maintenance_parser/provider.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from circuit_maintenance_parser.parsers.crowncastle import HtmlParserCrownCastle1
2727
from circuit_maintenance_parser.parsers.equinix import HtmlParserEquinix, SubjectParserEquinix
2828
from circuit_maintenance_parser.parsers.gtt import HtmlParserGTT1
29+
from circuit_maintenance_parser.parsers.google import HtmlParserGoogle1
2930
from circuit_maintenance_parser.parsers.hgc import HtmlParserHGC1, HtmlParserHGC2, SubjectParserHGC1
3031
from circuit_maintenance_parser.parsers.lumen import HtmlParserLumen1
3132
from circuit_maintenance_parser.parsers.megaport import HtmlParserMegaport1
@@ -252,6 +253,15 @@ class EUNetworks(GenericProvider):
252253
_default_organizer = "noc@eunetworks.com"
253254

254255

256+
class Google(GenericProvider):
257+
"""Google provider custom class."""
258+
259+
_processors: List[GenericProcessor] = [
260+
CombinedProcessor(data_parsers=[EmailDateParser, HtmlParserGoogle1]),
261+
]
262+
_default_organizer = "noc-noreply@google.com"
263+
264+
255265
class GTT(GenericProvider):
256266
"""EXA (formerly GTT) provider custom class."""
257267

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<div style="font-family: 'Open Sans', sans-serif;">
2+
<div style="font-weight: bold; font-size: larger;"><span style="color: rgb(51, 105, 232);">G</span><span style="color: rgb(213, 15, 37);">o</span><span style="color: rgb(238, 178, 17);">o</span><span style="color:rgb(51, 105, 232);">g</span><span style="color: rgb(0, 153, 37);">l</span><span style="color: rgb(213, 15, 37);">e</span> Network Maintenance Notification - Reference PCR/123456</div>
3+
<hr />
4+
5+
<div style="font-size: smaller;">
6+
This message was sent to: [sample@example.net]<br />
7+
This address was selected from the <a href="http://peering.google.com/">Google ISP Portal</a>. You can update your preferences by navigating to "Configuration > Contacts" and adjusting Email Subscriptions for each user. You can find additional details about Contacts <a href="https://support.google.com/interconnect/answer/7658597?hl=en&ref_topic=7650153">here</a>.
8+
</div>
9+
10+
<br />
11+
<br />
12+
13+
<span style="font-weight: bold;">Details:</span><br />
14+
<span style="font-weight: bold;">Start Time:</span> 2023-12-05 20:55:00 &#43;0000 UTC<br />
15+
<span style="font-weight: bold;">End Time:</span> 2023-12-06 05:05:00 &#43;0000 UTC<br />
16+
<span style="font-weight: bold;">Duration:</span> 8h10m0s<br />
17+
<table>
18+
<tr>
19+
<td><span style="font-weight: bold;">Google ASN:</span></td><td>15169</td>
20+
<td><span style="font-weight: bold;">Peer ASN:</span></td><td>65001</td>
21+
</tr>
22+
=20
23+
<tr style="vertical-align: top;">
24+
<td><span style="font-weight: bold;">Google Neighbor Address(es):</span></td><td>192.0.2.1</td>
25+
<td><span style="font-weight: bold;">Peer Neighbor Address(es):</span></td><td>192.0.2.0</td>
26+
</tr>
27+
=20
28+
<tr style="vertical-align: top;">
29+
<td><span style="font-weight: bold;">Google Neighbor Address(es):</span></td><td>2001:db8::1</td>
30+
<td><span style="font-weight: bold;">Peer Neighbor Address(es):</span></td><td>2001:db8::</td>
31+
</tr>
32+
=20
33+
</table>
34+
35+
<p>
36+
Google systems will automatically re-route the traffic away from the peering link(s) under maintenance.
37+
</p>
38+
<p>
39+
Depending on the nature of the work, your BGP session with Google may stay up through the maintenance window. Traffic may shift to alternate sessions with Google and/or your upstream provider(s).
40+
</p>
41+
<p>
42+
Questions about this event can be sent to noc@google.com.
43+
</p>
44+
<p>
45+
Thank you for peering with <span style="color: rgb(51, 105, 232);">G</span><span style="color: rgb(213, 15, 37);">o</span><span style="color: rgb(238, 178, 17);">o</span><span style="color: rgb(51, 105, 232);">g</span><span style="color: rgb(0, 153, 37);">l</span><span style="color: rgb(213, 15, 37);">e</span>!<br />
46+
</p>
47+
<hr />
48+
<br />
49+
<div style="font-size: smaller; color: silver;">
50+
PRIVILEGE AND CONFIDENTIALITY NOTICE: The information in this
51+
e-mail communication and any attached documents may be privileged,
52+
confidential or otherwise protected from disclosure and is intended only
53+
for the use of the designated recipient(s). If the reader is neither the
54+
intended recipient nor an employee or agent thereof who is responsible
55+
for delivering it to the intended recipient, you are hereby notified
56+
that any review, dissemination, distribution, copying or other use of
57+
this communication is strictly prohibited. If you have received this
58+
communication in error, please immediately notify us by return e-mail
59+
and promptly delete the original electronic e-mail communication and
60+
any attached documentation. Receipt by anyone other than the intended
61+
recipient is not a waiver of any attorney-client or work-product
62+
privilege.
63+
</div>
64+
</div>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"account": "65001",
4+
"circuits": [
5+
{
6+
"circuit_id": "192.0.2.1-192.0.2.0",
7+
"impact": "OUTAGE"
8+
},
9+
{
10+
"circuit_id": "2001:db8::1-2001:db8::",
11+
"impact": "OUTAGE"
12+
}
13+
],
14+
"end": 1701839100,
15+
"maintenance_id": "PCR/123456",
16+
"start": 1701809700,
17+
"status": "CONFIRMED",
18+
"summary": "Network Maintenance Notification - Reference PCR/123456"
19+
}
20+
]

tests/unit/data/google/google2.eml

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
Date: Wed, 06 Dec 2023 00:40:05 +0000
2+
Subject: [Scheduled] Google Planned Network Maintenance Notification - Reference PCR/123456
3+
From: Google NOC <noc-noreply@google.com>
4+
Content-Type: multipart/alternative; boundary="000000000000a556e4060bffffff"
5+
6+
--000000000000a556e4060bffffff
7+
Content-Type: text/plain; charset="UTF-8"; format=flowed; delsp=yes
8+
9+
Google Network Maintenance Notification - Reference PCR/123456
10+
11+
12+
This message was sent to: [sample@example.net]
13+
This address was selected from the Google ISP Portal. You can update your
14+
preferences by navigating to "Configuration > Contacts" and adjusting Email
15+
Subscriptions for each user. You can find additional details about Contacts
16+
here.
17+
18+
19+
Details:
20+
Start Time: 2023-12-05 20:55:00 +0000 UTC
21+
End Time: 2023-12-06 05:05:00 +0000 UTC
22+
Duration: 8h10m0s
23+
24+
25+
Google ASN: 15169 Peer ASN: 65001
26+
27+
Google Neighbor Address(es): 192.0.2.1 Peer Neighbor Address(es):
28+
192.0.2.0
29+
30+
Google Neighbor Address(es): 2001:db8::1 Peer Neighbor
31+
Address(es): 2001:db8::
32+
33+
34+
Google systems will automatically re-route the traffic away from the
35+
peering link(s) under maintenance.
36+
37+
Depending on the nature of the work, your BGP session with Google may stay
38+
up through the maintenance window. Traffic may shift to alternate sessions
39+
with Google and/or your upstream provider(s).
40+
41+
Questions about this event can be sent to noc@google.com.
42+
43+
Thank you for peering with Google!
44+
45+
46+
47+
PRIVILEGE AND CONFIDENTIALITY NOTICE: The information in this e-mail
48+
communication and any attached documents may be privileged, confidential or
49+
otherwise protected from disclosure and is intended only for the use of the
50+
designated recipient(s). If the reader is neither the intended recipient
51+
nor an employee or agent thereof who is responsible for delivering it to
52+
the intended recipient, you are hereby notified that any review,
53+
dissemination, distribution, copying or other use of this communication is
54+
strictly prohibited. If you have received this communication in error,
55+
please immediately notify us by return e-mail and promptly delete the
56+
original electronic e-mail communication and any attached documentation.
57+
Receipt by anyone other than the intended recipient is not a waiver of any
58+
attorney-client or work-product privilege.
59+
60+
61+
--000000000000a556e4060bffffff
62+
Content-Type: text/html; charset="UTF-8"
63+
Content-Transfer-Encoding: quoted-printable
64+
65+
66+
<div style=3D"font-family: 'Open Sans', sans-serif;">
67+
<div style=3D"font-weight: bold; font-size: larger;"><span style=3D"color=
68+
: rgb(51, 105, 232);">G</span><span style=3D"color: rgb(213, 15, 37);">o</s=
69+
pan><span style=3D"color: rgb(238, 178, 17);">o</span><span style=3D"color:=
70+
rgb(51, 105, 232);">g</span><span style=3D"color: rgb(0, 153, 37);">l</spa=
71+
n><span style=3D"color: rgb(213, 15, 37);">e</span> Network Maintenance No=
72+
tification - Reference PCR/123456</div>
73+
<hr />
74+
=20
75+
<div style=3D"font-size: smaller;">
76+
This message was sent to: [sample@example.net]<br />
77+
This address was selected from the <a href=3D"http://peering.google.com/"=
78+
>Google ISP Portal</a>. You can update your preferences by navigating to "C=
79+
onfiguration > Contacts" and adjusting Email Subscriptions for each user. Y=
80+
ou can find additional details about Contacts <a href=3D"https://support.go=
81+
ogle.com/interconnect/answer/7658597?hl=3Den&ref_topic=3D7650153">here</a>.
82+
</div>
83+
84+
<br />
85+
<br />
86+
=20
87+
<span style=3D"font-weight: bold;">Details:</span><br />
88+
<span style=3D"font-weight: bold;">Start Time:</span> 2023-12-05 20:55:00=
89+
&#43;0000 UTC<br />
90+
<span style=3D"font-weight: bold;">End Time:</span> 2023-12-06 05:05:00 &=
91+
#43;0000 UTC<br />
92+
<span style=3D"font-weight: bold;">Duration:</span> 8h10m0s<br />
93+
<table>
94+
<tr>
95+
<td><span style=3D"font-weight: bold;">Google ASN:</span></td><td>151=
96+
69</td>
97+
<td><span style=3D"font-weight: bold;">Peer ASN:</span></td><td>65001<=
98+
/td>
99+
</tr>
100+
=20
101+
<tr style=3D"vertical-align: top;">
102+
<td><span style=3D"font-weight: bold;">Google Neighbor Address(es):</=
103+
span></td><td>192.0.2.1</td>
104+
<td><span style=3D"font-weight: bold;">Peer Neighbor Address(es):</sp=
105+
an></td><td>192.0.2.0</td>
106+
</tr>
107+
=20
108+
<tr style=3D"vertical-align: top;">
109+
<td><span style=3D"font-weight: bold;">Google Neighbor Address(es):</=
110+
span></td><td>2001:db8::1</td>
111+
<td><span style=3D"font-weight: bold;">Peer Neighbor Address(es):</sp=
112+
an></td><td>2001:db8::</td>
113+
</tr>
114+
=20
115+
</table>
116+
117+
<p>
118+
Google systems will automatically re-route the traffic away from the peer=
119+
ing link(s) under maintenance.
120+
</p>
121+
<p>
122+
Depending on the nature of the work, your BGP session with Google may sta=
123+
y up through the maintenance window. Traffic may shift to alternate session=
124+
s with Google and/or your upstream provider(s).
125+
</p>
126+
<p>
127+
Questions about this event can be sent to noc@google.com.
128+
</p>
129+
<p>
130+
Thank you for peering with <span style=3D"color: rgb(51, 105, 232);">G</s=
131+
pan><span style=3D"color: rgb(213, 15, 37);">o</span><span style=3D"color: =
132+
rgb(238, 178, 17);">o</span><span style=3D"color: rgb(51, 105, 232);">g</sp=
133+
an><span style=3D"color: rgb(0, 153, 37);">l</span><span style=3D"color: rg=
134+
b(213, 15, 37);">e</span>!<br />
135+
</p>
136+
<hr />
137+
<br />
138+
<div style=3D"font-size: smaller; color: silver;">
139+
PRIVILEGE AND CONFIDENTIALITY NOTICE: The information in this
140+
e-mail communication and any attached documents may be privileged,
141+
confidential or otherwise protected from disclosure and is intended onl=
142+
y
143+
for the use of the designated recipient(s). If the reader is neither th=
144+
e
145+
intended recipient nor an employee or agent thereof who is responsible
146+
for delivering it to the intended recipient, you are hereby notified
147+
that any review, dissemination, distribution, copying or other use of
148+
this communication is strictly prohibited. If you have received this
149+
communication in error, please immediately notify us by return e-mail
150+
and promptly delete the original electronic e-mail communication and
151+
any attached documentation. Receipt by anyone other than the intended
152+
recipient is not a waiver of any attorney-client or work-product
153+
privilege.
154+
</div>
155+
</div>
156+
157+
--000000000000a556e4060bffffff--
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[
2+
{
3+
"account": "65001",
4+
"circuits": [
5+
{
6+
"circuit_id": "192.0.2.1-192.0.2.0",
7+
"impact": "OUTAGE"
8+
},
9+
{
10+
"circuit_id": "2001:db8::1-2001:db8::",
11+
"impact": "OUTAGE"
12+
}
13+
],
14+
"end": 1701839100,
15+
"maintenance_id": "PCR/123456",
16+
"organizer": "noc-noreply@google.com",
17+
"provider": "google",
18+
"sequence": 1,
19+
"stamp": 1701823205,
20+
"start": 1701809700,
21+
"status": "CONFIRMED",
22+
"summary": "Network Maintenance Notification - Reference PCR/123456",
23+
"uid": "0"
24+
}
25+
]

tests/unit/test_e2e.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
Colt,
2222
CrownCastle,
2323
EUNetworks,
24+
Google,
2425
GTT,
2526
HGC,
2627
Lumen,
@@ -420,6 +421,16 @@
420421
Path(dir_path, "data", "hgc", "hgc2_result.json"),
421422
],
422423
),
424+
# Google
425+
(
426+
Google,
427+
[
428+
("email", Path(dir_path, "data", "google", "google2.eml")),
429+
],
430+
[
431+
Path(dir_path, "data", "google", "google2_result.json"),
432+
],
433+
),
423434
# Lumen
424435
(
425436
Lumen,

0 commit comments

Comments
 (0)