Skip to main content

Custom Alerts API

Overview​

The Custom Alerts API allows you to send alerts from any source to OpsiMate via HTTP requests. This webhook integration enables you to integrate custom monitoring tools, scripts, or third-party services that aren't natively supported. Alerts are fired and resolved through the same endpoint, and resolved alerts can be permanently deleted.

Getting Started​

To start sending alerts, you'll need an API token. The default token is:

opsimate

Authentication​

All requests require the API token, for example as a query parameter:

?api_token=opsimate
Where the API token comes from
  • With a config file (CONFIG_FILE points to an existing file): the token is security.api_token in config.yml, and the API_TOKEN environment variable is ignored. The shipped docker-compose.yml, the Helm chart and the all-in-one image all run this way. With docker-compose.yml and the all-in-one image, the default-config.yml they start from sets it to opsimate. The Helm chart's config.configYml does not set it, and its API_TOKEN secret is ignored, so on Helm add api_token under security in config.configYml.
  • Without a config file: the token comes from the API_TOKEN environment variable, and falls back to opsimate.

Change the default for anything that is not a demo. See Configuration.

Send the token in any of these ways:

  • the api_token query parameter: ?api_token=YOUR_TOKEN
  • the X-API-Token header: X-API-Token: YOUR_TOKEN
  • the Authorization header: Authorization: Bearer YOUR_TOKEN

Endpoints​

Fire an Alert​

POST /api/v1/alerts/custom?api_token=YOUR_TOKEN

Creates a new alert or updates an existing one if the id already exists.

Request Body:

{
"id": "alert-123",
"alertName": "High CPU Usage",
"tags": {
"service": "api-server",
"environment": "production"
},
"severity": "critical",
"team": "platform",
"summary": "CPU usage exceeded 90% threshold",
"startsAt": "2024-01-15T10:30:00Z",
"updatedAt": "2024-01-15T10:35:00Z",
"links": [
{ "label": "Source", "url": "https://monitoring.example.com/alerts/123" },
{ "label": "Runbook", "url": "https://wiki.example.com/runbooks/high-cpu" }
]
}

cURL Example:

curl -X POST "https://your-opsimate-instance.com/api/v1/alerts/custom?api_token=opsimate" \
-H "Content-Type: application/json" \
-d '{
"id": "alert-123",
"alertName": "High CPU Usage",
"tags": {
"service": "api-server"
},
"severity": "critical",
"links": [
{ "label": "Source", "url": "https://monitoring.example.com/alerts/123" }
]
}'

Resolve an Alert​

POST /api/v1/alerts/custom?api_token=YOUR_TOKEN

To resolve an alert, POST the same id with "status": "resolved". A body with only id and status is enough:

{
"id": "alert-123",
"status": "resolved"
}
  • Re-sending a resolve is safe: an unknown or already-resolved id is not an error.
  • endsAt sets the resolve time. It defaults to now.
  • If you send the full alert (alertName, tags, ...) with "status": "resolved" for an alert OpsiMate never saw firing, OpsiMate still records that episode, so the incident isn't lost.

cURL Example:

curl -X POST "https://your-opsimate-instance.com/api/v1/alerts/custom?api_token=opsimate" \
-H "Content-Type: application/json" \
-d '{
"id": "alert-123",
"status": "resolved",
"endsAt": "2024-01-15T11:00:00Z"
}'

Resolve with the full alert​

You can also send the full alert with "status": "resolved". It counts as full when it would be a valid firing alert, so it needs alertName and tags. If the alert is firing, the fields you send update it as it moves to the resolved alerts, so the Resolved list shows what your source said last:

{
"id": "alert-123",
"status": "resolved",
"alertName": "High CPU Usage",
"tags": {
"service": "api-server"
},
"severity": "info",
"summary": "Recovered: CPU back under 60%"
}

