Added monitoring script(#3882).

This commit is contained in:
Christian P. MOMON 2020-12-26 22:11:51 +01:00 committed by root
parent 67c8d8a3ea
commit f34781ca18

View File

@ -0,0 +1,39 @@
#!/bin/bash
#
json=$(curl -s https://status.chapril.org/api/v1/version)
#
regexp='.*"data":\s*"([^"]+)".*'
if [[ $json =~ $regexp ]]; then
currentVersion=${BASH_REMATCH[1]}
else
currentVersion=
fi
#
regexp='.*"tag_name":\s*"v([^"]+)".*'
if [[ $json =~ $regexp ]]; then
lastVersion=${BASH_REMATCH[1]}
else
lastVersion=
fi
#echo "$currentVersion"
#echo "$lastVersion"
if [ -z "$currentVersion" ]; then
echo "WARNING : current version not found."
result=1
elif [ -z "$lastVersion" ]; then
echo "WARNING : last version not found."
result=1
elif [ $currentVersion = $lastVersion ]; then
echo "OK"
result=0
else
echo "WARNING : new version available, current is $currentVersion, last is $lastVersion."
result=1
fi
exit $result