Recently, I was looking for a solution to notify me when a website is down and when it is back up. I found a few solutions, but they all had a learning curve. So I thought of an alternative solution using Google App Script, which I had recently learned about.
- Can run every 5 minutes.
- Can send emails when the website is down.
I wasn’t sure if the first requirement was possible with Google App Script, but the other two were. After reading the documentation, I found that it was possible to create a time-based trigger for a script.
Steps to follow:
- Create a new Google App Script project.
- Create a function to track the website. Here is an example:
- Go to the “Triggers” menu in the left sidebar of the Google App Script project.
- Click the “Add Trigger” button and select the function to run.
- Choose the options to run the trigger every 5 minutes and click “Save”
This above code uses the UrlFetchApp service to make HTTP requests to the websites and check their status. it stores the value of each trigger in a variable so that whenver site goes live again it can send email of website backed up.
You can also check the logs for each trigger execution in the “Execution” menu on the left side of the project.
In conclusion, Google App Script is a useful tool for creating a customized website tracker that can notify the user when a website is down. The process of setting up the tracker is straightforward and the logs can be easily accessed to track the execution of the function. this basic functionality can be enhanced more to record the status in a csv file. also interesting graphs and charts can be made using that data.
Upptime is one of the good open-source alternative which can be used to monitor a website. it uses github actions to make sure the website is up and creates a issue if website is down for some reason. it also logs the information about the website speed.