Initial action

This commit is contained in:
2026-08-10 20:18:50 +02:00
parent 0a2c12aeed
commit 0598aa08c3
2 changed files with 112 additions and 0 deletions
+104
View File
@@ -0,0 +1,104 @@
name: Website Monitor
on:
schedule:
- cron: "*/10 * * * *"
workflow_dispatch:
permissions:
contents: write
jobs:
monitor:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check website
id: check
env:
WEBSITE_URL: ${{ secrets.WEBSITE_URL }}
run: |
set +e
# Follow redirects and fail on HTTP errors.
curl \
--silent \
--show-error \
--location \
--fail \
--max-time 30 \
--connect-timeout 10 \
"$WEBSITE_URL"
EXIT_CODE=$?
if [ "$EXIT_CODE" -eq 0 ]; then
echo "status=up" >> "$GITHUB_OUTPUT"
else
echo "status=down" >> "$GITHUB_OUTPUT"
fi
- name: Handle website status
env:
WEBSITE_STATUS: ${{ steps.check.outputs.status }}
WEBSITE_URL: ${{ secrets.WEBSITE_URL }}
NTFY_URL: ${{ secrets.NTFY_URL }}
NTFY_TOKEN: ${{ secrets.NTFY_TOKEN }}
run: |
if [ -f "./websiteIsDown" ]; then
# Website was previously detected as down.
if [ "$WEBSITE_STATUS" = "up" ]; then
echo "Website is back up."
rm ./websiteIsDown
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add ./websiteIsDown
git commit -m "chore: website is back up"
git push
curl \
--fail \
--silent \
--show-error \
-X POST \
-H "Authorization: Bearer $NTFY_TOKEN" \
-d "Website is back up: $WEBSITE_URL" \
"$NTFY_URL"
else
echo "Website is still down. No notification."
fi
else
# Website was not previously detected as down.
if [ "$WEBSITE_STATUS" = "down" ]; then
echo "Website is down."
touch ./websiteIsDown
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add ./websiteIsDown
git commit -m "chore: website is down"
git push
curl \
--fail \
--silent \
--show-error \
-X POST \
-H "Authorization: Bearer $NTFY_TOKEN" \
-d "Website is down: $WEBSITE_URL" \
"$NTFY_URL"
else
echo "Website is up. Nothing to do."
fi
fi
+8
View File
@@ -1,2 +1,10 @@
# action-ntfy-down # action-ntfy-down
Really simple GitHub actions to alert via ntfy when a website is down. Really simple GitHub actions to alert via ntfy when a website is down.
# How to use
1. Activate actions in your repo.
2. Add the following secrets to your actions
- WEBSITE_URL
- NTFY_URL
- NTFY_TOKEN