Updated the script to fix and issue when a post was opened it woul post as colour blue instead of the colour of the severity
This commit is contained in:
parent
fcf99a87a1
commit
19bc33270e
@ -17,17 +17,11 @@ FEED_URL = "https://aastatus.net/atom.cgi"
|
|||||||
WEBHOOK_URL = "https://discord.com/api/webhooks/XXXXXXX" # Discord webhook URL
|
WEBHOOK_URL = "https://discord.com/api/webhooks/XXXXXXX" # Discord webhook URL
|
||||||
STATE_FILE = Path("/tmp/aaisp_atom_state.json")
|
STATE_FILE = Path("/tmp/aaisp_atom_state.json")
|
||||||
|
|
||||||
# Severity colors
|
# Event colors
|
||||||
COLOR_MINOR = 16763904
|
COLOR_MINOR_OPEN = 0xFFFF00 # yellow
|
||||||
COLOR_MSO = 16711680
|
COLOR_MAJOR_OPEN = 0xFF0000 # red
|
||||||
COLOR_PEW = 65535
|
COLOR_CLOSED = 0x2ECC71 # green
|
||||||
COLOR_DEFAULT = 3092790
|
COLOR_UNKNOWN = 0x95A5A6 # grey
|
||||||
|
|
||||||
# Status colors
|
|
||||||
COLOR_STATUS_OPEN = 0x3498DB # blue
|
|
||||||
COLOR_STATUS_CLOSED = 0x2ECC71 # green
|
|
||||||
COLOR_STATUS_UNKNOWN = 0x95A5A6 # grey
|
|
||||||
|
|
||||||
|
|
||||||
### STATE MANAGEMENT ###
|
### STATE MANAGEMENT ###
|
||||||
|
|
||||||
@ -65,7 +59,6 @@ def get_first_valid_entry(feed_xml):
|
|||||||
atom_ns = "{http://www.w3.org/2005/Atom}"
|
atom_ns = "{http://www.w3.org/2005/Atom}"
|
||||||
|
|
||||||
for entry in root.findall(f"{atom_ns}entry"):
|
for entry in root.findall(f"{atom_ns}entry"):
|
||||||
|
|
||||||
id_elem = entry.find(f"{atom_ns}id")
|
id_elem = entry.find(f"{atom_ns}id")
|
||||||
if id_elem is None:
|
if id_elem is None:
|
||||||
continue
|
continue
|
||||||
@ -142,19 +135,14 @@ def html_to_markdown(html_content):
|
|||||||
|
|
||||||
### COLOR LOGIC ###
|
### COLOR LOGIC ###
|
||||||
|
|
||||||
def get_embed_color(severity):
|
def get_event_color(status, severity):
|
||||||
return {
|
if status == "Closed":
|
||||||
"Minor": COLOR_MINOR,
|
return COLOR_CLOSED
|
||||||
"MSO": COLOR_MSO,
|
if status == "Open" and severity == "Minor":
|
||||||
"PEW": COLOR_PEW
|
return COLOR_MINOR_OPEN
|
||||||
}.get(severity, COLOR_DEFAULT)
|
if status == "Open" and severity in ("Major", "MSO", "PEW"):
|
||||||
|
return COLOR_MAJOR_OPEN
|
||||||
|
return COLOR_UNKNOWN
|
||||||
def get_status_color(status):
|
|
||||||
return {
|
|
||||||
"Open": COLOR_STATUS_OPEN,
|
|
||||||
"Closed": COLOR_STATUS_CLOSED
|
|
||||||
}.get(status, COLOR_STATUS_UNKNOWN)
|
|
||||||
|
|
||||||
|
|
||||||
### DISCORD FORMAT ###
|
### DISCORD FORMAT ###
|
||||||
@ -167,10 +155,7 @@ def build_discord_payload(entry, change_type="New entry"):
|
|||||||
except Exception:
|
except Exception:
|
||||||
updated_ts = entry["updated"]
|
updated_ts = entry["updated"]
|
||||||
|
|
||||||
# PRIORITY: Status color > Severity color
|
color = get_event_color(entry["status"], entry["severity"])
|
||||||
color = get_status_color(entry["status"])
|
|
||||||
if color == COLOR_STATUS_UNKNOWN:
|
|
||||||
color = get_embed_color(entry["severity"])
|
|
||||||
|
|
||||||
embed = {
|
embed = {
|
||||||
"title": f"{entry['title']} ({change_type})",
|
"title": f"{entry['title']} ({change_type})",
|
||||||
@ -224,21 +209,17 @@ def main():
|
|||||||
if prev is None:
|
if prev is None:
|
||||||
must_post = True
|
must_post = True
|
||||||
change_type = "New Incident Detected"
|
change_type = "New Incident Detected"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Compare important fields
|
# Compare important fields
|
||||||
if entry["status"] != prev.get("status"):
|
if entry["status"] != prev.get("status"):
|
||||||
must_post = True
|
must_post = True
|
||||||
change_type = f"Status changed: {prev.get('status')} → {entry['status']}"
|
change_type = f"Status changed: {prev.get('status')} → {entry['status']}"
|
||||||
|
|
||||||
elif entry["severity"] != prev.get("severity"):
|
elif entry["severity"] != prev.get("severity"):
|
||||||
must_post = True
|
must_post = True
|
||||||
change_type = f"Severity changed: {prev.get('severity')} → {entry['severity']}"
|
change_type = f"Severity changed: {prev.get('severity')} → {entry['severity']}"
|
||||||
|
|
||||||
elif entry["updated"] != prev.get("updated"):
|
elif entry["updated"] != prev.get("updated"):
|
||||||
must_post = True
|
must_post = True
|
||||||
change_type = "Feed updated"
|
change_type = "Feed updated"
|
||||||
|
|
||||||
elif entry["content"] != prev.get("content"):
|
elif entry["content"] != prev.get("content"):
|
||||||
must_post = True
|
must_post = True
|
||||||
change_type = "Content updated"
|
change_type = "Content updated"
|
||||||
@ -260,4 +241,3 @@ def main():
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user