[enh] Ignore first checks and if the host can't ping

This commit is contained in:
ljf 2018-02-19 21:11:40 +01:00
parent 6a01b21ec4
commit ebfc4ffa62
2 changed files with 122 additions and 86 deletions

View file

@ -1,6 +1,8 @@
# monitor-ynh # monitor-ynh
A small infra monitoring tool A small infra monitoring tool
You need to install bc and redis-server.
You need to configure a cron like this: You need to configure a cron like this:
``` ```

View file

@ -9,121 +9,155 @@ MAIL=""
#============================================================================== #==============================================================================
# Check if it's always the same HTTP content # Check if it's always the same HTTP content
# usage: check_content URL HASH # usage: check_content [IP_VERSION] NB_IGNORED URL HASH
check_content () { check_content () {
check_content4 $1 $2 if (( $# < 4 ));then
check_content6 $1 $2 check_content 4 $@
} check_content 6 $@
else
# Same but just on ipv4 hash="$(curl -$1 -s $3 | md5sum | cut -d ' ' -f1)"
check_content4 () { [ "$hash" == "$4" ]
hash="$(curl -4 -s $1 | md5sum | cut -d ' ' -f1)" register_event $? $2 "${FUNCNAME[0]} $*" "[ipv$1] Content of $3 has changed"
[ "$hash" == "$2" ] ||
alert "$1 $hash" $MAIL
sleep 3s
}
# Same but just on ipv4
check_content6 () {
hash6="$(curl -6 -s $1 | md5sum | cut -d ' ' -f1)"
[ "$hash6" == "$2" ] ||
alert "$1 $hash6 ipv6" $MAIL
sleep 3s sleep 3s
fi
} }
# Check if dig A request return the correct answer # Check if dig A request return the correct answer
# usage: check_dig NAMESERVER DOMAIN IPv4 # usage: check_dig [IP_VERSION] NB_IGNORED NAMESERVER DOMAIN IPv4
check_dig () { check_dig () {
hash="$(dig +short @$1 A $2)" if (( $# < 5 ));then
hash6="$(dig -6 +short @$1 A $2)" check_dig 4 $@
[ "$hash" == "$3" ] || check_dig 6 $@
alert "dns $1 $hash" $MAIL else
[ "$hash6" == "$3" ] || hash="$(dig -$1 +short @$3 A $4)"
alert "dns $1 $hash6 ipv6" $MAIL [ "$hash" == "$5" ]
register_event $? $2 "${FUNCNAME[0]} $*" "[ipv$1] DNS server $3 may not work"
sleep 1s sleep 1s
fi
} }
# Check if it returns a 200 answer # Check if it returns a 200 answer
# usage: check_dig URL # usage: check_dig [IP_VERSION] NB_IGNORED URL
check_200 () { check_200 () {
[ "$(curl -4 -s -I -w '%{http_code}' -o /dev/null $1)" == "200" ] || if (( $# < 3 ));then
alert "$1 ipv4" $MAIL check_200 4 $@
sleep 3s check_200 6 $@
[ "$(curl -6 -s -I -w '%{http_code}' -o /dev/null $1)" == "200" ] || else
alert "$1 ipv6" $MAIL [ "$(curl -$1 -s -I -w '%{http_code}' -o /dev/null $3)" == "200" ]
register_event $? $2 "${FUNCNAME[0]} $*" "[ipv$1] $3 call fails"
sleep 3s sleep 3s
fi
} }
# Check if the machine ping # Check if the machine ping
# usage: check_ping DOMAIN_OR_IP # usage: check_ping [IP_VERSION] NB_IGNORED DOMAIN_OR_IP
check_ping () { check_ping () {
ping -c 1 $1 > /dev/null || if (( $# < 3 ));then
alert "$1 ipv4" $MAIL check_ping 4 $@
ping6 -c 1 $1 > /dev/null || check_ping 6 $@
alert "$1 ipv6" $MAIL else
ping -$1 -c 1 $3 > /dev/null
register_event $? $2 "${FUNCNAME[0]} $*" "[ipv$1] $3 no ping"
fi
} }
# Send an alert to the admin # Check freespace of the host
alert () { freespace () {
echo "$1 has changed or not reachable" | mail -s "[ljf-MONITOR] $1 has changed or not reachable" $2 freespace="$(df --output=avail / | sed -n '2 p')"
(($freespace < $2))
register_event $? $1 "${FUNCNAME[0]} $*" "Missing space $freespace"
} }
# Get the id of the monitored things
# Usage: get_id ID_TEXT
get_id () {
echo "$*" | sha256sum | cut -d ' ' -f1
}
# Send an register_event to the admin
# Usage: register_event TEST_VALUE NB_IGNORED ID_TEXT ALERT_TEXT
register_event () {
local var_name=$(get_id $3)
if [ "$1" -eq "0" ]; then
redis-cli set $var_name 0 > /dev/null
else
local count=$(redis-cli --raw incr $var_name)
local nb_ignored=$2
local reminder=$(( $count - $nb_ignore + 1 ))
reminder="$(echo obase=2\;$reminder | bc | tail -c +2)0"
if [ $count -eq $2 ]; then
alert " ${@: -1}"
elif [ $count -gt $nb_ignore ] && [ $reminder -eq 0 ]; then
alert "[Reminder] ${@: -1}"
fi
fi
}
# Send on alert
# Usage: alert ID_TEXT
alert() {
echo "$1" | mail -s "[ljf-MONITOR]$1" $MAIL &> /dev/null
}
ping -c 1 9.8.9.8 > /dev/null || dig +short A wikipedia.fr > /dev/null || exit 1
#============================================================================== #==============================================================================
# Configuration # Configuration
#============================================================================== #==============================================================================
# Check All server ping # Check All server ping
check_ping bearnaise.yunohost.org check_ping 2 bearnaise.yunohost.org
check_ping aioli.yunohost.org check_ping 2 aioli.yunohost.org
check_ping demo.yunohost.org check_ping 2 demo.yunohost.org
check_ping forum.yunohost.org check_ping 2 forum.yunohost.org
#check_ping tartare.yunohost.org #ipv6 issue #check_ping tartare.yunohost.org #ipv6 issue
# Check critic services (needed for yunohost instances works correctly) # Check critic services (needed for yunohost instances works correctly)
check_dig ns0.yunohost.org toto.noho.st 81.57.118.36 check_dig 2 ns0.yunohost.org toto.noho.st 81.57.118.36
check_dig ns0.yunohost.org toto.nohost.me 162.243.7.71 check_dig 2 ns0.yunohost.org toto.nohost.me 162.243.7.71
#check_dig ns1.yunohost.org toto.noho.st 81.57.118.36 #check_dig 2 ns1.yunohost.org toto.noho.st 81.57.118.36
#check_dig ns1.yunohost.org toto.nohost.me 162.243.7.71 #check_dig 2 ns1.yunohost.org toto.nohost.me 162.243.7.71
check_content https://repo.yunohost.org/ 1477866e988c7180d486afec7bd4341c check_content 2 https://repo.yunohost.org/ 1477866e988c7180d486afec7bd4341c
check_content https://dyndns.yunohost.org/ c9b426d468e2145a212032c16bebc26f check_content 2 https://dyndns.yunohost.org/ c9b426d468e2145a212032c16bebc26f
check_content4 https://ip.yunohost.org/ 32453f31e928721f8c272c6dda5f86e6 check_content 4 2 https://ip.yunohost.org/ 32453f31e928721f8c272c6dda5f86e6
check_content6 https://ip6.yunohost.org/ 0340bdddba91963e24f153adaf3c4570 check_content 6 2 https://ip6.yunohost.org/ 0340bdddba91963e24f153adaf3c4570
check_content6 https://ipv6.yunohost.org/ 0340bdddba91963e24f153adaf3c4570 check_content 6 2 https://ipv6.yunohost.org/ 0340bdddba91963e24f153adaf3c4570
check_200 https://app.yunohost.org/official.json check_200 2 https://app.yunohost.org/official.json
check_200 https://app.yunohost.org/community.json check_200 2 https://app.yunohost.org/community.json
check_200 https://app.yunohost.org/list.json check_200 2 https://app.yunohost.org/list.json
# Check for install resources # Check for install resources
check_content https://install-app.yunohost.org/ b215745d9fdd5302d2b1f95083d74604 check_content 2 https://install-app.yunohost.org/ b215745d9fdd5302d2b1f95083d74604
check_content https://paste.yunohost.org/ 6d6f3a20399719cd0cfbd4f165de076c check_content 2 https://paste.yunohost.org/ 6d6f3a20399719cd0cfbd4f165de076c
check_200 https://install.yunohost.org/ check_200 2 https://install.yunohost.org/
check_content https://install.yunohost.org/install_yunohost 4c53314cd822fff7423821e08f0c850d check_content 2 https://install.yunohost.org/install_yunohost 4c53314cd822fff7423821e08f0c850d
check_content https://build.yunohost.org/ 207d7c46e03352d98dd533fe38f9bb4c check_content 2 https://build.yunohost.org/ 207d7c46e03352d98dd533fe38f9bb4c
check_content https://build.yunohost.org/yunohost-jessie-201701261126-sdraspi-stable.zip.sum cf2e8d4c40fbee7bb57ac4541751e989 check_content 2 https://build.yunohost.org/yunohost-jessie-201701261126-sdraspi-stable.zip.sum cf2e8d4c40fbee7bb57ac4541751e989
check_content https://build.yunohost.org/yunohost-jessie-0127171259-amd64-stable.iso.sum 6d07211e77e4051b880925719d8bb314 check_content 2 https://build.yunohost.org/yunohost-jessie-0127171259-amd64-stable.iso.sum 6d07211e77e4051b880925719d8bb314
check_content https://build.yunohost.org/yunohost-jessie-0127171609-i386-stable.iso.sum 2bebadec817843b942a5bf4a7b7b8c7e check_content 2 https://build.yunohost.org/yunohost-jessie-0127171609-i386-stable.iso.sum 2bebadec817843b942a5bf4a7b7b8c7e
# Check for public website, support tools # Check for public website, support tools
check_200 https://forum.yunohost.org/ check_200 2 https://forum.yunohost.org/
check_200 https://yunohost.org/ check_200 2 https://yunohost.org/
check_content https://www.yunohost.org/ a718c83022dda2cc03813d97ea9f3a9a check_content 2 https://www.yunohost.org/ a718c83022dda2cc03813d97ea9f3a9a
check_content https://ports.yunohost.org/ ffc3113a26780253c9f005523dc39fc8 check_content 2 https://ports.yunohost.org/ ffc3113a26780253c9f005523dc39fc8
check_content https://im.yunohost.org/logs/ 4b0a139edf5c86f2e0e5f5b915082a0d check_content 2 https://im.yunohost.org/logs/ 4b0a139edf5c86f2e0e5f5b915082a0d
check_content https://chat.yunohost.org/ feafc193207604dc21bd20ca2077a7ce check_content 2 https://chat.yunohost.org/ feafc193207604dc21bd20ca2077a7ce
#check_content https://demo.yunohost.org/yunohost/sso/ c4cb70333b081ebef35ab2d32e941d9e #check_content 2 https://demo.yunohost.org/yunohost/sso/ c4cb70333b081ebef35ab2d32e941d9e
# Check for contribution tools # Check for contribution tools
#check_200 https://dev.yunohost.org/ #check_200 2 https://dev.yunohost.org/
check_200 http://vinaigrette.yunohost.org/ check_200 2 http://vinaigrette.yunohost.org/
check_200 https://dash.yunohost.org/ check_200 2 https://dash.yunohost.org/
check_200 https://ci-apps.yunohost.org/jenkins/ check_200 2 https://ci-apps.yunohost.org/jenkins/
#check_200 https://ci-core.yunohost.org/ #check_200 2 https://ci-core.yunohost.org/
check_content https://list.yunohost.org/listinfo d1f6166e91acbbb75dbee8f6db472e4d check_content 2 https://list.yunohost.org/listinfo d1f6166e91acbbb75dbee8f6db472e4d
check_200 https://wekan.yunohost.org/b/ufMZHMyRpfCqssFY5/yunohost check_200 2 https://wekan.yunohost.org/b/ufMZHMyRpfCqssFY5/yunohost
check_200 https://translate.yunohost.org/ check_200 2 https://translate.yunohost.org/
# Check for internetcube services # Check for internetcube services
check_200 https://repo.internetcu.be/ check_200 2 https://repo.internetcu.be/
check_200 https://labriqueinter.net/ check_200 2 https://labriqueinter.net/
check_200 https://repo.labriqueinter.net/ check_200 2 https://repo.labriqueinter.net/
check_content https://install.labriqueinter.net/ 8535d71123c772afaf708de02ce97d30 check_content 2 https://install.labriqueinter.net/ 8535d71123c772afaf708de02ce97d30
check_200 https://wiki.labriqueinter.net/doku.php check_200 2 https://wiki.labriqueinter.net/doku.php