diff --git a/monitor-ynh b/monitor-ynh index f3a4a25..5a4ef28 100755 --- a/monitor-ynh +++ b/monitor-ynh @@ -3,11 +3,11 @@ source ./monitor-ynh-settings IPV4=false -if ping -c 1 9.9.9.9 > /dev/null && dig +short A wikipedia.fr > /dev/null; then +if ping -c 1 9.9.9.9 &> /dev/null && dig +short A wikipedia.fr &> /dev/null; then IPV4=true fi IPV6=false -if ping6 -c 1 2620:0:862:ed1a::1 > /dev/null && dig +short A wikipedia.fr > /dev/null; then +if ping6 -c 1 2620:0:862:ed1a::1 &> /dev/null && dig +short A wikipedia.fr &> /dev/null; then IPV6=true fi #============================================================================== @@ -65,10 +65,10 @@ check_ping () { $IPV6 && check_ping 6 $@ else if [ "$1" -eq "4" ]; then - ping -c 1 $3 > /dev/null + ping -c 1 $3 &> /dev/null register_event $? $2 "${FUNCNAME[0]} $*" "[ipv$1] $3 no ping" else - ping6 -c 1 $3 > /dev/null + ping6 -c 1 $3 &> /dev/null register_event $? $2 "${FUNCNAME[0]} $*" "[ipv$1] $3 no ping" fi fi @@ -98,7 +98,7 @@ register_event () { local count=$(redis-cli --raw incr $var_name) local nb_ignored=$2 local reminder=$(( $count - $nb_ignore + 1 )) - echo "[KO] ${@: -1}" + #echo "[KO] ${@: -1}" reminder="$(echo obase=2\;$reminder | bc | tail -c +2)0" if [ $count -eq $2 ]; then alert " ${@: -1}" @@ -107,12 +107,12 @@ register_event () { fi fi } - +alert_msg="" +newline=$'\n' # Send on alert # Usage: alert ID_TEXT alert() { - echo "[mail] $1" - echo "$1" | mail -s "[ljf-MONITOR]$1" $MAIL &> /dev/null + alert_msg="${alert_msg}[alert] $1${newline}" } @@ -177,4 +177,6 @@ check_200 2 https://repo.labriqueinter.net/ check_content 2 https://install.labriqueinter.net/ 7c2a6659857dcddee846403bdb10b7fe check_200 2 https://wiki.labriqueinter.net/doku.php - +if [[ ! -z "$alert_msg" ]]; then + echo "$alert_msg" | mail -s "[$PSEUDO-MONITOR] !!!" $MAIL &> /dev/null +fi