curl, then how to automate it with a small script on a Linux VM.
How it works
Two API calls are all you need:- List alerts (
GET /api/v1/alerts) withstart_idset to one more than the last alert ID you have seen. Only alerts newer than that are returned. - Get an alert (
GET /api/v1/alerts/{id}) for each new alert, to get the alert reason, GenAI Triage result, screenshots and the changes detected.
Before you begin
You will need:- An API token. Generate one in the portal under Account → Manage Credentials.
- A Linux VM with Python 3.9 or later and outbound HTTPS (port 443) to
api.monitor.weborion.io. Python 3 comes preinstalled on Ubuntu 24.04 and Amazon Linux 2023. The VM used for Scheduled Rebaseline works fine.
Try it by hand
Set your token for this terminal session:1. List recent alerts
The first time, there is no last alert ID yet, so list alerts from a point in time instead. This lists alerts from the last 60 minutes. Times are in UTC.data gives the alert ID, the webpage and when the change was detected:
last_page is more than 1, repeat the request with -d page=2, -d page=3 and so on until you reach it.
2. List only new alerts
Note the highestid you received, 1048214 in the example above. To get only alerts newer than that, pass one more than it as start_id:
data list means there are no new alerts.
3. Get the details of an alert
For each new alert, request its details by ID:An alert can appear in the list a little before its details are ready. If Get an alert does not return the details yet, try again a minute later.
Automate it
The script below runs the same steps every minute. It remembers the last alert ID it handled and passes each new alert to a function calledhandle_alert(). By default, that function adds the alert to a file as one line of JSON.
The script also keeps things gentle on the API and safe for whatever receives the alerts:
- One list request per minute when there is nothing new, and a detail request only for each new alert.
- At most 100 alerts per run, with a short pause between requests. If more are waiting, for example after the VM was offline, they are picked up over the next few runs, oldest first.
- Each alert is handled once. The script saves its progress after every run, including runs that stop part way.
- No alert is dropped. Alerts whose details aren’t ready are retried each minute for 30 minutes. After that, they are passed on with the basic information and
details_availableset tofalse. - Errors stop the run quietly. If the API rate limit is reached or the network is down, the script stops and continues on the next run.
1. Prepare the VM
Create a service user and the folders the script needs:On Amazon Linux 2023, cron is not installed by default. Run
sudo dnf install -y cronie and then sudo systemctl enable --now crond.2. Store the API token
3. Save the script
Paste this whole block into your terminal. It saves the script to/opt/weborion/check_alerts.py as root, makes it owned by root so the service user can run it but not change it, and checks that the file was pasted cleanly:
check_alerts.py OK, the whole script was pasted correctly. If you see an error or nothing at all, paste the block again. Then do a test run as the service user:
handled 3 alerts, 0 waiting for details, last alert ID 1048214, or nothing if there were no alerts.
4. Run it every minute
Add a cron entry.flock makes sure a new run never starts while the previous one is still going.
check_alerts.log when it handled an alert or something went wrong, so the log stays small.
5. Check that it works
After a few minutes, look at the log and the latest alert:Changing what happens to each alert
handle_alert() is the only part of the script you need to change. It receives each new alert in the same format as the Get an alert response, plus a details_available field. The script is owned by root, so open it with sudo, for example sudo vim /opt/weborion/check_alerts.py.
For example, to keep the file and also post HIGH severity alerts to a Slack incoming webhook, add WEBORION_WEBHOOK_URL=https://hooks.slack.com/services/... to /etc/weborion/alerts.env and replace handle_alert() with:
Use cases
Once new alerts land in a file, or pass throughhandle_alert(), you can send them wherever your team works.
| Use case | How to set it up |
|---|---|
| SIEM, such as Splunk, Elastic, Microsoft Sentinel, QRadar or Google SecOps | Point your SIEM’s log collection agent at /var/log/weborion/alerts.ndjson. Each line is one complete JSON alert. Use the alert id to remove duplicates. |
| Central logging | Have rsyslog, Fluent Bit or Vector read the same file and forward it to your logging platform. |
| Chat notifications | Post alerts to Slack, Microsoft Teams or similar from handle_alert(), as in the example above. |
| Ticketing | Create an incident in Jira fromhandle_alert(). Grouping by webpage avoids one ticket per alert. |
| On-call paging | Send HIGH severity alerts to PagerDuty, using the alert id as the dedupe key. |
| Long-term archive | Copy the rotated files to object storage, such as Amazon S3, for audit and reporting. |
sudo usermod -aG weborion splunkfwd, and restart the agent.
Troubleshooting
| Symptom | Likely cause |
|---|---|
The API rejected the token | The token is wrong, expired or revoked. Generate a new one under Account → Manage Credentials and update /etc/weborion/alerts.env. |
The API rate limit was reached | Can happen while catching up on many alerts. The script continues on the next run. If it happens often, lower WEBORION_MAX_ALERTS_PER_RUN. |
Alerts with details_available set to false | The alert details weren’t ready within the retry window. Open the alert in the portal, or raise WEBORION_RETRY_MINUTES. |
| Nothing happens at all | Check that cron is running (systemctl status cron, or crond on Amazon Linux) and that /var/lib/weborion-alerts is owned by weborion. |
/var/lib/weborion-alerts/state.json. The next run picks up the last 60 minutes of alerts again, so some may be handled twice.
For anything else, contact CloudsineAI support.