Skip to main content
You can use the WebOrion Monitor API to check for new alerts once a minute and pull their full details, so they can go anywhere you need them: a SIEM, a logging platform, a chat channel or a ticketing system. This guide shows you how to do this by hand with curl, then how to automate it with a small script on a Linux VM.

How it works

Two API calls are all you need:
  1. List alerts (GET /api/v1/alerts) with start_id set to one more than the last alert ID you have seen. Only alerts newer than that are returned.
  2. 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.
After handling the new alerts, remember the highest alert ID. Next time, start from the one after it.

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.
The response is paginated. Each entry in data gives the alert ID, the webpage and when the change was detected:
If 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 highest id you received, 1048214 in the example above. To get only alerts newer than that, pass one more than it as start_id:
An empty data list means there are no new alerts.

3. Get the details of an alert

For each new alert, request its details by ID:
The response includes everything shown in the alert email and the portal. A shortened example:
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 called handle_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_available set to false.
  • 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

You can also add these optional settings to the same file:

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:
If the last line prints 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:
The first run picks up alerts from the last 60 minutes. It prints a line such as 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.
The script only writes to 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:
To keep the files from growing forever, rotate them with logrotate:

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:
Send only the alerts people need to act on, such as HIGH severity, to chat or paging tools, and keep the full record in the file. To reduce noisy alerts at the source, see Reducing False Positives and Auto Finetune.

Use cases

Once new alerts land in a file, or pass through handle_alert(), you can send them wherever your team works.
Use caseHow to set it up
SIEM, such as Splunk, Elastic, Microsoft Sentinel, QRadar or Google SecOpsPoint 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 loggingHave rsyslog, Fluent Bit or Vector read the same file and forward it to your logging platform.
Chat notificationsPost alerts to Slack, Microsoft Teams or similar from handle_alert(), as in the example above.
TicketingCreate an incident in Jira fromhandle_alert(). Grouping by webpage avoids one ticket per alert.
On-call pagingSend HIGH severity alerts to PagerDuty, using the alert id as the dedupe key.
Long-term archiveCopy the rotated files to object storage, such as Amazon S3, for audit and reporting.
If your log collection agent runs as its own user, give it read access to the file, for example sudo usermod -aG weborion splunkfwd, and restart the agent.

Troubleshooting

SymptomLikely cause
The API rejected the tokenThe 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 reachedCan 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 falseThe alert details weren’t ready within the retry window. Open the alert in the portal, or raise WEBORION_RETRY_MINUTES.
Nothing happens at allCheck that cron is running (systemctl status cron, or crond on Amazon Linux) and that /var/lib/weborion-alerts is owned by weborion.
To start again from scratch, delete /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.