The author selected the Apache Software Foundation to receive a donation as part of the Write for DOnations program.
When you have critical websites you’ll want to know when they are experiencing any issues so you can fix them before there’s an impact on your users. One way to receive notifications is to set up alerts through a text-based chat system.
Discord is a hosted chat system similar to Slack. With Discord, you can set up a free messaging system that lets you communicate with text messages, images, audio, and video. While it offers premium features, you can sign up for free, and it has clients available for Windows, macOS, Linux, Android, and iOS.
In this tutorial, you will configure your own Discord server, create a Discord webhook, write a Bash script that will check the status of a list of websites, and test notifications from your server to your Discord channel.
Before you begin this guide you’ll need the following:
Once you have opened your Discord account you can create your own private Discord server.
First, log in to your Discord account in your browser or launch your Discord app and click on the Create a server button.
Then pick a name for your server and click on the Create a server button.
Next, you will configure your Discord webhook. The webhooks are unique URLs that you can use to link services together. Discord’s webhooks allow you to automate your messages and send data updates to your Discord text channels.
In this tutorial, you will send a notification to your webhook when a specific service on your server goes down, and Discord will make sure that you get those messages on your channel.
To create a webhook you have to first click on your channel and then click on the Edit Channel button right next to your channel’s name.
Then click on the Webhooks tab and click the Create Webhook button.
After that, pick a name for your webhook, in this tutorial we’ll use Alerts
as this is what our Bash script will do—alert us in the case that one of our websites goes down.
Copy your webhook URL and save it for later. Finally, click the Save button.
You now have your Discord account, server, and webhook. You can now move on to create a test file for your script to monitor.
If you don’t have your own website to test already, complete this step to add a test file to check how your monitoring script will work. Make sure to run these commands on your apache-server.
First, create the test file with the following command:
nano /var/www/your_domain/test
Add some content to your file, so you can check it’s working:
test
test
Save and exit the file.
Now navigate to http://``your_domain``/test
in your browser to make sure you can receive the text in the test
file.
In the next step, you’ll start to build your monitoring script.
#ubuntu