The author chosen the Apache applications basis to receive a contribution included in the prepare for DOnations plan.
Introduction
When you’ve got vital web pages you’ll want to know while they are experiencing any issues to correct all of them before there’s a visible impact on your consumers. One method to obtain notifications will be arranged notifications through a text-based chat program.
Dissension is actually a managed speak program much like Slack. With Discord, you’ll put up a no cost texting system that allows you to keep in touch with sms, graphics, sound, and videos. Although it offers superior characteristics, you can easily sign up for free, and it has customers designed for windowpanes, macOS, Linux, Android, and apple’s ios.
In this tutorial, could configure your own Discord machine, create a Discord webhook, write a Bash software that will check out the status of a listing of web pages, and test notifications out of your machine to your Discord station.
Prerequisites
Before you begin this informative guide you’ll require the following:
An Ubuntu 18.04 servers that will operate the tracking script and consult with Discord (monitor-server). You can easily arranged this servers up by following this original host Setup guidelines.
Any time you don’t bring an internet site you desire to supervise yet, build the apache-server with Simple tips to apply the Apache internet servers on Ubuntu 18.04 and make sure to accomplish action 5 on installing a virtual number.
a Discord account. You can check out the dissension enrollment web page to join a totally free Discord profile.
Step 1 — Creating The Dissension Webhook
After you’ve unwrapped your own dissension membership you can make your very own exclusive Discord machine.
Very first, get on your own Discord accounts within web browser or release the Discord application and click throughout the build a host switch.
Then pick a reputation for the host and click about Create a server button.
Subsequent, you certainly will configure their dissension webhook. The webhooks are unique URLs which you can use to connect treatments collectively. Discord’s webhooks allow you to speed up your own information and submit facts updates your Dissension book networks.
Within this information, you certainly will deliver a notice towards webhook when a particular provider on your server goes down, and dissension will ensure that you will get those emails on your own channel.
Generate a webhook you have to first click their station after which click on the change route button appropriate near to the channel’s label.
Subsequently click the Webhooks loss and click the Make Webhook option.
Then, choose a name for your webhook, within this tutorial we’ll use notifications since this is what the Bash script can do—alert us in case that certain your web pages decreases.
Duplicate their webhook URL and conserve they for later on. At long last, click the conserve option.
You now have your own Discord membership, host, and webhook. It’s simple to proceed to establish a test apply for your program to keep track of.
2 — producing a Test document (Optional)
Should you don’t get own website to check currently, complete this action to include an examination file to check on how your spying program is going to work. Always manage these commands in your apache-server.
Initially, create the examination file using following demand:
Increase material to your file, to scan it is operating:
Conserve and leave the document.
Today navigate to http:// your_domain /test inside internet browser to ensure that you can get the book inside test file.
In the next action, you’ll beginning to build your spying script.
3 — Creating Your Own Monitoring Script
Now you’ve set up your webhook, you’ll go on and make your Bash script that will look into the responses rule of one’s web pages. In the event that any of the sites return an updates distinct from 200 OK , your own script will be sending a request to your Discord webhook you will receive a notification within dissension station.
Note: make use of some other programming language to construct a software along these lines.
Very first SSH into your own monitor-server that you’re making use of to operate their spying program.
Begin by creating a document at home folder. We’ll call the file check_status.sh within this information.
Together with your favorite book editor available the file:
Your program loader to identify this executable file as a Bash software, put listed here line to the top of document:
All lines you start with a # were an opinion. The responses become elective, but having comments within software are likely to make it more convenient for other individuals to know exactly what the script really does:
Further, establish your own Discord webhook as a variable. Add the Address you duplicated before for your webhook:
As you’ll possibly utilize this script to evaluate the position of multiple web pages, make an adjustable called websites_list and shop the domain names or IP address contact information on the internet sites that you want observe. If you’re making use of the optional test file within information, make sure to include /test after your domain name or internet protocol address:
In the event you are keeping track of multiple web site, you can add more names of domain or IP details into the websites_list variable and employ area as a separator:
Now you’ll need loop through variety of website and check their own condition. To achieve this incorporate the following for loop towards file:
This for circle is certainly going through each object when you look at the websites_list varying and check the condition with the websites together with the curl order.
The echo $status_code report will print the response updates in the curl demand. If the websites was operating as you expected the curl demand will return a reply laws 200 OK , meaning that the web site is ready to go. Otherwise you’ll receive another responses code.
In the as circle, include a provided statement to check in the event that responses rule try 200 or otherwise not. When the impulse laws try 200 then which means that the website was operating and you also wouldn’t require a Discord notification. Put the next conditional block to your file:
If discover any issues with website after that you’ll see yet another impulse code, contained in this celebration you’ll want to obtain a notice via your dissension webhook.
To transmit the notification you should use the curl order add AN ARTICLE demand to your dissension webhook URL.
Incorporate the subsequent curl consult inside your if statement:
Today let’s read the many arguments: