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.
What we’ll do
Section titled “What we’ll do”- On an independent device (with its own fallback channel — an LTE/4G dongle, mobile hotspot) we’ll run the script-watchdog.
- It tries every minute to reach the home server/router
and an external host (for example,
1.1.1.1). - On state transitions it sends to Notifly.
Script notifly-net-check
Section titled “Script notifly-net-check”#!/usr/bin/env bashset -euset -a; source /etc/notifly.env; set +a
HOME_HOST="192.168.1.1" # home routerWAN_HOST="1.1.1.1" # external hostSTATE=/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_OKelif ping_ok "$WAN_HOST" && ! ping_ok "$HOME_HOST"; then NOW=HOME_DOWNelif ! ping_ok "$WAN_HOST" && ping_ok "$HOME_HOST"; then NOW=WAN_DOWNelse NOW=ALL_DOWNfi
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/nullfiecho "$NOW" > "$STATE"Cron every minute:
* * * * * /usr/local/bin/notifly-net-checkAlternative: 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 minutesCOUNT=0while 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 60doneWindows: PowerShell + Test-Connection
Section titled “Windows: PowerShell + Test-Connection”If the watchdog is a work Windows laptop with mobile internet.
Assumes the function Send-Notifly is configured.
. $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 $StateSchedule 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 $TriggerBenefits
Section titled “Benefits”- 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.”
What to improve next
Section titled “What to improve next”- Integrate a UPS daemon (
apcupsd,nut) — push on switching to battery. - Attach
mtroutput to the problematic node.