Skip to content

Internet outage notifications

Paradox: if the internet at home goes down, a notification web service won’t be able to send anything. The solution is to send from a different device: a NAS, a Raspberry Pi with an LTE modem, or a work laptop with an active mobile connection.

  1. On an independent device (with its own fallback channel — an LTE/4G dongle, mobile hotspot) we’ll run the script-watchdog.
  2. It tries every minute to reach the home server/router and an external host (for example, 1.1.1.1).
  3. On state transitions it sends to Notifly.
/usr/local/bin/notifly-net-check
#!/usr/bin/env bash
set -eu
set -a; source /etc/notifly.env; set +a
HOME_HOST="192.168.1.1" # home router
WAN_HOST="1.1.1.1" # external host
STATE=/var/lib/notifly-net.state
ping_ok() { ping -c1 -W2 "$1" >/dev/null 2>&1; }
if ping_ok "$WAN_HOST" && ping_ok "$HOME_HOST"; then NOW=ALL_OK
elif ping_ok "$WAN_HOST" && ! ping_ok "$HOME_HOST"; then NOW=HOME_DOWN
elif ! ping_ok "$WAN_HOST" && ping_ok "$HOME_HOST"; then NOW=WAN_DOWN
else NOW=ALL_DOWN
fi
PREV=$(cat "$STATE" 2>/dev/null || echo ALL_OK)
if [[ "$NOW" != "$PREV" ]]; then
case "$NOW" in
ALL_OK) TITLE="✅ Интернет восстановлен"; PRI=4 ;;
WAN_DOWN) TITLE="⚠️ Нет внешнего интернета"; PRI=7 ;;
HOME_DOWN) TITLE="⚠️ Дом не отвечает"; PRI=8 ;;
ALL_DOWN) TITLE="🔥 Всё лежит"; PRI=10 ;;
esac
curl -fsS -X POST "$NOTIFLY_URL/message?token=$NOTIFLY_TOKEN" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg t "$TITLE" \
--arg m "Состояние: $NOW (было $PREV)" \
--argjson p "$PRI" \
'{title:$t, message:$m, priority:$p}')" >/dev/null
fi
echo "$NOW" > "$STATE"

Cron every minute:

* * * * * /usr/local/bin/notifly-net-check

Alternative: checking from a phone or laptop

Section titled “Alternative: checking from a phone or laptop”

If you don’t have a separate device, you can set up the watchdog on a work laptop — it is almost always connected to a mobile hotspot:

Окно терминала
# checks the home router and sends a push if it's silent for five consecutive minutes
COUNT=0
while true; do
if ping -c1 -W2 home.duckdns.org >/dev/null 2>&1; then
COUNT=0
else
COUNT=$((COUNT+1))
if (( COUNT == 5 )); then
notifly-send "⚠️ Дом не пингуется 5 минут" "" 7
fi
fi
sleep 60
done

If the watchdog is a work Windows laptop with mobile internet. Assumes the function Send-Notifly is configured.

C:\scripts\Notifly-Net-Check.ps1
. $env:USERPROFILE\Documents\WindowsPowerShell\Notifly.ps1
$HomeHost = "192.168.1.1"
$WanHost = "1.1.1.1"
$State = "$env:LOCALAPPDATA\notifly-net.state"
function Ping-Ok($h) {
return Test-Connection -ComputerName $h -Count 1 -Quiet -TimeoutSeconds 2
}
$wanOk = Ping-Ok $WanHost
$homeOk = Ping-Ok $HomeHost
$now = if ($wanOk -and $homeOk) { "ALL_OK" }
elseif ($wanOk -and -not $homeOk) { "HOME_DOWN" }
elseif (-not $wanOk -and $homeOk) { "WAN_DOWN" }
else { "ALL_DOWN" }
$prev = if (Test-Path $State) { Get-Content $State -Raw } else { "ALL_OK" }
$prev = $prev.Trim()
if ($now -ne $prev) {
$info = switch ($now) {
"ALL_OK" { @{ Title = "✅ Интернет восстановлен"; Pri = 4 } }
"WAN_DOWN" { @{ Title = "⚠️ Нет внешнего интернета"; Pri = 7 } }
"HOME_DOWN" { @{ Title = "⚠️ Дом не отвечает"; Pri = 8 } }
"ALL_DOWN" { @{ Title = "🔥 Всё лежит"; Pri = 10 } }
}
Send-Notifly -Title $info.Title -Message "Состояние: $now (было $prev)" -Priority $info.Pri
}
$now | Set-Content $State

Schedule to run every minute:

Окно терминала
$Action = New-ScheduledTaskAction -Execute "powershell.exe" `
-Argument "-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File C:\scripts\Notifly-Net-Check.ps1"
$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) `
-RepetitionInterval (New-TimeSpan -Minutes 1)
Register-ScheduledTask -TaskName "Notifly Net Check" -Action $Action -Trigger $Trigger
  • You’ll find out about an outage before you notice quiet social media.
  • Especially valuable for a home server / NAS: you’re out of town, the power at home went out, the NAS is already offline — and you received a push immediately.
  • Can be integrated with a UPS: when switching to battery send a message estimating “time until shutdown.”
  • Integrate a UPS daemon (apcupsd, nut) — push on switching to battery.
  • Attach mtr output to the problematic node.