Skip to content

Commit

Permalink
Merge pull request #118 from networktocode/release-v2.0.6
Browse files Browse the repository at this point in the history
Release v2.0.6
  • Loading branch information
chadell authored Nov 29, 2021
2 parents a25fad5 + 825a498 commit 8d6e825
Show file tree
Hide file tree
Showing 17 changed files with 573 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## v2.0.6 - 2021-11-30

### Added

- #116 - New `EmailSubjectParser` for Colt notifications and tests.
- #117 - Add new notification status of `Alternate Night` for Lumen.

## v2.0.5 - 2021-11-18

### Fixed
Expand Down
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]
2 changes: 2 additions & 0 deletions circuit_maintenance_parser/parsers/lumen.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def parse_tables(self, tables: ResultSet, data: Dict):
data["status"] = Status("RE-SCHEDULED")
elif status_string == "Not Completed":
data["status"] = Status("CANCELLED")
elif status_string == "Alternate Night":
data["status"] = Status("RE-SCHEDULED")
elif "status" not in data:
# Update to an existing ticket may not include an update to the status - make a guess
data["status"] = "CONFIRMED"
Expand Down
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 pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "circuit-maintenance-parser"
version = "2.0.5"
version = "2.0.6"
description = "Python library to parse Circuit Maintenance notifications and return a structured data back"
authors = ["Network to Code <[email protected]>"]
license = "Apache-2.0"
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

0 comments on commit 8d6e825

Please sign in to comment.