After this request, the resolved alert shows severity info and the summary "Recovered: CPU back under 60%".

  • These fields are updated when sent: alertName, summary, severity, team, tags, links, and the deprecated alertUrl and runbookUrl.
  • A field you leave out keeps its stored value. A resolve can't blank the summary or reset the severity to the default.
  • tags replaces the stored tags as a whole. The fix and team tags are kept unless the resolve sends one.
  • startsAt, the owner and the silence state never change on a resolve. endsAt still sets the resolve time.
  • A body with only id and status (or one that is missing alertName or tags) resolves the alert and changes nothing else.

Resolve an Alert with DELETE (deprecated for senders)​

DELETE /api/v1/alerts/:alertId?api_token=YOUR_TOKEN

This is the manual Resolve the OpsiMate UI uses. It moves an active alert to the resolved alerts. It accepts an optional JSON body with a resolve note:

{
"comment": "Fixed by restarting the service"
}

Senders should use Resolve an Alert (POST with "status": "resolved") instead.

cURL Example:

curl -X DELETE "https://your-opsimate-instance.com/api/v1/alerts/alert-123?api_token=opsimate"

Permanently Delete a Resolved Alert​

DELETE /api/v1/alerts/resolved/:alertId?api_token=YOUR_TOKEN

Permanently removes a resolved alert from the system. This action is irreversible.

cURL Example:

curl -X DELETE "https://your-opsimate-instance.com/api/v1/alerts/resolved/alert-123?api_token=opsimate"

Response Format​

Alert fired:

{
"success": true,
"data": {
"alertId": "alert-123",
"status": "firing"
}
}

Alert resolved:

{
"success": true,
"data": {
"alertId": "alert-123",
"status": "resolved",
"resolved": true,
"created": false
}
}

resolved is true when a firing alert was resolved by this request. created is true when the alert wasn't firing in OpsiMate but you sent the full alert, so its fired-and-resolved episode was recorded. Both are false when there was nothing to do (an unknown or already-resolved id).

Validation error (HTTP 400):

{
"success": false,
"error": "Validation error",
"details": [
{
"expected": "string",
"code": "invalid_type",
"path": ["alertName"],
"message": "Invalid input: expected string, received undefined"
}
]
}

Invalid API token (HTTP 401):

{
"success": false,
"error": "Invalid API token"
}

Field Reference​

Field NameTypeRequiredDescription
idstringRequiredUnique identifier for the alert
alertNamestringRequiredDisplay name of the alert. Not needed to resolve.
tagsobject (string → string)RequiredKey-value pairs for categorization and filtering. Not needed to resolve.
statusstringOptional"resolved" resolves the alert. Anything else, or no value, fires it. With "resolved" and the full alert, the other fields you send update the stored alert. See Resolve with the full alert.
summarystringOptionalDetailed description of the alert
startsAtstringOptionalISO 8601 timestamp when the alert started
updatedAtstringOptionalISO 8601 timestamp of the last update
endsAtstringOptionalISO 8601 timestamp when the alert ended. Only read with "status": "resolved". Defaults to now.
severitystringOptionalFree-form. Mapped onto critical, warning or info. Unknown or missing values become warning.
teamstringOptionalOwning team. Falls back to a team tag.
fixstringOptionalFix classification: manual or auto
linksarrayOptionalUp to 20 links, each { "label", "url", "icon"? }. icon is an optional integration icon name, such as grafana.
alertUrlstringOptionalDeprecated, use links. Still accepted, and shown as the "Source" link when links is absent.
runbookUrlstringOptionalDeprecated, use links. Still accepted, and shown as the "Runbook" link when links is absent.
createdAtstringOptionalAccepted but currently not used

Best Practices​

  • Use consistent id formats across your monitoring sources
  • Include meaningful tags for filtering and grouping
  • Add a runbook to links for operational efficiency
  • Use ISO 8601 format for all timestamps
  • Resolve alerts by POSTing "status": "resolved" when your source recovers, to keep the active alert view clean