Overview

Send Monit alerts to Callgoose SQIBS. Monit's exec action runs a small script that posts the event to your SQIBS API endpoint, once when a check fails and once when it succeeds again. SQIBS opens an incident on the failure and resolves it on the recovery.

You need
Monit 5.x on the host, curl, and a SQIBS API token
Setup time
About 15 minutes
Result
Monit failures open SQIBS incidents; recoveries resolve them

How it works

Monit
Alert fires
A check fails (process, port, disk, and so on).
Monit
Sends a webhook
The exec action runs a script that posts JSON.
SQIBS
API filter matches
The filter decides whether to open or resolve, and the priority.
SQIBS
Incident opens
firing opens it, resolved closes it.

Want SQIBS to fix known issues before anyone is paged? See Fix known issues automatically.

Step 1: Add the API filter in SQIBS

  1. In SQIBS, open Services, choose the service that should receive these incidents, and click Add Or Update API Integration.
  2. Add a filter with these values (there is no built-in Monit template yet, so enter them by hand):
Part Payload JSON key Key value contains What it does
Trigger "status" firing Opens an incident.
Resolve "status" resolved Resolves the open incident.
Match "alert_key" Host/service: ties the recovery to its failure.
Title from "description" Becomes the incident title.
  1. Choose the Priority for these incidents and click Save.

Not sure of a key? Send one test message first (step below), then build the filter from the real payload.

Find the right key with the JSON key creator
In the API Integration window, click the round {} button at the bottom right. Paste a payload that SQIBS received (copy it from the API log). SQIBS lists every key with its value, each with a copy button. Copy the key into Payload JSON key and the value into Key value contains. No need to read the JSON by hand.

Step 2: Add the script

Save this script as /usr/local/bin/monit-to-callgoose, put in your endpoint and token, and make it executable (chmod 750):

#!/bin/bash
# /usr/local/bin/monit-to-callgoose  - Monit sets MONIT_SERVICE, MONIT_EVENT, MONIT_DESCRIPTION, MONIT_HOST.
# Usage in monitrc:  exec "/usr/local/bin/monit-to-callgoose firing"   /   exec "/usr/local/bin/monit-to-callgoose resolved"
URL="https://<your-endpoint>/sqibs-api/v1/process?from=monit&token=<your-token>"
esc() { printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g' | tr '\n\r\t' '   '; }
curl -s -m 20 -X POST "$URL" -H 'Content-Type: application/json' --data-binary @- <<EOF
{
  "status": "$1",
  "alert_key": "$(esc "$MONIT_HOST/$MONIT_SERVICE")",
  "service": "$(esc "$MONIT_SERVICE")",
  "event": "$(esc "$MONIT_EVENT")",
  "description": "$(esc "$MONIT_DESCRIPTION")",
  "host": "$(esc "$MONIT_HOST")"
}
EOF

Replace <your-endpoint> and <your-token> with the values from your SQIBS account. See how to get the endpoint URL and API tokens.

Step 3: Call it from your checks

In /etc/monit/monitrc (or a file under /etc/monit/conf.d/), add exec actions with an else if succeeded branch so the recovery is sent too:

check process nginx with pidfile /run/nginx.pid
  start program = "/usr/bin/systemctl start nginx"
  stop program  = "/usr/bin/systemctl stop nginx"
  if failed port 80 protocol http for 2 cycles
    then exec "/usr/local/bin/monit-to-callgoose firing"
    else if succeeded then exec "/usr/local/bin/monit-to-callgoose resolved"

check filesystem rootfs with path /
  if space usage > 90% then exec "/usr/local/bin/monit-to-callgoose firing"
    else if succeeded then exec "/usr/local/bin/monit-to-callgoose resolved"

Check and reload: monit -t && monit reload.

Step 4: Test it

The API log saves payloads only while API Tracking is on for the token. Turn it on under API Tokens before you test; it switches itself off after 48 hours.

  1. Stop the monitored service, for example systemctl stop nginx, and wait two Monit cycles.
  2. In SQIBS, a new incident opens, titled with Monit's description.
  3. Start the service again. Monit runs the script with resolved, and SQIBS resolves the incident.

No incident? Open the API log (with API Tracking on). If the payload is there, the filter did not match it: paste it into the JSON key creator and check the keys. If it is not there, check the URL and token in the script (run it by hand with the MONIT_* variables set).

Fix known issues automatically

Many alerts have a known fix: restart a service, clear a full disk, run a health check. SQIBS can run that fix for you the moment the incident opens. This is event-driven auto remediation. Monit can restart a process itself; SQIBS adds the rest. For example, when Monit reports the disk almost full, SQIBS can run a workflow that clears old logs and archives, then rechecks the space.

Incident opens
Workflow starts
SQIBS runs the automation workflow linked to the filter.
Fixed
Incident resolved
The issue is fixed before anyone has to step in.
Not fixed
Escalated to the engineer
After the waiting time you set, the escalation policy pages on-call as usual.

Safe by design. SQIBS runs only workflows your own engineers wrote and approved for your environment. Nothing is guessed or generated: the same steps an engineer would run by hand, run sooner. If the workflow does not fix the issue, the engineer is paged as usual.

To set it up, in the same API filter:

  1. Select Workflow: choose the automation workflow to run when this filter opens an incident.
  2. If success then make incident resolved: turn on to resolve the incident when the workflow succeeds.
  3. Waiting time for escalate to escalation policies: how many minutes to give the workflow before paging the on-call engineer.

Start with low-risk workflows, such as a health check, and add fixes as you come to trust them.

Learn more: