1
1
dpinger-container/ntfy.sh

29 lines
691 B
Bash
Raw Normal View History

2023-12-18 17:52:54 +01:00
#!/bin/ash
# Input data
ID="$1"
[[ "$6" ]] && shift
IP="$1"
ALERT=$2
LAT=$3
LAT=$((LAT/1000))
#DEV=$4
LOSS=$5
# Set notification content
if [[ $ALERT -eq 0 ]]; then
EMOJI="green_circle"
MESSAGE=$(printf "Link returned to nominal condition.\nPacket loss: %i%%\nLatency: %ims\n" $LOSS $LAT)
elif [[ $LOSS -lt 100 ]]; then
EMOJI="orange_circle"
MESSAGE=$(printf "Link is experiencing packet loss or high latency.\nPacket loss: %i%%\nLatency: %ims\n" $LOSS $LAT)
else
EMOJI="red_circle"
MESSAGE=$(printf "Link is down.\n")
fi
# Send notification
if [[ "$NTFY_URL" ]]; then
curl -fsS -m 10 --retry 5 -q -H "title: $ID" -H "tags: $EMOJI" -d "$MESSAGE" -o /dev/null "$NTFY_URL"
fi