Skip to content

Instantly share code, notes, and snippets.

@javierwilson
Last active June 3, 2020 06:03
Show Gist options
  • Save javierwilson/9235d776beab8ef532c18667adc44740 to your computer and use it in GitHub Desktop.
Save javierwilson/9235d776beab8ef532c18667adc44740 to your computer and use it in GitHub Desktop.
Runs check, sends output to events API
#!/bin/bash
rootdir="/usr/local/bin/checks"
checkfile=${1//[^a-zA-Z0-9_]/}
checkfile="${rootdir}/$checkfile"
checkname=${1//[^a-zA-Z0-9_]/}
if [ $# -lt 2 ]; then
echo "Usage:"
script=`basename "$0"`
echo "${script} <check_script> <check_name> [arg1] [arg2] [argN]"
exit 1
fi
if [ ! -f $checkfile ]; then
echo "File not found! $checkfile"
exit 1
fi
shift
shift
args="$@"
output=`$checkfile $args`
output=${output//[\"\']/}
status="$?"
curl -X POST \
-H 'Content-Type: application/json' \
-d "{
\"check\": {
\"metadata\": {
\"name\": \"${checkname}\"
},
\"status\": ${status},
\"output\": \"${output}\"
}
}" \
http://127.0.0.1:3031/events
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment