Files
action-ntfy-down/.github/workflows/action.yml
T
2026-08-10 20:40:27 +02:00

107 lines
2.7 KiB
YAML

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: |
if curl \
--silent \
--show-error \
--location \
--fail \
--max-time 30 \
--connect-timeout 10 \
"$WEBSITE_URL"
then
echo "Website is UP"
echo "status=up" >> "$GITHUB_OUTPUT"
else
echo "Website is DOWN"
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: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if [ -f "./websiteIsDown" ]; then
# Website was previously down
if [ "$WEBSITE_STATUS" = "up" ]; then
echo "Website is back up."
rm ./websiteIsDown
git add ./websiteIsDown
git commit -m "chore: website is back up"
git push
echo "Sending notification..."
curl \
--fail \
--silent \
--show-error \
--request POST \
--header "Authorization: Bearer $NTFY_TOKEN" \
--data "Website is back up: $WEBSITE_URL" \
"$NTFY_URL"
else
echo "Website is still down. No notification."
fi
else
# Website was previously up
if [ "$WEBSITE_STATUS" = "down" ]; then
echo "Website is down."
touch ./websiteIsDown
git add ./websiteIsDown
git commit -m "chore: website is down"
git push
echo "Sending notification..."
curl \
--fail \
--silent \
--show-error \
--request POST \
--header "Authorization: Bearer $NTFY_TOKEN" \
--data "Website is down: $WEBSITE_URL" \
"$NTFY_URL"
else
echo "Website is up. Nothing to do."
fi
fi