From c7be517e3413d5492620a6f2a8405c9eb69461b1 Mon Sep 17 00:00:00 2001 From: david Date: Mon, 18 Dec 2023 17:52:54 +0100 Subject: [PATCH] Initial commit --- Dockerfile | 17 +++++++++++++++++ README.md | 3 +++ docker-compose.yml | 18 ++++++++++++++++++ ntfy.sh | 28 ++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 docker-compose.yml create mode 100755 ntfy.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..96d8109 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..017d736 --- /dev/null +++ b/README.md @@ -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`. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a9af68b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +version: "3.7" + +services: + dpinger-container: + build: + context: . + image: local/dpinger-container:latest + command: -i -L 15 -D 80 + 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 diff --git a/ntfy.sh b/ntfy.sh new file mode 100755 index 0000000..add81e1 --- /dev/null +++ b/ntfy.sh @@ -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