Filters API
NOTE: Requests to the filters 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 event filters
The /filters
API endpoint provides HTTP GET access to event filter data.
Example
The following example demonstrates a request to the /filters
API endpoint, resulting in a JSON array that contains event filter definitions.
curl -X GET \
http://127.0.0.1:8080/api/core/v2/namespaces/default/filters \
-H "Authorization: Bearer $TOKEN"
HTTP/1.1 200 OK
[
{
"metadata": {
"name": "development_filter",
"namespace": "default",
"created_by": "admin"
},
"action": "deny",
"expressions": [
"event.entity.metadata.namespace == 'development'"
],
"runtime_assets": null
},
{
"metadata": {
"name": "state_change_only",
"namespace": "default"
},
"action": "allow",
"expressions": [
"event.check.occurrences == 1"
],
"runtime_assets": null
}
]
API Specification
/filters (GET) | |
---|---|
description | Returns the list of event filters. |
example url | http://hostname:8080/api/core/v2/namespaces/default/filters |
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 filter
The /filters
API endpoint provides HTTP POST access to create an event filter.
Example
In the following example, an HTTP POST request is submitted to the /filters
API endpoint to create the event filter development_filter
.
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": "development_filter",
"namespace": "default",
"labels": null,
"annotations": null
},
"action": "deny",
"expressions": [
"event.entity.metadata.namespace == 'development'"
],
"runtime_assets": []
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/filters
HTTP/1.1 201 Created
API Specification
/filters (POST) | |
---|---|
description | Creates a Sensu event filter. |
example URL | http://hostname:8080/api/core/v2/namespaces/default/filters |
payload |
|
response codes |
|
Get a specific event filter
The /filters/:filter
API endpoint provides HTTP GET access to event filter data for specific :filter
definitions, by filter name.
Example
In the following example, querying the /filters/:filter
API endpoint returns a JSON map that contains the requested :filter
definition (in this example, for the :filter
named state_change_only
).
curl -X GET \
http://127.0.0.1:8080/api/core/v2/namespaces/default/filters/state_change_only \
-H "Authorization: Bearer $TOKEN"
HTTP/1.1 200 OK
{
"metadata": {
"name": "state_change_only",
"namespace": "default",
"created_by": "admin"
},
"action": "allow",
"expressions": [
"event.check.occurrences == 1"
],
"runtime_assets": null
}
API Specification
/filters/:filter (GET) | |
---|---|
description | Returns the specified event filter. |
example url | http://hostname:8080/api/core/v2/namespaces/default/filters/state_change_only |
response type | Map |
response codes |
|
output |
|
Create or update an event filter
The /filters/:filter
API endpoint provides HTTP PUT access to create or update an event filter.
Example
In the following example, an HTTP PUT request is submitted to the /filters
API endpoint to create the event filter development_filter
.
The request returns a successful HTTP 200 OK
response.
curl -X PUT \
-H "Authorization: Key $SENSU_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"metadata": {
"name": "development_filter",
"namespace": "default",
"labels": null,
"annotations": null
},
"action": "deny",
"expressions": [
"event.entity.metadata.namespace == 'development'"
],
"runtime_assets": []
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/filters/development_filter
HTTP/1.1 201 Created
API Specification
/filters/:filter (PUT) | |
---|---|
description | Creates or updates the specified Sensu event filter. |
example URL | http://hostname:8080/api/core/v2/namespaces/default/filters/development_filter |
payload |
|
response codes |
|
Update a filter with PATCH
The /filters/:filter
API endpoint provides HTTP PATCH access to update :filter
definitions, specified by filter 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 /filters/:filter
API endpoint to update the expressions array for the us-west
filter, resulting in an HTTP 200 OK
response and the updated filter 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 '{
"expressions": [
"event.check.occurrences == 3"
]
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/filter/us-west
HTTP/1.1 200 OK
API Specification
/filters/:filter (PATCH) | |
---|---|
description | Updates the specified Sensu filter. |
example URL | http://hostname:8080/api/core/v2/namespaces/default/filter/us-west |
payload |
|
response codes |
|
Delete an event filter
The /filters/:filter
API endpoint provides HTTP DELETE access to delete an event filter from Sensu (specified by the filter name).
Example
The following example shows a request to the /filters/:filter
API endpoint to delete the event filter development_filter
, resulting in a successful HTTP 204 No Content
response.
curl -X DELETE \
http://127.0.0.1:8080/api/core/v2/namespaces/default/filters/development_filter \
-H "Authorization: Key $SENSU_API_KEY"
HTTP/1.1 204 No Content
API Specification
/filters/:filter (DELETE) | |
---|---|
description | Removes the specified event filter from Sensu. |
example url | http://hostname:8080/api/core/v2/namespaces/default/filters/development_filter |
response codes |
|