core/v2/mutators
NOTE: Requests to core/v2/mutators
API endpoints require you to authenticate with a Sensu API key or access token.
The code examples in this document use the environment variable $SENSU_API_KEY
to represent a valid API key in API requests.
Get all mutators
The /mutators
API endpoint provides HTTP GET access to mutator data.
Example
The following example demonstrates a GET request to the /mutators
API endpoint:
curl -X GET \
http://127.0.0.1:8080/api/core/v2/namespaces/default/mutators \
-H "Authorization: Key $SENSU_API_KEY"
The request results in a successful HTTP/1.1 200 OK
response and a JSON array that contains the mutator definitions in the default
namespace:
[
{
"metadata": {
"name": "example-mutator",
"namespace": "default",
"created_by": "admin",
"labels": null,
"annotations": null
},
"command": "example_mutator.go",
"timeout": 0,
"env_vars": [],
"runtime_assets": [],
"secrets": null,
"type": "pipe"
}
]
API Specification
/mutators (GET) | |
---|---|
description | Returns the list of mutators. |
example url | http://hostname:8080/api/core/v2/namespaces/default/mutators |
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 mutator
The /mutators
API endpoint provides HTTP POST access to create mutators.
Example
In the following example, an HTTP POST request is submitted to the /mutators
API endpoint to create the mutator example-mutator
:
curl -X POST \
-H "Authorization: Key $SENSU_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"metadata": {
"name": "example-mutator",
"namespace": "default",
"labels": null,
"annotations": null
},
"command": "example_mutator.go",
"timeout": 0,
"env_vars": [],
"runtime_assets": [],
"secrets": null,
"type": "pipe"
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/mutators
The request will return a successful HTTP/1.1 201 Created
response.
API Specification
/mutators (POST) | |
---|---|
description | Creates a Sensu mutator. |
example URL | http://hostname:8080/api/core/v2/namespaces/default/mutators |
payload |
|
response codes |
|
Get a specific mutator
The /mutators/:mutator
API endpoint provides HTTP GET access to mutator data for specific :mutator
definitions, by mutator name.
Example
The following example queries the /mutators/:mutator
API endpoint for the :mutator
named example-mutator
:
curl -X GET \
http://127.0.0.1:8080/api/core/v2/namespaces/default/mutators/example-mutator \
-H "Authorization: Key $SENSU_API_KEY"
The request will return a successful HTTP/1.1 200 OK
response and a JSON map that contains the requested :mutator
definition (in this example, example-mutator
):
{
"metadata": {
"name": "example-mutator",
"namespace": "default",
"created_by": "admin",
"labels": null,
"annotations": null
},
"command": "example_mutator.go",
"timeout": 0,
"env_vars": [],
"runtime_assets": [],
"secrets": null,
"type": "pipe"
}
API Specification
/mutators/:mutator (GET) | |
---|---|
description | Returns the specified mutator. |
example url | http://hostname:8080/api/core/v2/namespaces/default/mutators/example-mutator |
response type | Map |
response codes |
|
output |
|
Create or update a mutator
The /mutators/:mutator
API endpoint provides HTTP PUT access to mutator data to create or update specific :mutator
definitions, by mutator name.
Example
In the following example, an HTTP PUT request is submitted to the /mutators/:mutator
API endpoint to create the mutator example-mutator
:
curl -X PUT \
-H "Authorization: Key $SENSU_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"metadata": {
"name": "example-mutator",
"namespace": "default",
"labels": null,
"annotations": null
},
"command": "example_mutator.go",
"timeout": 0,
"env_vars": [],
"runtime_assets": [],
"secrets": null,
"type": "pipe"
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/mutators/example-mutator
The request will return a successful HTTP/1.1 201 Created
response.
API Specification
/mutators/:mutator (PUT) | |
---|---|
description | Creates or updates a Sensu mutator. |
example URL | http://hostname:8080/api/core/v2/namespaces/default/mutators/example-mutator |
payload |
|
response codes |
|
Update a mutator with PATCH
The /mutators/:mutator
API endpoint provides HTTP PATCH access to update :mutator
definitions, specified by mutator 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 /mutators/:mutator
API endpoint to update the timeout for the example-mutator
mutator, resulting in an HTTP/1.1 200 OK
response and the updated mutator 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 '{
"timeout": 10
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/mutators/example-mutator
API Specification
/mutators/:mutator (PATCH) | |
---|---|
description | Updates the specified Sensu mutator. |
example URL | http://hostname:8080/api/core/v2/namespaces/default/mutators/process-tree |
payload |
|
response codes |
|
Delete a mutator
The /mutators/:mutator
API endpoint provides HTTP DELETE access to delete a mutator from Sensu (specified by the mutator name).
Example
The following example shows a request to the /mutators/:mutator
API endpoint to delete the mutator example-mutator
, resulting in a successful HTTP/1.1 204 No Content
response.
curl -X DELETE \
http://127.0.0.1:8080/api/core/v2/namespaces/default/mutators/example-mutator \
-H "Authorization: Key $SENSU_API_KEY"
API Specification
/mutators/:mutator (DELETE) | |
---|---|
description | Removes the specified mutator from Sensu. |
example url | http://hostname:8080/api/core/v2/namespaces/default/mutators/example-mutator |
response codes |
|
Get a subset of mutators with response filtering
The /mutators
API endpoint supports response filtering for a subset of mutator data based on labels and the following fields:
mutator.name
mutator.namespace
mutator.runtime_assets
Example
The following example demonstrates a request to the /mutators
API endpoint with response filtering for only mutator definitions that are in the production
namespace:
curl -H "Authorization: Key $SENSU_API_KEY" http://127.0.0.1:8080/api/core/v2/mutators -G \
--data-urlencode 'fieldSelector=mutator.namespace == production'
The example request will result in a successful HTTP/1.1 200 OK
response and a JSON array that contains only mutator definitions in the production
namespace:
[
{
"metadata": {
"name": "add_check_label",
"namespace": "production",
"labels": {
"sensu.io/managed_by": "sensuctl"
},
"created_by": "admin"
},
"timeout": 0,
"env_vars": null,
"runtime_assets": null,
"secrets": null,
"type": "javascript",
"eval": "data = JSON.parse(JSON.stringify(event)); delete data.check.metadata.name; delete data.entity.metadata.labels.app_id; return JSON.stringify(data)"
},
{
"metadata": {
"name": "example-mutator",
"namespace": "production",
"labels": {
"sensu.io/managed_by": "sensuctl"
},
"created_by": "admin"
},
"command": "example_mutator.go",
"timeout": 0,
"env_vars": null,
"runtime_assets": [
"example-mutator-asset"
],
"secrets": null,
"type": "pipe"
}
]
NOTE: Read API response filtering for more filter statement examples that demonstrate how to filter responses using different operators with label and field selectors.
API Specification
/mutators (GET) with response filters | |
---|---|
description | Returns the list of mutators that match the response filters applied in the API request. |
example url | http://hostname:8080/api/core/v2/mutators |
pagination | This endpoint supports pagination using the limit and continue query parameters. |
response type | Array |
response codes |
|
output |
|