1
1
Fork 0
dpinger-container/ntfy.sh

29 lines
691 B
Bash
Executable File

#!/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