Skip to content

Instantly share code, notes, and snippets.

@jspaleta
Created August 29, 2019 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jspaleta/c69fd53474835e0e6f811c6e67ea664a to your computer and use it in GitHub Desktop.
Save jspaleta/c69fd53474835e0e6f811c6e67ea664a to your computer and use it in GitHub Desktop.
Sensu Check Status to Metric Mutator
#!/bin/sh
#
# check_status_as_metric.sh
# optionally set measurement, field
# Ex:
# check_status_as_metric.sh measurement="${entity_name}" field="${check_name}.status"
#
event=$(cat /dev/stdin)
check_status=$(echo $event | jq .check.status)
check_name=$(echo $event | jq .check.metadata.name | tr -d '"')
check_proxy_entity_name=$(echo $event | jq .check.proxy_entity_name | tr -d '"')
check_timestamp=$(echo $event | jq .check.issued | tr -d '"')
entity_name=$(echo $event | jq .entity.metadata.name | tr -d '"')
host_name=$(echo $event | jq .entity.system.hostname | tr -d '"')
CONFIG=( "$@" )
# Update Envvars using cmdline args
for line in "${CONFIG[@]}"; do
eval "$line"
done
[ -z ${measurement} ] && measurement="${host_name}"
[ -z ${field} ] && field="${check_name}.status"
point="[{ \"name\" : \"${measurement}.${field}\", \"timestamp\" : ${check_timestamp}, \"value\" : $check_status , \"tags\" : null }]"
echo $event | jq ".metrics.points += $point"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment