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

Colt parsing updates #116

Merged
merged 2 commits into from
Nov 26, 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
38 changes: 33 additions & 5 deletions circuit_maintenance_parser/parsers/colt.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def parse_csv(raw):


class SubjectParserColt1(EmailSubjectParser):
"""Subject parser for Colt notifications."""
"""Subject parser for Colt notifications - type 1."""

def parse_subject(self, subject):
"""Parse subject.
Expand All @@ -44,18 +44,46 @@ def parse_subject(self, subject):
"""
data = {}
search = re.search(
r"\[.+\](.+).+?(CRQ\w+-\w+).+?(\d+/\d+/\d+\s\d+:\d+:\d+\s[A-Z]+).+?(\d+/\d+/\d+\s\d+:\d+:\d+\s[A-Z]+).+?([A-Z]+)",
r"\[.+\]\s([A-Za-z\s]+).+?(CRQ\w+-\w+)\s(\d+/\d+/\d+\s\d+:\d+:\d+\s+[A-Z]+).+?(\d+/\d+/\d+\s\d+:\d+:\d+\s+[A-Z]+).+?([A-Z]+)",
subject,
)
if search:
data["maintenance_id"] = search.group(2)
data["start"] = self.dt2ts(parser.parse(search.group(3)))
data["end"] = self.dt2ts(parser.parse(search.group(4)))
if search.group(5) == "START":
status = search.group(5).strip()
if status == "START":
data["status"] = Status("IN-PROCESS")
elif search.group(5) == "COMPLETED":
elif status == "COMPLETED":
data["status"] = Status("COMPLETED")
else:
data["status"] = Status("CONFIRMED")
data["summary"] = subject
data["summary"] = search.group(1).strip()
return [data]


class SubjectParserColt2(EmailSubjectParser):
"""Subject parser for Colt notifications - type 2."""

def parse_subject(self, subject):
r"""Parse subject.

Example:
- [ EXTERNAL ] Cancellation Colt Third Party Maintenance Notification -\n CRQ1-12345678 [07/12/2021 23:00:00 GMT - 08/12/2021 05:00:00 GMT] for\n ACME, 123456
- [ EXTERNAL ] Colt Third Party Maintenance Notification -\n CRQ1-48926339503 [07/12/2021 23:00:00 GMT - 08/12/2021 05:00:00 GMT] for\n ACME, 123456
"""
data = {}
search = re.search(
r"\[.+\]\s+([A-Za-z]+)\s+([\w\s]+)[\s-]+?(CRQ\w+-\w+).+?(\d+/\d+/\d+\s\d+:\d+:\d+\s+[A-Z]+).+?(\d+/\d+/\d+\s\d+:\d+:\d+\s[A-Z]+).+",
subject,
)
if search:
if search.group(1).upper() == "CANCELLATION":
data["status"] = Status("CANCELLED")
else:
data["status"] = Status("CONFIRMED")
data["maintenance_id"] = search.group(3)
data["start"] = self.dt2ts(parser.parse(search.group(4)))
data["end"] = self.dt2ts(parser.parse(search.group(5)))
data["summary"] = search.group(2).strip()
return [data]
3 changes: 2 additions & 1 deletion circuit_maintenance_parser/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from circuit_maintenance_parser.parsers.aquacomms import HtmlParserAquaComms1, SubjectParserAquaComms1
from circuit_maintenance_parser.parsers.aws import SubjectParserAWS1, TextParserAWS1
from circuit_maintenance_parser.parsers.cogent import HtmlParserCogent1
from circuit_maintenance_parser.parsers.colt import CsvParserColt1, SubjectParserColt1
from circuit_maintenance_parser.parsers.colt import CsvParserColt1, SubjectParserColt1, SubjectParserColt2
from circuit_maintenance_parser.parsers.equinix import HtmlParserEquinix, SubjectParserEquinix
from circuit_maintenance_parser.parsers.gtt import HtmlParserGTT1
from circuit_maintenance_parser.parsers.hgc import HtmlParserHGC1, HtmlParserHGC2, SubjectParserHGC1
Expand Down Expand Up @@ -194,6 +194,7 @@ class Colt(GenericProvider):

_processors: List[GenericProcessor] = [
CombinedProcessor(data_parsers=[EmailDateParser, CsvParserColt1, SubjectParserColt1]),
CombinedProcessor(data_parsers=[EmailDateParser, CsvParserColt1, SubjectParserColt2]),
]
_default_organizer = "[email protected]"

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/data/colt/colt1_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"stamp": 1627653788,
"start": 1628283600,
"status": "CONFIRMED",
"summary": "[ EXTERNAL ] Colt Service Affecting Maintenance Notification - CRQ1-12345678 [06/8/2021 22:00:00 GMT - 07/8/2021 06:00:00 GMT] for ACME, 12345000"
"summary": "Service Affecting Maintenance Notification"
}
]
2 changes: 1 addition & 1 deletion tests/unit/data/colt/colt3_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"stamp": 1630760572,
"start": 1623189600,
"status": "CONFIRMED",
"summary": "[ EXTERNAL ] Colt Service Affecting Maintenance Notification - CRQ1-12345678 [06/8/2021 22:00:00 GMT - 07/8/2021 06:00:00 GMT] for ACME, 12345000"
"summary": "Service Affecting Maintenance Notification"
}
]
2 changes: 1 addition & 1 deletion tests/unit/data/colt/colt4.eml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
MIME-Version: 1.0
Date: Mon, 1 Nov 2021 11:51:41 +0000
Subject: [ EXTERNAL ] MAINTENANCE ALERT: CRQ1-12345678 31/10/2021 00:00:00 GMT - 31/10/2021 07:30:00 GMT - COMPLETED
From: Maintenance Request <[email protected]>
To: Maintenance Request <[email protected]>
Content-Type: multipart/mixed; boundary="000000000000e8c2b105cfb8cc38"
Subject: [ EXTERNAL ] MAINTENANCE ALERT: CRQ1-12345678 31/10/2021 00:00:00 GMT - 31/10/2021 07:30:00 GMT - COMPLETED

--000000000000e8c2b105cfb8cc38
Content-Type: multipart/alternative; boundary="000000000000e8c2ae05cfb8cc36"
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/data/colt/colt4_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"stamp": 1635767501,
"start": 1635638400,
"status": "COMPLETED",
"summary": "[ EXTERNAL ] MAINTENANCE ALERT: CRQ1-12345678 31/10/2021 00:00:00 GMT - 31/10/2021 07:30:00 GMT - COMPLETED"
"summary": "MAINTENANCE ALERT"
}
]
9 changes: 9 additions & 0 deletions tests/unit/data/colt/colt4_subject_parser_1_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"end": 1635665400,
"maintenance_id": "CRQ1-12345678",
"start": 1635638400,
"status": "COMPLETED",
"summary": "MAINTENANCE ALERT"
}
]
Loading