Skip to content

Instantly share code, notes, and snippets.

@renizgo
Created November 27, 2018 11:59
Show Gist options
  • Save renizgo/9b1dff00e160811307728463cf5491c0 to your computer and use it in GitHub Desktop.
Save renizgo/9b1dff00e160811307728463cf5491c0 to your computer and use it in GitHub Desktop.
Check API Text
#!/bin/bash
ORIGEM=apis.txt
ERRO=OK
echo "###########" > /var/rundeck/projects/Manutencao/scripts/results.txt
echo "# APIs Tests #" >> /var/rundeck/projects/Manutencao/scripts/results.txt
echo "###########" >> /var/rundeck/projects/Manutencao/scripts/results.txt
for LISTA in $(cat /var/rundeck/projects/Manutencao/scripts/apis.txt)
do
#URL=$(curl -s $LISTA)
#echo "A API URL: $LISTA"
#curl -s $LISTA | jq '.status'
RESULT=`curl -s $LISTA | jq '.status'`
if [ "$RESULT" != "\"Healthy\"" ] ; then
#echo "ERRO NA API: $LISTA"
ERRO="FALHA"
echo "ERRO NA API: $LISTA" >> /var/rundeck/projects/Manutencao/scripts/results.txt
#else
#echo ""
fi
done
if [ $ERRO == "FALHA" ]; then
DADOS=`cat /var/rundeck/projects/Manutencao/scripts/results.txt`
json="{\"text\": \"$DADOS\"}"
curl -s -H "Content-type: application/json" -XPOST https://hooks.slack.com/services/<TOKEN> --data "$json"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment