Skip to content

Commit 6d9eb7a

Browse files
authored
Merge pull request #116 from pke11y/colt-subject
Colt parsing updates
2 parents 89b180a + 893cf37 commit 6d9eb7a

File tree

12 files changed

+418
-11
lines changed

12 files changed

+418
-11
lines changed

circuit_maintenance_parser/parsers/colt.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def parse_csv(raw):
3333

3434

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

3838
def parse_subject(self, subject):
3939
"""Parse subject.
@@ -44,18 +44,46 @@ def parse_subject(self, subject):
4444
"""
4545
data = {}
4646
search = re.search(
47-
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]+)",
47+
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]+)",
4848
subject,
4949
)
5050
if search:
5151
data["maintenance_id"] = search.group(2)
5252
data["start"] = self.dt2ts(parser.parse(search.group(3)))
5353
data["end"] = self.dt2ts(parser.parse(search.group(4)))
54-
if search.group(5) == "START":
54+
status = search.group(5).strip()
55+
if status == "START":
5556
data["status"] = Status("IN-PROCESS")
56-
elif search.group(5) == "COMPLETED":
57+
elif status == "COMPLETED":
5758
data["status"] = Status("COMPLETED")
5859
else:
5960
data["status"] = Status("CONFIRMED")
60-
data["summary"] = subject
61+
data["summary"] = search.group(1).strip()
62+
return [data]
63+
64+
65+
class SubjectParserColt2(EmailSubjectParser):
66+
"""Subject parser for Colt notifications - type 2."""
67+
68+
def parse_subject(self, subject):
69+
r"""Parse subject.
70+
71+
Example:
72+
- [ 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
73+
- [ 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
74+
"""
75+
data = {}
76+
search = re.search(
77+
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]+).+",
78+
subject,
79+
)
80+
if search:
81+
if search.group(1).upper() == "CANCELLATION":
82+
data["status"] = Status("CANCELLED")
83+
else:
84+
data["status"] = Status("CONFIRMED")
85+
data["maintenance_id"] = search.group(3)
86+
data["start"] = self.dt2ts(parser.parse(search.group(4)))
87+
data["end"] = self.dt2ts(parser.parse(search.group(5)))
88+
data["summary"] = search.group(2).strip()
6189
return [data]

circuit_maintenance_parser/provider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from circuit_maintenance_parser.parsers.aquacomms import HtmlParserAquaComms1, SubjectParserAquaComms1
2020
from circuit_maintenance_parser.parsers.aws import SubjectParserAWS1, TextParserAWS1
2121
from circuit_maintenance_parser.parsers.cogent import HtmlParserCogent1
22-
from circuit_maintenance_parser.parsers.colt import CsvParserColt1, SubjectParserColt1
22+
from circuit_maintenance_parser.parsers.colt import CsvParserColt1, SubjectParserColt1, SubjectParserColt2
2323
from circuit_maintenance_parser.parsers.equinix import HtmlParserEquinix, SubjectParserEquinix
2424
from circuit_maintenance_parser.parsers.gtt import HtmlParserGTT1
2525
from circuit_maintenance_parser.parsers.hgc import HtmlParserHGC1, HtmlParserHGC2, SubjectParserHGC1
@@ -194,6 +194,7 @@ class Colt(GenericProvider):
194194

195195
_processors: List[GenericProcessor] = [
196196
CombinedProcessor(data_parsers=[EmailDateParser, CsvParserColt1, SubjectParserColt1]),
197+
CombinedProcessor(data_parsers=[EmailDateParser, CsvParserColt1, SubjectParserColt2]),
197198
]
198199
_default_organizer = "[email protected]"
199200

tests/unit/data/colt/colt1_result.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
"stamp": 1627653788,
88
"start": 1628283600,
99
"status": "CONFIRMED",
10-
"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"
10+
"summary": "Service Affecting Maintenance Notification"
1111
}
1212
]

tests/unit/data/colt/colt3_result.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
"stamp": 1630760572,
1414
"start": 1623189600,
1515
"status": "CONFIRMED",
16-
"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"
16+
"summary": "Service Affecting Maintenance Notification"
1717
}
1818
]

tests/unit/data/colt/colt4.eml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
MIME-Version: 1.0
22
Date: Mon, 1 Nov 2021 11:51:41 +0000
3-
Subject: [ EXTERNAL ] MAINTENANCE ALERT: CRQ1-12345678 31/10/2021 00:00:00 GMT - 31/10/2021 07:30:00 GMT - COMPLETED
43
From: Maintenance Request <[email protected]>
54
To: Maintenance Request <[email protected]>
65
Content-Type: multipart/mixed; boundary="000000000000e8c2b105cfb8cc38"
6+
Subject: [ EXTERNAL ] MAINTENANCE ALERT: CRQ1-12345678 31/10/2021 00:00:00 GMT - 31/10/2021 07:30:00 GMT - COMPLETED
77

88
--000000000000e8c2b105cfb8cc38
99
Content-Type: multipart/alternative; boundary="000000000000e8c2ae05cfb8cc36"

tests/unit/data/colt/colt4_result.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
"stamp": 1635767501,
1414
"start": 1635638400,
1515
"status": "COMPLETED",
16-
"summary": "[ EXTERNAL ] MAINTENANCE ALERT: CRQ1-12345678 31/10/2021 00:00:00 GMT - 31/10/2021 07:30:00 GMT - COMPLETED"
16+
"summary": "MAINTENANCE ALERT"
1717
}
1818
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
{
3+
"end": 1635665400,
4+
"maintenance_id": "CRQ1-12345678",
5+
"start": 1635638400,
6+
"status": "COMPLETED",
7+
"summary": "MAINTENANCE ALERT"
8+
}
9+
]

0 commit comments

Comments
 (0)