mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Add possibility to send mail when server or proxy is down/up
This commit is contained in:
parent
34dca22728
commit
051577195e
5 changed files with 162 additions and 5 deletions
|
@ -79,8 +79,26 @@ while true; do
|
|||
nocontact=""
|
||||
[ "${last}" -ge "${retry}" ] || [ "$(uci -q get openmptcprouter.omr.v2ray)" = "" ] && {
|
||||
_log "V2Ray is up (can contact via http ${host})"
|
||||
OMR_TRACKER_STATUS_MSG="V2Ray is up (can contact via http ${host})"
|
||||
uci -q set openmptcprouter.omr.v2ray="up"
|
||||
uci -q commit openmptcprouter.omr
|
||||
/etc/init.d/openmptcprouter-vps set_vps_firewall
|
||||
mail_alert="$(uci -q get omr-tracker.proxy.mail_alert)"
|
||||
#[ -z "$mail_alert" ] && mail_alert="$(uci -q get omr-tracker.defaults.mail_alert)"
|
||||
[ "$mail_alert" = "1" ] && [ -n "$(uci -q get mail.default.to)" ] && {
|
||||
OMR_SYSNAME="$(uci -q get system.@system[0].hostname)"
|
||||
if [ "$(uci -q get omr-tracker.defaults.mail_up_subject)" != "" ] && [ "$(uci -q get omr-tracker.defaults.mail_up_message)" != "" ]; then
|
||||
mail_subject="$(uci -q get omr-tracker.defaults.mail_up_subject)"
|
||||
mail_subject=`echo $mail_subject | sed -e "s/%SYSNAME%/$OMR_SYSNAME/g" -e "s/%INTERFACE%/V2Ray Proxy/g" -e "s/%DEVICE%/Shadowsocks Proxy/g" -e "s/%MESSAGE%/$OMR_TRACKER_STATUS_MSG/g"`
|
||||
mail_message="$(uci -q get omr-tracker.defaults.mail_up_message)"
|
||||
mail_message=`echo $mail_message | sed -e "s/%SYSNAME%/$OMR_SYSNAME/g" -e "s/%INTERFACE%/V2Ray Proxy/g" -e "s/%DEVICE%/Shadowsocks Proxy/g" -e "s/%MESSAGE%/$OMR_TRACKER_STATUS_MSG/g"`
|
||||
echo -e "Subject: ${mail_subject}\n\n${mail_message}" | sendmail $(uci -q get mail.default.to)
|
||||
else
|
||||
echo -e "Subject: $OMR_SYSNAME: V2Ray Proxy is UP." | sendmail $(uci -q get mail.default.to)
|
||||
fi
|
||||
}
|
||||
script_alert_up="$(uci -q get omr-tracker.proxy.script_alert_up)"
|
||||
[ -n "$script_alert_up" ] && eval $script_alert_up
|
||||
}
|
||||
if [ -z "$($IPTABLES -w -t nat -L -n 2>/dev/null | grep v2r)" ]; then
|
||||
_log "Reload V2Ray rules"
|
||||
|
@ -95,8 +113,10 @@ while true; do
|
|||
[ "${last}" -ge "${retry}" ] && {
|
||||
if [ -n "$($IPTABLES -w -t nat -L -n 2>/dev/null | grep v2r)" ]; then
|
||||
_log "V2Ray is down (can't contact via http ${nocontact})"
|
||||
OMR_TRACKER_STATUS_MSG="V2Ray is down (can't contact via http ${nocontact})"
|
||||
uci -q set openmptcprouter.omr.v2ray="down"
|
||||
uci -q commit openmptcprouter.omr
|
||||
/etc/init.d/openmptcprouter-vps set_vps_firewall
|
||||
/etc/init.d/v2ray rules_down 2> /dev/null
|
||||
_get_ip
|
||||
server_ping=false
|
||||
|
@ -104,7 +124,24 @@ while true; do
|
|||
_ping_server $server
|
||||
if [ "$server_ping" = false ]; then
|
||||
_log "Server ($server) seems down, no answer to ping"
|
||||
OMR_TRACKER_STATUS_MSG="${OMR_TRACKER_STATUS_MSG} - Server ($server) seems down, no answer to ping"
|
||||
fi
|
||||
mail_alert="$(uci -q get omr-tracker.proxy.mail_alert)"
|
||||
#[ -z "$mail_alert" ] && mail_alert="$(uci -q get omr-tracker.defaults.mail_alert)"
|
||||
[ "$mail_alert" = "1" ] && [ -n "$(uci -q get mail.default.to)" ] && {
|
||||
OMR_SYSNAME="$(uci -q get system.@system[0].hostname)"
|
||||
if [ "$(uci -q get omr-tracker.defaults.mail_down_subject)" != "" ] && [ "$(uci -q get omr-tracker.defaults.mail_down_message)" != "" ]; then
|
||||
mail_subject="$(uci -q get omr-tracker.defaults.mail_down_subject)"
|
||||
mail_subject=`echo $mail_subject | sed -e "s/%SYSNAME%/$OMR_SYSNAME/g" -e "s/%INTERFACE%/V2Ray Proxy/g" -e "s/%DEVICE%/V2Ray Proxy/g" -e "s/%MESSAGE%/$OMR_TRACKER_STATUS_MSG/g"`
|
||||
mail_message="$(uci -q get omr-tracker.defaults.mail_down_message)"
|
||||
mail_message=`echo $mail_message | sed -e "s/%SYSNAME%/$OMR_SYSNAME/g" -e "s/%INTERFACE%/V2Ray Proxy/g" -e "s/%DEVICE%/V2Ray Proxy/g" -e "s/%MESSAGE%/$OMR_TRACKER_STATUS_MSG/g"`
|
||||
echo -e "Subject: ${mail_subject}\n\n${mail_message}" | sendmail $(uci -q get mail.default.to)
|
||||
else
|
||||
echo -e "Subject: $OMR_SYSNAME: V2Ray Proxy is down\n\nConnection failure of V2Ray proxy detected. The reason is \"$OMR_TRACKER_STATUS_MSG\"." | sendmail $(uci -q get mail.default.to)
|
||||
fi
|
||||
}
|
||||
script_alert_down="$(uci -q get omr-tracker.proxy.script_alert_down)"
|
||||
[ -n "$script_alert_down" ] && eval $script_alert_down
|
||||
sleep $wait_test
|
||||
fi
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue