Created
August 29, 2019 00:08
-
-
Save jspaleta/c69fd53474835e0e6f811c6e67ea664a to your computer and use it in GitHub Desktop.
Sensu Check Status to Metric Mutator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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