Hooks API

The /hooks API endpoint

/hooks (GET)

The /hooks API endpoint provides HTTP GET access to hook data.

EXAMPLE

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

curl -s http://127.0.0.1:8080/api/core/v2/namespaces/default/hooks -H "Authorization: Bearer TOKEN"
[
  {
    "metadata": {
      "name": "process-tree",
      "namespace": "default",
      "labels": null,
      "annotations": null
    },
    "command": "ps aux",
    "timeout": 10,
    "stdin": false
  }
]

API Specification

/hooks (GET)
description Returns the list of hooks.
example url http://hostname:8080/api/core/v2/namespaces/default/hooks
response type Array
response codes
  • Success: 200 (OK)
  • Error: 500 (Internal Server Error)
output
[
  {
    "metadata": {
      "name": "process-tree",
      "namespace": "default",
      "labels": null,
      "annotations": null
    },
    "command": "ps aux",
    "timeout": 10,
    "stdin": false
  },
  {
    "metadata": {
      "name": "nginx-log",
      "namespace": "default",
      "labels": null,
      "annotations": null
    },
    "command": "tail -n 100 /var/log/nginx/error.log",
    "timeout": 10,
    "stdin": false
  }
]

/hooks (POST)

/hooks (POST)
description Create a Sensu hook.
example URL http://hostname:8080/api/core/v2/namespaces/default/hooks
payload
{
  "metadata": {
    "name": "process-tree",
    "namespace": "default",
    "labels": null,
    "annotations": null
  },
  "command": "ps aux",
  "timeout": 10,
  "stdin": false
}
response codes
  • Success: 200 (OK)
  • Malformed: 400 (Bad Request)
  • Error: 500 (Internal Server Error)

The /hooks/:hook API endpoint

/hooks/:hook (GET)

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

EXAMPLE

In the following example, querying the /hooks/:hook API returns a JSON Map containing the requested :hook definition (in this example: for the :hook named process-tree).

curl -s http://127.0.0.1:8080/api/core/v2/namespaces/default/hooks/process-tree -H "Authorization: Bearer TOKEN"
{
  "metadata": {
    "name": "process-tree",
    "namespace": "default",
    "labels": null,
    "annotations": null
  },
  "command": "ps aux",
  "timeout": 10,
  "stdin": false
}

API Specification

/hooks/:hook (GET)
description Returns a hook.
example url http://hostname:8080/api/core/v2/namespaces/default/hooks/process-tree
response type Map
response codes
  • Success: 200 (OK)
  • Missing: 404 (Not Found)
  • Error: 500 (Internal Server Error)
output
{
  "metadata": {
    "name": "process-tree",
    "namespace": "default",
    "labels": null,
    "annotations": null
  },
  "command": "ps aux",
  "timeout": 10,
  "stdin": false
}

/hooks/:hook (PUT)

API Specification

/hooks/:hook (PUT)
description Create or update a Sensu hook.
example URL http://hostname:8080/api/core/v2/namespaces/default/hooks/process-tree
payload
{
  "metadata": {
    "name": "process-tree",
    "namespace": "default",
    "labels": null,
    "annotations": null
  },
  "command": "ps aux",
  "timeout": 10,
  "stdin": false
}
response codes
  • Success: 201 (Created)
  • Malformed: 400 (Bad Request)
  • Error: 500 (Internal Server Error)

/hooks/:hook (DELETE)

API Specification

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