From 7eb26fd5fa03041978d77c787065195dbdfb2777 Mon Sep 17 00:00:00 2001 From: Eliezer Croitoru Date: Fri, 1 Nov 2024 14:40:49 +0200 Subject: [PATCH] 1 --- .gitignore | 1 + Dockerfile | 22 ++++++++++++++++ Makefile | 15 +++++++++++ blackbox.yml | 65 +++++++++++++++++++++++++++++++++++++++++++++++ build.sh | 34 +++++++++++++++++++++++++ container-name | 1 + publish.sh | 11 ++++++++ start-blackbox.sh | 3 +++ start.sh | 3 +++ supervisord.conf | 21 +++++++++++++++ username | 1 + 11 files changed, 177 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 blackbox.yml create mode 100644 build.sh create mode 100644 container-name create mode 100644 publish.sh create mode 100644 start-blackbox.sh create mode 100644 start.sh create mode 100644 supervisord.conf create mode 100644 username diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aaf4570 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build-dir/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d4d41ca --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM alpine:latest + +ARG TARGETOS +ARG TARGETARCH + +RUN apk update && apk add --no-cache supervisor && mkdir -p /opt/blackbox_exporter/etc + +ADD build-dir/${TARGETOS}/${TARGETARCH}/blackbox_exporter /opt/blackbox_exporter/ + +ADD supervisord.conf /etc/supervisord.conf + +ADD start-blackbox.sh /start-blackbox.sh + +ADD start.sh /start.sh + +RUN chmod +x /opt/blackbox_exporter/blackbox_exporter + +EXPOSE 9115 + +WORKDIR / + +CMD ["/bin/sh", "/start.sh"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0bacb72 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +all: init-buildx build publish + +build: + bash build.sh +publish: + bash publish.sh + +init-buildx: clean-buildx + docker buildx create --name mybuilder + docker buildx use mybuilder + docker buildx inspect --bootstrap + docker buildx ls +clean-buildx: + docker buildx rm mybuilder;true + diff --git a/blackbox.yml b/blackbox.yml new file mode 100644 index 0000000..415dde8 --- /dev/null +++ b/blackbox.yml @@ -0,0 +1,65 @@ +modules: + http_2xx: + prober: http + + http_2xx_3xx_403: + prober: http + http: + valid_http_versions: ["HTTP/1.1", "HTTP/2.0"] + valid_status_codes: [ 200, 204, 301,302,307,308,403] + no_follow_redirects: false + + http_post_2xx: + prober: http + http: + method: POST + tcp_connect: + prober: tcp + tcp: + preferred_ip_protocol: "ip4" + pop3s_banner: + prober: tcp + tcp: + query_response: + - expect: "^+OK" + tls: true + tls_config: + insecure_skip_verify: false + grpc: + prober: grpc + grpc: + tls: true + preferred_ip_protocol: "ip4" + grpc_plain: + prober: grpc + grpc: + tls: false + service: "service1" + ssh_banner: + prober: tcp + tcp: + query_response: + - expect: "^SSH-2.0-" + - send: "SSH-2.0-blackbox-ssh-check" + irc_banner: + prober: tcp + tcp: + query_response: + - send: "NICK prober" + - send: "USER prober prober prober :prober" + - expect: "PING :([^ ]+)" + send: "PONG ${1}" + - expect: "^:[^ ]+ 001" + icmp: + prober: icmp + icmp_ttl5: + prober: icmp + timeout: 5s + icmp: + ttl: 5 + tcp_connect_tls: + prober: tcp + tcp: + tls: true + preferred_ip_protocol: "ip4" + diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..6c02ef3 --- /dev/null +++ b/build.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +echo "cleaning up" + +rm -vrf build-dir/linux/{amd64,arm64,arm,armv6} + +mkdir -p build-dir/linux/{amd64,arm64,arm,armv6} + +#Download latest version of Rustdesk-server +LATEST=$(curl https://api.github.com/repos/prometheus/blackbox_exporter/releases/latest -s | grep "tag_name"| awk '{print substr($2, 2, length($2)-3) }') + +wget "https://github.com/prometheus/blackbox_exporter/releases/download/${LATEST}/blackbox_exporter-$( echo -n ${LATEST}|sed -e"s@^v@@g").linux-amd64.tar.gz" -O "build-dir/linux/amd64/blackbox_exporter-linux-amd64.tar.gz" +cd build-dir/linux/amd64/ && tar xvf "blackbox_exporter-linux-amd64.tar.gz" && cd - +chmod +x build-dir/linux/amd64/blackbox_exporter-*.linux-amd64/blackbox_exporter +mv -v build-dir/linux/amd64/blackbox_exporter-*.linux-amd64/blackbox_exporter build-dir/linux/amd64/ + +wget "https://github.com/prometheus/blackbox_exporter/releases/download/${LATEST}/blackbox_exporter-$( echo -n ${LATEST}|sed -e"s@^v@@g").linux-arm64.tar.gz" -O "build-dir/linux/arm64/blackbox_exporter-linux-arm64.tar.gz" +cd build-dir/linux/arm64/ && tar xvf "blackbox_exporter-linux-arm64.tar.gz" && cd - +chmod +x build-dir/linux/arm64/blackbox_exporter-*.linux-arm64/blackbox_exporter +mv -v build-dir/linux/arm64/blackbox_exporter-*.linux-arm64/blackbox_exporter build-dir/linux/arm64/ + +wget "https://github.com/prometheus/blackbox_exporter/releases/download/${LATEST}/blackbox_exporter-$( echo -n ${LATEST}|sed -e"s@^v@@g").linux-armv7.tar.gz" -O "build-dir/linux/arm/blackbox_exporter-linux-armv7.tar.gz" +cd build-dir/linux/arm/ && tar xvf "blackbox_exporter-linux-armv7.tar.gz" && cd - +chmod +x build-dir/linux/arm/blackbox_exporter-*.linux-armv7/blackbox_exporter +mv -v build-dir/linux/arm/blackbox_exporter-*.linux-armv7/blackbox_exporter build-dir/linux/arm/ + +wget "https://github.com/prometheus/blackbox_exporter/releases/download/${LATEST}/blackbox_exporter-$( echo -n ${LATEST}|sed -e"s@^v@@g").linux-armv6.tar.gz" -O "build-dir/linux/armv6/blackbox_exporter-linux-armv6.tar.gz" +cd build-dir/linux/armv6/ && tar xvf "blackbox_exporter-linux-armv6.tar.gz" && cd - +chmod +x build-dir/linux/armv6/blackbox_exporter-*.linux-armv6/blackbox_exporter +mv -v build-dir/linux/armv6/blackbox_exporter-*.linux-armv6/blackbox_exporter build-dir/linux/armv6/ + + + +echo "Downloaded blackbox-exporter files" diff --git a/container-name b/container-name new file mode 100644 index 0000000..9664072 --- /dev/null +++ b/container-name @@ -0,0 +1 @@ +blackbox_exporter diff --git a/publish.sh b/publish.sh new file mode 100644 index 0000000..757abd8 --- /dev/null +++ b/publish.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -x + +name="$(head -1 container-name)" +docker_username="$(head -1 username)" + +docker login +docker buildx build -t "${docker_username}/${name}:latest" --platform linux/amd64,linux/arm64,linux/arm/v7 --push . + +set +x diff --git a/start-blackbox.sh b/start-blackbox.sh new file mode 100644 index 0000000..c0c2b3c --- /dev/null +++ b/start-blackbox.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +/opt/blackbox_exporter/blackbox_exporter --config.file=/opt/blackbox_exporter/etc/blackbox.yml diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..b555d88 --- /dev/null +++ b/start.sh @@ -0,0 +1,3 @@ +#!/usr/sh + +/usr/bin/supervisord -c /etc/supervisord.conf diff --git a/supervisord.conf b/supervisord.conf new file mode 100644 index 0000000..0c6f9a7 --- /dev/null +++ b/supervisord.conf @@ -0,0 +1,21 @@ +[unix_http_server] +file=/tmp/supervisor.sock + +[supervisorctl] +serverurl=unix:///tmp/supervisor.sock + +[rpcinterface:supervisor] +supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface + +[supervisord] +nodaemon=true +user=root +minfds=1024 +minprocs=200 + +[program:blackbox] +command=/bin/sh /start-blackbox.sh +directory=/data +user=root +autostart=true +autorestart=true diff --git a/username b/username new file mode 100644 index 0000000..2737d98 --- /dev/null +++ b/username @@ -0,0 +1 @@ +elicro