Events API
NOTE: Requests to the events API require you to authenticate with a Sensu access token or API key.
The code examples in this document use the environment variable $SENSU_API_KEY
to represent a valid API key in API requests.
Get all events
The /events
API endpoint provides HTTP GET access to event data.
Example
The following example demonstrates a request to the /events
API endpoint, resulting in a JSON array that contains event definitions.
curl -X GET \
http://127.0.0.1:8080/api/core/v2/namespaces/default/events \
-H "Authorization: Key $SENSU_API_KEY"
HTTP/1.1 200 OK
[
{
"timestamp": 1542667666,
"id": "caaf2c38-2afb-4f96-89b3-8ca5c3e6f449",
"entity": {
"entity_class": "agent",
"system": {
"hostname": "webserver01",
"...": "...",
"arch": "amd64"
},
"subscriptions": [
"testing",
"entity:webserver01"
],
"metadata": {
"name": "check-nginx",
"namespace": "default",
"created_by": "admin",
"labels": null,
"annotations": null
}
},
"check": {
"check_hooks": null,
"duration": 2.033888684,
"command": "http_check.sh http://localhost:80",
"handlers": [
"slack"
],
"high_flap_threshold": 0,
"interval": 20,
"is_silenced": true,
"low_flap_threshold": 0,
"publish": true,
"runtime_assets": [],
"subscriptions": [
"testing"
],
"proxy_entity_name": "",
"check_hooks": null,
"stdin": false,
"ttl": 0,
"timeout": 0,
"duration": 0.010849143,
"output": "",
"silenced": [
"entity:gin:check-nginx"
],
"state": "failing",
"status": 1,
"total_state_change": 0,
"last_ok": 0,
"occurrences": 1,
"occurrences_watermark": 1,
"output_metric_format": "",
"output_metric_handlers": [],
"env_vars": null,
"metadata": {
"name": "check-nginx",
"namespace": "default",
"created_by": "admin",
"labels": null,
"annotations": null
}
}
}
]
API Specification
/events (GET) | |
---|---|
description | Returns the list of events. |
example url | http://hostname:8080/api/core/v2/namespaces/default/events |
pagination | This endpoint supports pagination using the limit and continue query parameters. |
response filtering | This endpoint supports API response filtering. |
response type | Array |
response codes |
|
output |
|
Create a new event
The /events
API endpoint provides HTTP POST access to create an event and send it to the Sensu pipeline.
Example
In the following example, an HTTP POST request is submitted to the /events
API endpoint to create an event.
The request includes information about the check and entity represented by the event and returns a successful HTTP 201 Created
response and the event definition.
curl -X POST \
-H "Authorization: Key $SENSU_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"entity": {
"entity_class": "proxy",
"metadata": {
"name": "server1",
"namespace": "default"
}
},
"check": {
"output": "Server error",
"silenced": [
"entity:gin:server-health"
],
"state": "failing",
"status": 2,
"handlers": ["slack"],
"interval": 60,
"is_silenced": true,
"metadata": {
"name": "server-health"
}
}
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/events
HTTP/1.1 201 Created
API Specification
/events (POST) | |
---|---|
description | Creates a new Sensu event. To update an existing event, use the /events PUT endpoint.If you create a new event that references an entity that does not already exist, the sensu-backend will automatically create a proxy entity in the same namespace when the event is published. NOTE: An agent cannot belong to, execute checks in, or create events in more than one namespace. |
example URL | http://hostname:8080/api/core/v2/namespaces/default/events |
payload |
|
response codes |
|
Get event data for a specific entity
The /events/:entity
API endpoint provides HTTP GET access to event data specific to an :entity
, by entity name
.
Example
In the following example, querying the /events/:entity
API endpoint returns a list of Sensu events for the sensu-go-sandbox
entity and a successful HTTP 200 OK
response.
curl -X GET \
http://127.0.0.1:8080/api/core/v2/namespaces/default/events/sensu-go-sandbox \
-H "Authorization: Key $SENSU_API_KEY"
HTTP/1.1 200 OK
[
{
"timestamp": 1543871497,
"id": "a68906e0-7c5c-49f0-8424-59a71d3ecfe2",
"entity": {
"entity_class": "agent",
"system": {
"hostname": "webserver01",
"...": "...",
"arch": "amd64"
},
"subscriptions": [
"linux",
"entity:sensu-go-sandbox"
],
"last_seen": 1543858763,
"metadata": {
"name": "sensu-go-sandbox",
"namespace": "default",
"created_by": "admin"
}
},
"check": {
"command": "check-cpu.sh -w 75 -c 90",
"duration": 1.054253257,
"executed": 1543871496,
"history": [
{
"status": 0,
"executed": 1543870296
}
],
"issued": 1543871496,
"output": "CPU OK - Usage:.50\n",
"silenced": [
"entity:gin:check-cpu"
],
"state": "passing",
"status": 0,
"total_state_change": 0,
"last_ok": 1543871497,
"occurrences": 1,
"metadata": {
"name": "check-cpu",
"namespace": "default",
"created_by": "admin"
}
},
"metadata": {
"namespace": "default"
}
},
{
"timestamp": 1543871524,
"id": "095c37e8-1cb4-4d10-91e9-0bdd55a4f35b",
"entity": {
"entity_class": "agent",
"system": {
"hostname": "webserver01",
"...": "...",
"arch": "amd64"
},
"subscriptions": [
"linux",
"entity:sensu-go-sandbox"
],
"last_seen": 1543871523,
"metadata": {
"name": "sensu-go-sandbox",
"namespace": "default",
"created_by": "admin"
}
},
"check": {
"handlers": [
"keepalive"
],
"executed": 1543871524,
"history": [
{
"status": 0,
"executed": 1543871124
}
],
"issued": 1543871524,
"output": "",
"silenced": [
"entity:gin:keepalive"
],
"state": "passing",
"status": 0,
"total_state_change": 0,
"last_ok": 1543871524,
"occurrences": 1,
"metadata": {
"name": "keepalive",
"namespace": "default",
"created_by": "admin"
}
},
"metadata": {}
}
]
API Specification
/events/:entity (GET) | |
---|---|
description | Returns a list of events for the specified entity. |
example url | http://hostname:8080/api/core/v2/namespaces/default/events/sensu-go-sandbox |
pagination | This endpoint supports pagination using the limit and continue query parameters. |
response type | Array |
response codes |
|
output |
|
Get event data for a specific entity and check
The /events/:entity/:check
API endpoint provides HTTP GET access to event data for the specified entity and check.
Example
In the following example, an HTTP GET request is submitted to the /events/:entity/:check
API endpoint to retrieve the event for the server1
entity and the server-health
check.
curl -X GET \
http://127.0.0.1:8080/api/core/v2/namespaces/default/events/server1/server-health \
-H "Authorization: Key $SENSU_API_KEY"
HTTP/1.1 200 OK
{
"timestamp": 1577724113,
"id": "cf3c9fc0-023a-497a-aaf4-880dbd490332",
"entity": {
"entity_class": "proxy",
"system": {
"network": {
"interfaces": null
}
},
"subscriptions": null,
"last_seen": 0,
"deregister": false,
"deregistration": {},
"metadata": {
"name": "server1",
"namespace": "default",
"created_by": "admin"
},
"sensu_agent_version": ""
},
"check": {
"handlers": [
"slack"
],
"high_flap_threshold": 0,
"interval": 60,
"is_silenced": true,
"low_flap_threshold": 0,
"publish": false,
"runtime_assets": null,
"subscriptions": [],
"proxy_entity_name": "",
"check_hooks": null,
"stdin": false,
"subdue": null,
"ttl": 0,
"timeout": 0,
"round_robin": false,
"executed": 1543880280,
"history": [
{
"status": 1,
"executed": 1543880296
},
{
"status": 2,
"executed": 1543880435
},
{
"status": 1,
"executed": 1543889363
}
],
"issued": 0,
"output": "Server error",
"silenced": [
"entity:gin:server-health"
],
"state": "failing",
"status": 1,
"total_state_change": 0,
"last_ok": 0,
"occurrences": 1,
"occurrences_watermark": 1,
"output_metric_format": "",
"output_metric_handlers": null,
"env_vars": null,
"metadata": {
"name": "server-health",
"namespace": "default",
"created_by": "admin"
}
},
"metadata": {}
}
The request returns an HTTP 200 OK
response and the resulting event definition.
API Specification
/events/:entity/:check (GET) | |
---|---|
description | Returns an event for the specified entity and check. |
example url | http://hostname:8080/api/core/v2/namespaces/default/events/server1/server-health |
response type | Map |
response codes |
|
output |
|
Create a new event for an entity and check
The /events/:entity/:check
API endpoint provides HTTP POST access to create an event and send it to the Sensu pipeline.
Example
In the following example, an HTTP POST request is submitted to the /events/:entity/:check
API endpoint to create an event for the server1
entity and the server-health
check and process it using the slack
event handler.
The event includes a status code of 1
, indicating a warning, and an output message of Server error
.
curl -X POST \
-H "Authorization: Key $SENSU_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"entity": {
"entity_class": "proxy",
"metadata": {
"name": "server1",
"namespace": "default"
}
},
"check": {
"output": "Server error",
"silenced": [
"entity:gin:server-health"
],
"status": 1,
"handlers": ["slack"],
"interval": 60,
"is_silenced": true,
"metadata": {
"name": "server-health"
}
}
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/events/server1/server-health
HTTP/1.1 201 Created
NOTE: A namespace is not required to create the event. The event will use the namespace in the URL by default.
You can use sensuctl or the Sensu web UI to see the event:
sensuctl event list
You should see the event with the status and output specified in the request:
Entity Check Output Status Silenced Timestamp
────────────── ───────────── ─────────────────────────────────── ──────── ────────── ───────────────────────────────
server1 server-health Server error 1 false 2019-03-14 16:56:09 +0000 UTC
API Specification
/events/:entity/:check (POST) | |
---|---|
description | Creates an event for the specified entity and check. |
example url | http://hostname:8080/api/core/v2/namespaces/default/events/server1/server-health |
payload |
|
response codes |
|
Create or update an event for an entity and check
The /events/:entity/:check
API endpoint provides HTTP PUT access to create or update an event and send it to the Sensu pipeline.
Example
In the following example, an HTTP PUT request is submitted to the /events/:entity/:check
API endpoint to create an event for the server1
entity and the server-health
check and process it using the slack
event handler.
The event includes a status code of 1
, indicating a warning, and an output message of Server error
.
curl -X PUT \
-H "Authorization: Key $SENSU_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"entity": {
"entity_class": "proxy",
"metadata": {
"name": "server1",
"namespace": "default"
}
},
"check": {
"output": "Server error",
"silenced": [
"entity:gin:server-health"
],
"status": 1,
"handlers": ["slack"],
"interval": 60,
"is_silenced": true,
"metadata": {
"name": "server-health"
}
}
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/events/server1/server-health
HTTP/1.1 201 Created
NOTE: A namespace is not required to create the event. The event will use the namespace in the URL by default.
You can use sensuctl or the Sensu web UI to see the event:
sensuctl event list
You should see the event with the status and output specified in the request:
Entity Check Output Status Silenced Timestamp
────────────── ───────────── ─────────────────────────────────── ──────── ────────── ───────────────────────────────
server1 server-health Server error 1 false 2019-03-14 16:56:09 +0000 UTC
API Specification
/events/:entity/:check (PUT) | |
---|---|
description | Creates an event for the specified entity and check. |
example url | http://hostname:8080/api/core/v2/namespaces/default/events/server1/server-health |
payload |
|
payload parameters | See the payload parameters section below. |
response codes |
|
Payload parameters
The /events/:entity/:check
PUT endpoint requires a request payload that contains an entity
scope and a check
scope.
- The
entity
scope contains information about the component of your infrastructure represented by the event. At minimum, Sensu requires theentity
scope to contain theentity_class
(agent
orproxy
) and the entityname
andnamespace
within ametadata
scope. For more information about entity attributes, see the entity specification. - The
check
scope contains information about the event status and how the event was created. At minimum, Sensu requires thecheck
scope to contain aname
within ametadata
scope and either aninterval
orcron
attribute. For more information about check attributes, see the check specification.
Example request with minimum required event attributes
curl -X PUT \
-H "Authorization: Key $SENSU_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"entity": {
"entity_class": "proxy",
"metadata": {
"name": "server1"
}
},
"check": {
"interval": 60,
"metadata": {
"name": "server-health"
}
}
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/events/server1/server-health
The minimum required attributes let you create an event using the /events/:entity/:check
PUT endpoint, but the request can include any attributes defined in the event specification.
To create useful, actionable events, we recommend adding check attributes such as the event status
(0
for OK, 1
for warning, 2
for critical), an output
message, and one or more event handlers
.
For more information about these attributes and their available values, see the event specification.
Example request with minimum recommended event attributes
curl -X PUT \
-H "Authorization: Key $SENSU_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"entity": {
"entity_class": "proxy",
"metadata": {
"name": "server1",
"namespace": "default"
}
},
"check": {
"output": "Server error",
"silenced": [
"entity:gin:server-health"
],
"status": 1,
"handlers": ["slack"],
"interval": 60,
"metadata": {
"name": "server-health"
}
}
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/events/server1/server-health
Create metrics events
In addition to the entity
and check
scopes, Sensu events can include a metrics
scope that contains metrics in Sensu metric format.
See the events reference and for more information about Sensu metric format.
Example request including metrics
curl -X PUT \
-H "Authorization: Key $SENSU_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"entity": {
"entity_class": "proxy",
"metadata": {
"name": "server1",
"namespace": "default"
}
},
"check": {
"status": 0,
"output_metric_handlers": ["influxdb"],
"interval": 60,
"metadata": {
"name": "server-metrics"
}
},
"metrics": {
"handlers": [
"influxdb"
],
"points": [
{
"name": "server1.server-metrics.time_total",
"tags": [],
"timestamp": 1552506033,
"value": 0.005
},
{
"name": "server1.server-metrics.time_namelookup",
"tags": [],
"timestamp": 1552506033,
"value": 0.004
}
]
}
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/events/server1/server-metrics
Delete an event
Example
The following example shows a request to the /events/:entity/:check
API endpoint to delete the event produced by the sensu-go-sandbox
entity and check-cpu
check, resulting in a successful HTTP 204 No Content
response.
curl -X DELETE \
http://127.0.0.1:8080/api/core/v2/namespaces/default/events/sensu-go-sandbox/check-cpu \
-H "Authorization: Key $SENSU_API_KEY"
HTTP/1.1 204 No Content
API Specification
/events/:entity/:check (DELETE) | |
---|---|
description | Deletes the event created by the specified entity using the specified check. |
example url | http://hostname:8080/api/core/v2/namespaces/default/events/sensu-go-sandbox/check-cpu |
response codes |
|