aastatus-to-discord/README.md
2025-11-17 12:34:27 +00:00

211 lines
3.7 KiB
Markdown

# 🛰️ AAISP Status Feed → Discord Webhook Notifier
Monitors the **Andrews & Arnold (AAISP)** status Atom feed and posts **new incidents, updates, and closures** to a Discord channel using a webhook.
This script:
* ✔ Detects new incidents
* ✔ Detects updates to existing incidents
* ✔ Detects severity changes
* ✔ Detects status changes (Open → Closed)
* ✔ Tracks each incident separately
* ✔ Sends color-coded Discord embeds
---
## 📌 Features
### 🔍 Intelligent Feed Monitoring
The script constantly fetches the official AAISP Atom feed:
```
https://aastatus.net/atom.cgi
```
It tracks each incident by ID and detects:
* New incidents
* Updated incidents
* Edited content
* Status changes
* Severity changes
* Updated timestamps
---
### 🎨 Color-Coded Notifications
The Discord embed color reflects the current **status** and **severity**
| Status / Severity | Colour | Meaning |
|------------------ | --------- | -------------------------|
| **Closed** | 🟩 Green | Issue resolved |
| **Open** | 🔵 Blue | Active incident |
| **Minor** | 🟨 Yellow | Low-impact issue |
| **MSO** | 🔴 Red | Major service outage |
| **PEW** | 🟦 Cyan | Planned engineering work |
| Default | ⚪ Grey | Unknown/other |
### 📦 Persistent State Tracking
Unlike simple "new entry only" scripts, this version uses:
```
/tmp/aaisp_atom_state.json
```
The state file stores:
```json
{
"<incident-id>": {
"status": "...",
"severity": "...",
"updated": "...",
"content": "..."
}
}
```
This allows the script to detect:
* “Open → Closed”
* Severity changes (Minor → MSO)
* New updates in the AAISP feed content
* Edits made to existing entries
---
### 📣 Clean Discord Notifications
Each message includes:
* Title with status/severity
* Full link to the AAISP page
* Markdown-formatted update content
* Timestamps
* Status, severity, and categories
Example:
```
[Closed] BT: Some BT lines dropped (Status changed Open → Closed)
```
---
## 🛠️ Installation
### 1. Clone or download the script
```
git clone https://git.ncltech.co.uk/phil/aastatus-to-discord
cd aastatus-to-discord
```
### 2. Install dependencies
```bash
pip install -r requirements.txt
```
Requirements:
* `requests`
### 3. Edit your Discord webhook URL
Open the script and set:
```python
WEBHOOK_URL = "https://discord.com/api/webhooks/XXXXXXX"
```
---
## 🚀 Running the Script
### Manual run:
```
python3 aastatus_to_discord.py
```
### Run automatically every 5 minutes (cron)
```
*/5 * * * * /usr/bin/python3 /path/to/aastatus_to_discord.py
```
State is preserved between runs because it stores incident data in:
```
/tmp/aaisp_atom_state.json
```
---
## 🔧 Configuration
If you want to override the state file path, edit:
```
STATE_FILE = Path("/tmp/aaisp_atom_state.json")
```
You can place it anywhere—e.g., `/var/lib/aaisp/state.json`.
---
## 🧪 Testing
You can simulate feed updates by:
* Editing timestamps in the XML
* Changing "Open" → "Closed"
* Adding a dummy category/status element
* Modifying content
The script will immediately detect the change and fire a Discord message.
---
## 🛡️ Error Handling & Logging
The script logs all operations:
* Feed fetch attempts
* Parsing failures
* State changes
* Discord webhook failures
Logs appear on stdout and are suitable for systemd or cron.
---
## ❤️ Contributing
Pull requests welcome!
Ideas to add:
* Support for multiple Discord channels
* HTML → Markdown improvements
* Option to track *all* entries, not just the newest
* A simple GUI or web dashboard
---
## 📜 License
GPL — free to modify and use.
---