1
1
Fork 0

Initial commit

This commit is contained in:
david 2023-12-18 17:52:54 +01:00
commit c7be517e34
4 changed files with 66 additions and 0 deletions

17
Dockerfile Normal file
View File

@ -0,0 +1,17 @@
# Build dpinger from Github
FROM alpine:latest AS build
RUN apk --no-cache add clang gcc git libc-dev make && \
cd tmp && \
git clone --depth 1 https://github.com/dennypage/dpinger.git && \
cd dpinger && \
make all
# Build final Docker image
FROM alpine:latest
RUN apk --no-cache add curl
COPY --from=build /tmp/dpinger/dpinger /usr/local/bin/
COPY ntfy.sh /usr/local/bin/
ENTRYPOINT ["/usr/local/bin/dpinger","-f", "-C", "/usr/local/bin/ntfy.sh"]

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# dpinger-container
Docker image for [dpinger](https://github.com/dennypage/dpinger) with [ntfy.sh](https://ntfy.sh) integration. The image is based off of `alpine:latest`.

18
docker-compose.yml Normal file
View File

@ -0,0 +1,18 @@
version: "3.7"
services:
dpinger-container:
build:
context: .
image: local/dpinger-container:latest
command: -i <optional-identifier> -L 15 -D 80 <ip-address>
restart: unless-stopped
environment:
- NTFY_URL=https://ntfy.sh/test
# This is only needed if your Docker setup needs to go through a VPN to reach the Internet
networks:
default:
driver: bridge
driver_opts:
com.docker.network.driver.mtu: 1420

28
ntfy.sh Executable file
View File

@ -0,0 +1,28 @@
#!/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