Mutators API

NOTE: Requests to the mutators 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 mutators

The /mutators API endpoint provides HTTP GET access to mutator data.

Example

The following example demonstrates a request to the /mutators API endpoint, resulting in a JSON array that contains mutator definitions.

curl -X GET \
http://127.0.0.1:8080/api/core/v2/namespaces/default/mutators \
-H "Authorization: Key $SENSU_API_KEY"

HTTP/1.1 200 OK
[
  {
    "metadata": {
      "name": "example-mutator",
      "namespace": "default",
      "created_by": "admin",
      "labels": null,
      "annotations": null
    },
    "command": "example_mutator.go",
    "timeout": 0,
    "env_vars": [],
    "runtime_assets": []
  }
]

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
  • Success: 200 (OK)
  • Error: 500 (Internal Server Error)
output
[
  {
    "metadata": {
      "name": "example-mutator",
      "namespace": "default",
      "created_by": "admin",
      "labels": null,
      "annotations": null
    },
    "command": "example_mutator.go",
    "timeout": 0,
    "env_vars": [],
    "runtime_assets": []
  }
]

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. 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": "example-mutator",
    "namespace": "default",
    "labels": null,
    "annotations": null
  },
  "command": "example_mutator.go",
  "timeout": 0,
  "env_vars": [],
  "runtime_assets": []
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/mutators

HTTP/1.1 201 Created

API Specification

/mutators (POST)
description Creates a Sensu mutator.
example URL http://hostname:8080/api/core/v2/namespaces/default/mutators
payload
{
  "metadata": {
    "name": "example-mutator",
    "namespace": "default",
    "labels": null,
    "annotations": null
  },
  "command": "example_mutator.go",
  "timeout": 0,
  "env_vars": [],
  "runtime_assets": []
}
response codes
  • Success: 201 (Created)
  • Malformed: 400 (Bad Request)
  • Error: 500 (Internal Server Error)

Get a specific mutator

The /mutators/:mutator API endpoint provides HTTP GET access to mutator data for specific :mutator definitions, by mutator name.

Example

In the following example, querying the /mutators/:mutator API endpoint returns a JSON map that contains the requested :mutator definition (in this example, 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"

HTTP/1.1 200 OK
{
  "metadata": {
    "name": "example-mutator",
    "namespace": "default",
    "created_by": "admin",
    "labels": null,
    "annotations": null
  },
  "command": "example_mutator.go",
  "timeout": 0,
  "env_vars": [],
  "runtime_assets": []
}

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
  • Success: 200 (OK)
  • Missing: 404 (Not Found)
  • Error: 500 (Internal Server Error)
output
{
  "metadata": {
    "name": "example-mutator",
    "namespace": "default",
    "created_by": "admin",
    "labels": null,
    "annotations": null
  },
  "command": "example_mutator.go",
  "timeout": 0,
  "env_vars": [],
  "runtime_assets": []
}

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. 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": "example-mutator",
    "namespace": "default",
    "labels": null,
    "annotations": null
  },
  "command": "example_mutator.go",
  "timeout": 0,
  "env_vars": [],
  "runtime_assets": []
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/mutators/example-mutator

HTTP/1.1 201 Created

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
{
  "metadata": {
    "name": "example-mutator",
    "namespace": "default",
    "labels": null,
    "annotations": null
  },
  "command": "example_mutator.go",
  "timeout": 0,
  "env_vars": [],
  "runtime_assets": []
}
response codes
  • Success: 201 (Created)
  • Malformed: 400 (Bad Request)
  • Error: 500 (Internal Server Error)

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 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

HTTP/1.1 200 OK

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
{
  "timeout": 10
}
response codes
  • Success: 200 (OK)
  • Malformed: 400 (Bad Request)
  • Error: 500 (Internal Server Error)

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 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" \

HTTP/1.1 204 No Content

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
  • Success: 204 (No Content)
  • Missing: 404 (Not Found)
  • Error: 500 (Internal Server Error)