Filters API

The /filters API endpoint

/filters (GET)

The /filters API endpoint provides HTTP GET access to filter data.

EXAMPLE

The following example demonstrates a request to the /filters API, resulting in a JSON Array containing filter definitions.

curl -s http://127.0.0.1:8080/api/core/v2/namespaces/default/filters -H "Authorization: Bearer TOKEN"
[
  {
    "metadata": {
      "name": "state_change_only",
      "namespace": "default",
      "labels": null,
      "annotations": null
    },
    "action": "allow",
    "expressions": [
      "event.check.occurrences == 1"
    ],
    "runtime_assets": []
  }
]

API Specification

/filters (GET)
description Returns the list of filters.
example url http://hostname:8080/api/core/v2/namespaces/default/filters
response type Array
response codes
  • Success: 200 (OK)
  • Error: 500 (Internal Server Error)
output
[
  {
    "metadata": {
      "name": "state_change_only",
      "namespace": "default",
      "labels": null,
      "annotations": null
    },
    "action": "allow",
    "expressions": [
      "event.check.occurrences == 1"
    ],
    "runtime_assets": []
  },
  {
    "metadata": {
      "name": "development_filter",
      "namespace": "default",
      "labels": null,
      "annotations": null
    },
    "action": "deny",
    "expressions": [
      "event.entity.metadata.namespace == 'production'"
    ],
    "runtime_assets": []
  }
]

/filters (POST)

/filters (POST)
description Create a Sensu filter.
example URL http://hostname:8080/api/core/v2/namespaces/default/filters
payload
{
  "metadata": {
    "name": "development_filter",
    "namespace": "default",
    "labels": null,
    "annotations": null
  },
  "action": "deny",
  "expressions": [
    "event.entity.metadata.namespace == 'production'"
  ],
  "runtime_assets": []
}
response codes
  • Success: 200 (OK)
  • Malformed: 400 (Bad Request)
  • Error: 500 (Internal Server Error)

The /filters/:filter API endpoint

/filters/:filter (GET)

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

EXAMPLE

In the following example, querying the /filters/:filter API returns a JSON Map containing the requested :filter definition (in this example: for the :filter named state_change_only).

curl -s http://127.0.0.1:8080/api/core/v2/namespaces/default/filters/state_change_only -H "Authorization: Bearer TOKEN"
{
  "metadata": {
    "name": "state_change_only",
    "namespace": "default",
    "labels": null,
    "annotations": null
  },
  "action": "allow",
  "expressions": [
    "event.check.occurrences == 1"
  ],
  "runtime_assets": []
}

API Specification

/filters/:filter (GET)
description Returns a filter.
example url http://hostname:8080/api/core/v2/namespaces/default/filters/state_change_only
response type Map
response codes
  • Success: 200 (OK)
  • Missing: 404 (Not Found)
  • Error: 500 (Internal Server Error)
output
{
  "metadata": {
    "name": "state_change_only",
    "namespace": "default",
    "labels": null,
    "annotations": null
  },
  "action": "allow",
  "expressions": [
    "event.check.occurrences == 1"
  ],
  "runtime_assets": []
}

/filters/:filter (PUT)

API Specification

/filters/:filter (PUT)
description Create or update a Sensu filter.
example URL http://hostname:8080/api/core/v2/namespaces/default/filters/development_filter
payload
{
  "metadata": {
    "name": "development_filter",
    "namespace": "default",
    "labels": null,
    "annotations": null
  },
  "action": "deny",
  "expressions": [
    "event.entity.metadata.namespace == 'production'"
  ],
  "runtime_assets": []
}
response codes
  • Success: 201 (Created)
  • Malformed: 400 (Bad Request)
  • Error: 500 (Internal Server Error)

/filters/:filter (DELETE)

API Specification

/filters/:filter (DELETE)
description Removes a filter from Sensu given the filter name.
example url http://hostname:8080/api/core/v2/namespaces/default/filters/state_change_only
response codes
  • Success: 202 (Accepted)
  • Missing: 404 (Not Found)
  • Error: 500 (Internal Server Error)