From f0477ec9c4e077e6678ab7a6e89248c15eb9d037 Mon Sep 17 00:00:00 2001 From: Leonard Excoffier <48970393+excoffierleonard@users.noreply.github.com> Date: Wed, 4 Sep 2024 17:04:55 -0400 Subject: [PATCH] feat: added isalivescript with variables. --- .dockerignore | 2 ++ .gitignore | 1 + DOCKERFILE | 18 ++++++++++++++++++ isalive.sh | 26 ++++++++++++++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 isalive.sh diff --git a/.dockerignore b/.dockerignore index e69de29..30bd623 100644 --- a/.dockerignore +++ b/.dockerignore @@ -0,0 +1,2 @@ +.env + diff --git a/.gitignore b/.gitignore index e69de29..4c49bd7 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/DOCKERFILE b/DOCKERFILE index e69de29..109f8d8 100644 --- a/DOCKERFILE +++ b/DOCKERFILE @@ -0,0 +1,18 @@ +FROM debian + +ENV WEBSITES=("google.com" "yahoo.com") + +ENV WEBHOOK_URL="" + +ENV DISCORD_ID="" + +RUN apt update && apt install -y \ + bash \ + curl \ + cron \ + +COPY ./start.sh /start.sh + +CMD ["/start.sh"] + + diff --git a/isalive.sh b/isalive.sh new file mode 100644 index 0000000..352803a --- /dev/null +++ b/isalive.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# List of websites to monitor +websites=$WEBSITES + +# Discord Webhook URL +webhook_url=$WEBHOOK_URL + +# Function to send a message to Discord webhook +send_discord_notification() { + local message=$1 + curl -H "Content-Type: application/json" \ + -X POST \ + -d "{\"content\": \"$message\"}" \ + "$webhook_url" +} + +# Loop through the websites and check their status +for website in "${websites[@]}"; do + response=$(curl -s -o /dev/null -L -w "%{http_code}" --max-time 10 --connect-timeout 5 --insecure "$website") + + if [ "$response" != "200" ]; then + send_discord_notification "$DISCORD_ID Alert: Website $website is down (HTTP $response)" + fi +done +