Skip to main content

Service API: notifications

info
  • We're assuming your API key is set in the environment variable $KEY with the necessary permissions.
  • The notification-integrations endpoints require a key with notification-integrations scope (read).
  • The notification-rules endpoints require a key with notification-rules scope (read).
  • The notification-events endpoint requires a key with notification-events scope (read).
  • Otherwise the API returns 403 Forbidden.

The Console sends notifications through three kinds of objects:

  • A notification integration is a connection between your Organization and a messaging tool: slack, webhook, discord or email.
  • A notification rule decides which events trigger a notification, and sends it to one or more destinations. A destination points at an integration and holds where the message goes on that tool (a Slack or Discord channel, a webhook URL, a list of email addresses).
  • A notification event type is one of the events a rule can react to, such as a Security Engine going offline.
Read only

Notification integrations and rules are created, changed and deleted from the CrowdSec Console only (see Notification integrations and Notification rule). The Service API reads them, it cannot create or change them.

Notification integrationsโ€‹

Get Notification Integrationsโ€‹

List the notification integrations of your Organization

The optional integration_type query parameter filters on one or more integration types (slack, webhook, discord, email); repeat it to pass several values.

SH
curl -i -H "x-api-key: ${KEY}" -X GET -H "Content-Type: application/json" \
"https://admin.api.crowdsec.net/v1/notification-integrations?integration_type=slack&page=1&size=50"
answer on success
JSON
{
"items": [
{
"id": "string",
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"is_active": true,
"integration_type": "slack",
"rules_count": 2,
"token_type": "bot",
"scope": "string",
"bot_id": "string",
"bot_user_id": "string",
"team": "string",
"team_id": "string",
"enterprise_id": null,
"icon_url": "string"
}
],
"total": 0,
"page": 1,
"size": 1,
"pages": 0,
"links": {
"first": "/api/v1/users?limit=1&offset1",
"last": "/api/v1/users?limit=1&offset1",
"self": "/api/v1/users?limit=1&offset1",
"next": "/api/v1/users?limit=1&offset1",
"prev": "/api/v1/users?limit=1&offset1"
}
}

Every integration returns id, created_at, updated_at, is_active, integration_type and rules_count (the number of rules using it). The other fields depend on integration_type:

  • slack: token_type, scope, bot_id, bot_user_id, team, team_id, enterprise_id, icon_url. The Slack access token is never returned.
  • discord: guild_id, guild_name, icon_url.
  • webhook and email: no other field.

Get Notification Integrationโ€‹

Retrieve a single notification integration, using the id returned by Get Notification Integrations

SH
curl -i -H "x-api-key: ${KEY}" -X GET -H "Content-Type: application/json" \
https://admin.api.crowdsec.net/v1/notification-integrations/${INTEGRATION_ID}
answer on success
JSON
{
"id": "string",
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"is_active": true,
"integration_type": "discord",
"rules_count": 1,
"guild_id": "string",
"guild_name": "string",
"icon_url": "string"
}

An unknown integration_id returns 404 Not Found.

Notification rulesโ€‹

Get Notification Rulesโ€‹

List the notification rules of your Organization

Both query parameters are optional and can be repeated:

  • integration_id: only return the rules with a destination on one of these integrations.
  • integration_type: only return the rules with a destination of one of these types (slack, webhook, discord, email).
SH
curl -i -H "x-api-key: ${KEY}" -X GET -H "Content-Type: application/json" \
"https://admin.api.crowdsec.net/v1/notification-rules?integration_id=${INTEGRATION_ID}&page=1&size=50"
answer on success
JSON
{
"items": [
{
"id": "string",
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"name": "string",
"organization_id": "string",
"destinations": [
{
"id": "string",
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"integration_id": "string",
"failure_state": null,
"integration_type": "slack",
"channel_id": "string",
"channel_name": "string"
}
],
"description": "string",
"events": [
{
"name": "security_engine_offline"
}
],
"event_filter": {
"all_entities": false,
"entity_ids": [],
"tag_ids": [
"string"
],
"filter_type": "stack_monitoring"
}
}
],
"total": 0,
"page": 1,
"size": 1,
"pages": 0,
"links": {
"first": "/api/v1/users?limit=1&offset1",
"last": "/api/v1/users?limit=1&offset1",
"self": "/api/v1/users?limit=1&offset1",
"next": "/api/v1/users?limit=1&offset1",
"prev": "/api/v1/users?limit=1&offset1"
}
}

