-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1398 from lukeckk/development
Script to check website status and send email to users if website is down
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
# * | ||
# * This Source Code Form is subject to the terms of the Mozilla Public | ||
# * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# * | ||
|
||
# This check the website status at hour level. | ||
# This should be copied to /etc/ or /etc/cron.hourly/ or /etc/cron.daily and the copy renamed so that its function will be clear to admins. | ||
|
||
# Check if a URL is provided as an argument | ||
if [ -z "$1" ]; then | ||
echo "Error: No URL provided. Usage: $0 URL-to-check" | ||
exit 1 | ||
fi | ||
|
||
URL=$1 | ||
|
||
# The absolute path the project root directory (OED) | ||
cd '/example/path/to/project/OED' | ||
|
||
# The following line should NOT need to be edited except by devs or if you have an old system with only docker-compose. | ||
docker compose run --rm web npm run --silent checkWebsiteStatus -- $URL &>> /dev/null & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
const { log } = require('../log'); | ||
const WEBSITE_URL = process.argv[2]; | ||
|
||
async function checkWebsite() { | ||
try { | ||
const response = await fetch(WEBSITE_URL, { method: 'HEAD' }); | ||
|
||
if (!response.ok) { | ||
const errorMessage = `The server at ${WEBSITE_URL} is down.`; | ||
// Log the error using Logger class | ||
log.error(errorMessage); | ||
} | ||
} catch (error) { | ||
const errorMessage = `Failed to reach ${WEBSITE_URL}. Error: ${error.message}`; | ||
log.error(errorMessage, error); | ||
} | ||
} | ||
|
||
checkWebsite(); |