mirror of
https://github.com/YunoHost/monitor-ynh.git
synced 2024-09-03 20:06:24 +02:00
[enh] Send just one mail
This commit is contained in:
parent
8fff1c70a2
commit
d5367a54fa
1 changed files with 11 additions and 9 deletions
20
monitor-ynh
20
monitor-ynh
|
@ -3,11 +3,11 @@
|
||||||
source ./monitor-ynh-settings
|
source ./monitor-ynh-settings
|
||||||
|
|
||||||
IPV4=false
|
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
|
IPV4=true
|
||||||
fi
|
fi
|
||||||
IPV6=false
|
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
|
IPV6=true
|
||||||
fi
|
fi
|
||||||
#==============================================================================
|
#==============================================================================
|
||||||
|
@ -65,10 +65,10 @@ check_ping () {
|
||||||
$IPV6 && check_ping 6 $@
|
$IPV6 && check_ping 6 $@
|
||||||
else
|
else
|
||||||
if [ "$1" -eq "4" ]; then
|
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"
|
register_event $? $2 "${FUNCNAME[0]} $*" "[ipv$1] $3 no ping"
|
||||||
else
|
else
|
||||||
ping6 -c 1 $3 > /dev/null
|
ping6 -c 1 $3 &> /dev/null
|
||||||
register_event $? $2 "${FUNCNAME[0]} $*" "[ipv$1] $3 no ping"
|
register_event $? $2 "${FUNCNAME[0]} $*" "[ipv$1] $3 no ping"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -98,7 +98,7 @@ register_event () {
|
||||||
local count=$(redis-cli --raw incr $var_name)
|
local count=$(redis-cli --raw incr $var_name)
|
||||||
local nb_ignored=$2
|
local nb_ignored=$2
|
||||||
local reminder=$(( $count - $nb_ignore + 1 ))
|
local reminder=$(( $count - $nb_ignore + 1 ))
|
||||||
echo "[KO] ${@: -1}"
|
#echo "[KO] ${@: -1}"
|
||||||
reminder="$(echo obase=2\;$reminder | bc | tail -c +2)0"
|
reminder="$(echo obase=2\;$reminder | bc | tail -c +2)0"
|
||||||
if [ $count -eq $2 ]; then
|
if [ $count -eq $2 ]; then
|
||||||
alert " ${@: -1}"
|
alert " ${@: -1}"
|
||||||
|
@ -107,12 +107,12 @@ register_event () {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
alert_msg=""
|
||||||
|
newline=$'\n'
|
||||||
# Send on alert
|
# Send on alert
|
||||||
# Usage: alert ID_TEXT
|
# Usage: alert ID_TEXT
|
||||||
alert() {
|
alert() {
|
||||||
echo "[mail] $1"
|
alert_msg="${alert_msg}[alert] $1${newline}"
|
||||||
echo "$1" | mail -s "[ljf-MONITOR]$1" $MAIL &> /dev/null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -177,4 +177,6 @@ check_200 2 https://repo.labriqueinter.net/
|
||||||
check_content 2 https://install.labriqueinter.net/ 7c2a6659857dcddee846403bdb10b7fe
|
check_content 2 https://install.labriqueinter.net/ 7c2a6659857dcddee846403bdb10b7fe
|
||||||
check_200 2 https://wiki.labriqueinter.net/doku.php
|
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
|
||||||
|
|
Loading…
Reference in a new issue