Handlers API
NOTE: Requests to the handlers 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 handlers
The /handlers
API endpoint provides HTTP GET access to handler data.
Example
The following example demonstrates a request to the /handlers
API endpoint, resulting in a JSON array that contains handler definitions.
curl -X GET \
http://127.0.0.1:8080/api/core/v2/namespaces/default/handlers \
-H "Authorization: Key $SENSU_API_KEY"
HTTP/1.1 200 OK
[
{
"metadata": {
"name": "influx-db",
"namespace": "default",
"created_by": "admin"
},
"type": "pipe",
"command": "sensu-influxdb-handler -d sensu",
"timeout": 0,
"handlers": null,
"filters": null,
"env_vars": [
"INFLUXDB_ADDR=http://influxdb.default.svc.cluster.local:8086",
"INFLUXDB_USER=sensu",
"INFLUXDB_PASSWORD=password"
],
"runtime_assets": ["sensu/sensu-influxdb-handler"]
},
{
"metadata": {
"name": "slack",
"namespace": "default",
"created_by": "admin"
},
"type": "pipe",
"command": "sensu-slack-handler --channel '#monitoring'",
"timeout": 0,
"handlers": null,
"filters": [
"is_incident",
"not_silenced"
],
"env_vars": [
"SLACK_WEBHOOK_URL=https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
],
"runtime_assets": ["sensu/sensu-influxdb-handler"]
}
]
API Specification
/handlers (GET) | |
---|---|
description | Returns the list of handlers. |
example url | http://hostname:8080/api/core/v2/namespaces/default/handlers |
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 handler
The /handlers
API endpoint provides HTTP POST access to create a handler.
Example
In the following example, an HTTP POST request is submitted to the /handlers
API endpoint to create the event handler influx-db
.
The request returns a successful HTTP 201 Created
response.
curl -X POST \
-H "Authorization: Key $SENSU_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"metadata": {
"name": "influx-db",
"namespace": "default",
"labels": null,
"annotations": null
},
"command": "sensu-influxdb-handler -d sensu",
"env_vars": [
"INFLUXDB_ADDR=http://influxdb.default.svc.cluster.local:8086",
"INFLUXDB_USER=sensu",
"INFLUXDB_PASSWORD=password"
],
"filters": [],
"handlers": [],
"runtime_assets": [],
"timeout": 0,
"type": "pipe"
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/handlers
HTTP/1.1 201 Created
API Specification
/handlers (POST) | |
---|---|
description | Creates a Sensu handler. |
example URL | http://hostname:8080/api/core/v2/namespaces/default/handlers |
payload |
|
response codes |
|
Get a specific handler
The /handlers/:handler
API endpoint provides HTTP GET access to handler data for specific :handler
definitions, by handler name
.
Example
In the following example, querying the /handlers/:handler
API endpoint returns a JSON map that contains the requested :handler
definition (in this example, for the :handler
named slack
).
curl -X GET \
http://127.0.0.1:8080/api/core/v2/namespaces/default/handlers/slack \
-H "Authorization: Key $SENSU_API_KEY"
HTTP/1.1 200 OK
{
"metadata": {
"name": "slack",
"namespace": "default",
"created_by": "admin",
"labels": null,
"annotations": null
},
"command": "sensu-slack-handler --channel '#monitoring'",
"env_vars": [
"SLACK_WEBHOOK_URL=https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
],
"filters": [
"is_incident",
"not_silenced"
],
"handlers": [],
"runtime_assets": [],
"timeout": 0,
"type": "pipe"
}
API Specification
/handlers/:handler (GET) | |
---|---|
description | Returns a handler. |
example url | http://hostname:8080/api/core/v2/namespaces/default/handlers/slack |
response type | Map |
response codes |
|
output |
|
Create or update a handler
The /handlers/:handler
API endpoint provides HTTP GET access to create or update a specific :handler
definition, by handler name
.
Example
In the following example, an HTTP PUT request is submitted to the /handlers/:handler
API endpoint to create the handler influx-dbdevelopment_filter
.
The request returns a successful HTTP 201 Created
response.
curl -X PUT \
-H "Authorization: Key $SENSU_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"metadata": {
"name": "influx-db",
"namespace": "default",
"labels": null,
"annotations": null
},
"command": "sensu-influxdb-handler -d sensu",
"env_vars": [
"INFLUXDB_ADDR=http://influxdb.default.svc.cluster.local:8086",
"INFLUXDB_USER=sensu",
"INFLUXDB_PASSWORD=password"
],
"filters": [],
"handlers": [],
"runtime_assets": ["sensu/sensu-influxdb-handler"],
"timeout": 0,
"type": "pipe"
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/handlers/influx-db
HTTP/1.1 201 Created
API Specification
/handlers/:handler (PUT) | |
---|---|
description | Creates or updates the specified Sensu handler. |
example URL | http://hostname:8080/api/core/v2/namespaces/default/handlers/influx-db |
payload |
|
response codes |
|
Update a handler with PATCH
The /handlers/:handler
API endpoint provides HTTP PATCH access to update :handler
definitions, specified by handler name.
NOTE: You cannot change a resource’s name
or namespace
with a PATCH request.
Use a PUT request instead.
Also, you cannot add elements to an array with a PATCH request — you must replace the entire array.
Example
In the following example, an HTTP PATCH request is submitted to the /handlers/:handler
API endpoint to update the filters array for the influx-db
handler, resulting in an HTTP 200 OK
response and the updated handler definition.
We support JSON merge patches, so you must set the Content-Type
header to application/merge-patch+json
for PATCH requests.
curl -X PATCH \
-H "Authorization: Key $SENSU_API_KEY" \
-H 'Content-Type: application/merge-patch+json' \
-d '{
"filters": [
"us-west",
"is_incident"
]
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/handlers/influx-db
HTTP/1.1 200 OK
API Specification
/handlers/:handler (PATCH) | |
---|---|
description | Updates the specified Sensu handler. |
example URL | http://hostname:8080/api/core/v2/namespaces/default/handlers/influx-db |
payload |
|
response codes |
|
Delete a handler
The /handlers/:handler
API endpoint provides HTTP DELETE access to delete a handler from Sensu (specified by the handler name).
Example
The following example shows a request to the /handlers/:handler
API endpoint to delete the handler slack
, resulting in a successful HTTP 204 No Content
response.
curl -X DELETE \
http://127.0.0.1:8080/api/core/v2/namespaces/default/handlers/slack \
-H "Authorization: Key $SENSU_API_KEY"
HTTP/1.1 204 No Content
API Specification
/handlers/:handler (DELETE) | |
---|---|
description | Removes the specified handler from Sensu. |
example url | http://hostname:8080/api/core/v2/namespaces/default/handlers/slack |
response codes |
|