Hooks API
NOTE: Requests to the hooks 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 hooks
The /hooks
API endpoint provides HTTP GET access to hook data.
Example
The following example demonstrates a request to the /hooks
API endpoint, resulting in a JSON array that contains hook definitions.
curl -X GET \
http://127.0.0.1:8080/api/core/v2/namespaces/default/hooks \
-H "Authorization: Key $SENSU_API_KEY"
HTTP/1.1 200 OK
[
{
"metadata": {
"name": "nginx-log",
"namespace": "default",
"created_by": "admin"
},
"command": "tail -n 100 /var/log/nginx/error.log",
"timeout": 10,
"stdin": false,
"runtime_assets": null
},
{
"metadata": {
"name": "process-tree",
"namespace": "default",
"created_by": "admin"
},
"command": "ps -eo user,pid,cmd:50,%cpu --sort=-%cpu | head -n 6",
"timeout": 10,
"stdin": false,
"runtime_assets": null
}
]
API Specification
/hooks (GET) | |
---|---|
description | Returns the list of hooks. |
example url | http://hostname:8080/api/core/v2/namespaces/default/hooks |
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 hook
The /hooks
API endpoint provides HTTP POST access to create a hook.
Example
In the following example, an HTTP POST request is submitted to the /hooks
API endpoint to create the hook process-tree
.
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": "process-tree",
"namespace": "default",
"labels": null,
"annotations": null
},
"command": "ps -eo user,pid,cmd:50,%cpu --sort=-%cpu | head -n 6",
"timeout": 10,
"stdin": false
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/hooks
HTTP/1.1 201 Created
API Specification
/hooks (POST) | |
---|---|
description | Creates a Sensu hook. |
example URL | http://hostname:8080/api/core/v2/namespaces/default/hooks |
payload |
|
response codes |
|
Get a specific hook
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 endpoint returns a JSON map that contains the requested :hook
definition (in this example, for the :hook
named process-tree
).
curl -X GET \
http://127.0.0.1:8080/api/core/v2/namespaces/default/hooks/process-tree \
-H "Authorization: Key $SENSU_API_KEY"
HTTP/1.1 200 OK
{
"metadata": {
"name": "process-tree",
"namespace": "default",
"created_by": "admin",
"labels": null,
"annotations": null
},
"command": "ps aux",
"timeout": 10,
"stdin": false
}
API Specification
/hooks/:hook (GET) | |
---|---|
description | Returns the specified hook. |
example url | http://hostname:8080/api/core/v2/namespaces/default/hooks/process-tree |
response type | Map |
response codes |
|
output |
|
Create or update a hook
The /hooks/:hook
API endpoint provides HTTP PUT access to create or update specific :hook
definitions, by hook name.
Example
In the following example, an HTTP PUT request is submitted to the /hooks/:hook
API endpoint to create the hook nginx-log
.
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": "nginx-log",
"namespace": "default",
"labels": null,
"annotations": null
},
"command": "tail -n 100 /var/log/nginx/error.log",
"timeout": 10,
"stdin": false
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/hooks/nginx-log
HTTP/1.1 201 Created
API Specification
/hooks/:hook (PUT) | |
---|---|
description | Creates or updates the specified Sensu hook. |
example URL | http://hostname:8080/api/core/v2/namespaces/default/hooks/nginx-log |
payload |
|
response codes |
|
Delete a hook
The /hooks/:hook
API endpoint provides HTTP DELETE access to delete a check hook from Sensu (specified by the hook name).
Example
The following example shows a request to the /hooks/:hook
API endpoint to delete the hook process-tree
, resulting in a successful HTTP 204 No Content
response.
curl -X DELETE \
http://127.0.0.1:8080/api/core/v2/namespaces/default/hooks/process-tree \
-H "Authorization: Key $SENSU_API_KEY"
HTTP/1.1 204 No Content
API Specification
/hooks/:hook (DELETE) | |
---|---|
description | Removes the specified hook from Sensu. |
example url | http://hostname:8080/api/core/v2/namespaces/default/hooks/process-tree |
response codes |
|