We have Sensu v0.26.3-1 in one of our critical legacy application running on Ubuntu 18.04. I’m trying to create a custom handler, like below, that will execute a bash script when keepalive fails for a host:
{
"handlers": {
"search": {
"command": "/etc/sensu/plugins/search.sh",
"type": "pipe",
"filters": [
"occurrences"
],
"severities": [
"critical",
"unknown",
"ok"
],
"handle_flapping": false,
"handle_silenced": false
}
}
}
The script ‘search.sh’ is:
#!/bin/bash
# Get HTTP Basic Auth token
TOKEN=$(cat /etc/sensu_svc_account)
curl -X POST https://<redacted> -H "Authorization: Basic $TOKEN" -H "Content-Type: application/json" -d '{ "ruleset": "sensu", "host": "'"$HOST"'", "service": "Keepalive Check", "state": "CRITICAL", "description": "CRITICAL: Keepalive check on '"$HOST"' failed", "service_id": "2677", "alert_source": "SENSU" }' >> /tmp/sensu_nexus_auth.log
echo ' ' >> /tmp/sensu_auth.log
My query:
I want to know how I can pass on the hostname of the host that has failed Sensu’s keepalive check (via $HOST variable) to the bash script.
PS: The format of the POST request needs to be maintained.
Thanks in advance.
Re,