Created
November 27, 2018 11:59
-
-
Save renizgo/9b1dff00e160811307728463cf5491c0 to your computer and use it in GitHub Desktop.
Check API Text
This file contains 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/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