events lists the event types that trigger the rule. event_filter is optional and narrows which of those events are notified. Its filter_type is one of:

  • stack_monitoring: all_entities, entity_ids, tag_ids. It applies to the Security Engine, Log Processor and Remediation Component monitoring events.
  • alert: the same fields plus all_scenarios and scenarios. It applies to the alert_triggered and self_report events.

The fields of each item in destinations are described in Get Notification Rule Destinations.

Get Notification Ruleโ€‹

Retrieve a single notification rule, using the id returned by Get Notification Rules

SH
curl -i -H "x-api-key: ${KEY}" -X GET -H "Content-Type: application/json" \
https://admin.api.crowdsec.net/v1/notification-rules/${RULE_ID}
answer on success
JSON
{
"id": "string",
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"name": "string",
"organization_id": "string",
"destinations": [
{
"id": "string",
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"integration_id": "string",
"failure_state": null,
"integration_type": "email",
"emails": [
"secops@example.com"
]
}
],
"description": "string",
"events": [
{
"name": "alert_triggered"
}
],
"event_filter": {
"all_entities": true,
"entity_ids": [],
"tag_ids": [],
"filter_type": "alert",
"all_scenarios": false,
"scenarios": [
"crowdsecurity/ssh-bf"
]
}
}

An unknown rule_id returns 404 Not Found.

Get Notification Rule Destinationsโ€‹

List the destinations of a notification rule

SH
curl -i -H "x-api-key: ${KEY}" -X GET -H "Content-Type: application/json" \
https://admin.api.crowdsec.net/v1/notification-rules/${RULE_ID}/destinations
answer on success
JSON
{
"items": [
{
"id": "string",
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"integration_id": "string",
"failure_state": {
"consecutive_failures": 10,
"last_error": "string",
"last_failure_attempt_at": "2019-08-24T14:15:22Z",
"next_attempt_at": "2019-08-24T15:15:22Z"
},
"integration_type": "webhook",
"url": "https://example.com/crowdsec",
"verify_ssl": true,
"credentials": {
"credential_type": "api_key",
"header_name": "x-crowdsec-api-key"
}
}
]
}

Every destination returns id, created_at, updated_at, integration_id, integration_type and failure_state. The other fields depend on integration_type:

  • slack and discord: channel_id, channel_name.
  • webhook: url, verify_ssl and credentials. credentials.credential_type is api_key (with header_name) or basic_auth (with username). The API key and password are never returned.
  • email: emails.

failure_state is null while the destination works. It is set while deliveries to the destination keep failing: consecutive_failures counts the failed deliveries in a row. After 10 failures in a row the destination is suspended: notifications are skipped until next_attempt_at, and the first one arriving after that time is attempted. next_attempt_at is null while the destination is not suspended.

An unknown rule_id returns 404 Not Found.

Notification eventsโ€‹

Get Notification Eventsโ€‹

List the event types a notification rule can react to

This endpoint returns the catalogue of event types, not a history of sent notifications. The event_type values are the ones found in the events[].name field of a notification rule.

SH
curl -i -H "x-api-key: ${KEY}" -X GET -H "Content-Type: application/json" \
https://admin.api.crowdsec.net/v1/notification-events
answer on success
JSON
{
"items": [
{
"event_type": "security_engine_offline",
"category": "stack",
"subcategory": "monitoring",
"label": "Security Engine Offline",
"description": "A Security Engine is offline (no login for 48h).",
"filter_type": "stack_monitoring"
}
]
}

category is one of alerts, stack, admin, integration or threat_hunting. filter_type tells which event_filter of a rule applies to the event (alert or stack_monitoring), and is null when the event cannot be filtered.

CrowdSec Docs
We use cookies

This site uses cookies to help us improve your experience. You can accept or decline below.