-
Notifications
You must be signed in to change notification settings - Fork 24
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
Parser for Apple peering notifications #227
Open
slyngshede
wants to merge
6
commits into
networktocode:develop
Choose a base branch
from
slyngshede:apple
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+206
−0
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7bf5fc8
Parser for Apple peering notifications
slyngshede ce38adf
Parser for Apple peering notifications
slyngshede d4cadf8
Ensure that Blake parses
slyngshede a51e9be
Apple: Flake8 and DocStrings
slyngshede 4b383e7
Apple: Fix blake error.
slyngshede 093855e
Apple: PyDocStyle fixes.
slyngshede File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import email | ||
import re | ||
|
||
from typing import Dict, List | ||
|
||
from circuit_maintenance_parser.output import Impact, Status | ||
from circuit_maintenance_parser.parser import EmailSubjectParser, Text, CircuitImpact | ||
|
||
class SubjectParserApple(EmailSubjectParser): | ||
def parser_hook(self, raw: bytes): | ||
message = email.message_from_string(self.bytes_to_string(raw)) | ||
return self.parse_subject(message['subject']) | ||
|
||
def parse_subject(self, subject: str) -> List[Dict]: | ||
return [{'summary': subject}] | ||
|
||
|
||
class TextParserApple(Text): | ||
def parse_text(self, text: str) -> List[Dict]: | ||
data = { | ||
'circuits': self._circuits(text), | ||
'maintenance_id': self._maintenance_id(text), | ||
'start': self._start_time(text), | ||
'end': self._end_time(text), | ||
'status': Status.CONFIRMED, # Have yet to see anything but confirmation. | ||
'organizer': '[email protected]', | ||
'provider': 'apple', | ||
} | ||
return [data] | ||
|
||
def _circuits(self, text): | ||
pattern = r'Peer AS: (\d*)' | ||
m = re.search(pattern, text) | ||
return [CircuitImpact( | ||
circuit_id=f'AS{m.group(1)}', | ||
impact=Impact.NO_IMPACT)] | ||
|
||
def _maintenance_id(self, text): | ||
# Apple ticket numbers always starts with "CHG". | ||
pattern = r'CHG(\d*)' | ||
m = re.search(pattern, text) | ||
return m.group(0) | ||
|
||
def _get_time(self, pattern, text): | ||
# Apple sends timestamps as RFC2822, misused | ||
# email module to convert to datetime. | ||
m = re.search(pattern, text) | ||
rfc2822 = m.group(1) | ||
time_tuple = email.utils.parsedate_tz(rfc2822) | ||
return email.utils.mktime_tz(time_tuple) | ||
|
||
def _start_time(self, text): | ||
pattern = 'Start Time: ([a-zA-Z0-9 :]*)' | ||
return self._get_time(pattern, text) | ||
|
||
def _end_time(self, text): | ||
pattern = 'End Time: ([a-zA-Z0-9 :]*)' | ||
return self._get_time(pattern, text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
from circuit_maintenance_parser.processor import CombinedProcessor, SimpleProcessor, GenericProcessor | ||
from circuit_maintenance_parser.constants import EMAIL_HEADER_SUBJECT | ||
|
||
from circuit_maintenance_parser.parsers.apple import SubjectParserApple, TextParserApple | ||
from circuit_maintenance_parser.parsers.aquacomms import HtmlParserAquaComms1, SubjectParserAquaComms1 | ||
from circuit_maintenance_parser.parsers.aws import SubjectParserAWS1, TextParserAWS1 | ||
from circuit_maintenance_parser.parsers.bso import HtmlParserBSO1 | ||
|
@@ -164,6 +165,14 @@ def get_provider_type(cls) -> str: | |
# PROVIDERS # | ||
#################### | ||
|
||
class Apple(GenericProvider): | ||
"""Apple provider custom class.""" | ||
|
||
_processors: List[GenericProcessor] = [ | ||
CombinedProcessor(data_parsers=[TextParserApple, SubjectParserApple]), | ||
] | ||
_default_organizer = "[email protected]" | ||
|
||
|
||
class AquaComms(GenericProvider): | ||
"""AquaComms provider custom class.""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Date-warning: Date header was inserted by rn-mailsvcp-relay-lapp01.rno.apple.com | ||
Date: Mon, 01 May 2023 10:38:11 -0700 (PDT) | ||
Message-id: <[email protected]> | ||
Received: from prz3-cstools-hyp001.corp.apple.com | ||
(prz3-cstools-hyp001.corp.apple.com [10.35.7.133]) | ||
by csmail.corp.apple.com (Postfix) with ESMTP id 1E23115EDE4; Mon, | ||
1 May 2023 17:38:11 +0000 (UTC) | ||
Content-type: multipart/mixed; boundary="===============1255676001481217459==" | ||
MIME-version: 1.0 | ||
From: [email protected] | ||
Subject: Apple (AS714) Net Maintenance Notice for AS12345 in Chicago | ||
To: recipients not specified: ; | ||
|
||
--===============1255676001481217459== | ||
Content-Type: text/plain; charset="us-ascii" | ||
MIME-Version: 1.0 | ||
Content-Transfer-Encoding: 7bit | ||
|
||
Apple (AS714) Network Maintenance Notification | ||
Reference Internal Ticket: CHG000123456 | ||
Message sent to: [email protected] | ||
|
||
Details: | ||
Start Time: 2 May 2023 14:00 UTC | ||
End Time: 16 May 2023 23:59 UTC | ||
|
||
Peering Details: | ||
Apple AS: 714 | ||
Peer AS: 12345 | ||
|
||
|
||
Apple IP: ['10.0.0.1', '2000:0000:0000:0000:0000:0000:0000:0001'] | ||
Peer IP: ['10.0.0.2', '2000:0000:0000:0000:0000:0000:0000:0002'] | ||
|
||
There is no change required on your end as we will gracefully drain the traffic prior to maintenance. | ||
|
||
When the maintenance is completed, Apple will automatically re-route traffic back. | ||
For reference, our current max prefix setting recommendation is: IPv4 = 10000 and IPv6 = 1000. | ||
Questions about this event can be sent to [email protected]. | ||
|
||
Thank you for peering with Apple! | ||
|
||
Regards, | ||
|
||
Apple Peering NOC (AS714) | ||
[email protected] | ||
as714.peeringdb.com | ||
|
||
--===============1255676001481217459==-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[ | ||
{ | ||
"circuits": [ | ||
{ | ||
"circuit_id": "AS12345", | ||
"impact": "OUTAGE" | ||
} | ||
], | ||
"end": 1684281540, | ||
"maintenance_id": "CHG000123456", | ||
"start": 1683036000, | ||
"status": "CONFIRMED", | ||
"summary": "Apple (AS714) Net Maintenance Notice for AS12345 in Chicago", | ||
"organizer": "[email protected]", | ||
"provider": "apple" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[ | ||
{ | ||
"circuits": [ | ||
{ | ||
"circuit_id": "AS12345", | ||
"impact": "NO-IMPACT" | ||
} | ||
], | ||
"end": 1684281540, | ||
"maintenance_id": "CHG000123456", | ||
"start": 1683036000, | ||
"status": "CONFIRMED", | ||
"organizer": "[email protected]", | ||
"provider": "apple" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ | ||
{ | ||
"summary": "Apple (AS714) Net Maintenance Notice for AS12345 in Chicago" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you would like to mark the circuit state during the maintenance as OUTAGE? NO_IMPACT is supposed for a circuit that it's not being affected during the maintenance period