Strategies for Discord Webhooks attain Notifications to suit your web site position on Ubuntu 18.04

Strategies for Discord Webhooks attain Notifications to suit your web site position on Ubuntu 18.04

The author picked the Apache computer software Foundation to receive a contribution as part of the prepare for contributions program.

Introduction

Once you have vital websites you’ll wish to know when they’re experiencing any problems to fix all of them before there’s an impact on your own people. The easiest way to receive notifications is to arranged alerts through a text-based cam program.

Dissension are a managed chat system comparable to Slack. With dissension, you’ll be able to set up a no cost messaging program that lets you communicate with texting, photos, sound, and video clip. Although it provides premiums properties, it is possible to sign up for free of charge, and contains consumers available for screens, macOS, Linux, Android, and iOS.

Within this information, you may arrange your own personal Discord machine, write a Discord webhook, create a Bash program that will check out the status of a list of sites, and examination notifications from your server your dissension channel.

Prerequisites

Before starting this guide you’ll require next:

An Ubuntu 18.04 server which will work the tracking software and communicate with dissension (monitor-server). You can easily set this server right up by using this first host set-up instructions.

In the event that you don’t have actually an internet site you desire to keep track of yet, developed the apache-server with how exactly to Install the Apache online host on Ubuntu 18.04 and make certain to complete Step 5 on starting an online variety.

a dissension levels. You can visit the Discord enrollment web page to sign up for a totally free dissension accounts.

Step 1 — Starting Their Discord Webhook

After you have exposed your dissension profile you are able to create your own private dissension servers.

1st, get on your own dissension profile within internet browser or begin your own dissension application and then click regarding Make a server key.

Next pick a reputation for the host and click throughout the Create a host button.

Then, could arrange their dissension webhook. The webhooks is distinctive URLs which you can use to link solutions together. Discord’s webhooks make it easier to automate the communications and send information changes towards Dissension book stations.

Within this guide, you’ll send a notice your webhook when a specific solution on your machine falls, and Discord will make sure that you get those emails on the station.

To create a webhook you have to first select their route immediately after which click on the Edit Channel option right next to your own channel’s identity.

Next click the Webhooks tab and then click the generate Webhook button.

After that, select a name to suit your webhook, inside tutorial we’ll use notifications as this is what our Bash program can do—alert us in the event any particular one in our web pages falls.

Duplicate your own webhook URL and rescue it for later on. Ultimately, click the Save key.

You’ve got the dissension account, host, and webhook. Anybody can move on to make a test file for the script to monitor.

2 — Creating a Test document (Optional)

If you don’t get own internet site to test currently, complete this to include an examination document to check on just how the spying software will continue to work. Be sure to run these commands on your own apache-server.

Very first, create the examination file with all the after command:

Add some articles your file, to test it is operating:

Rescue and leave the file.

Now browse to http:// your_domain /test within browser to make sure you can receive the book inside the examination file.

Within the next step, you’ll begin to construct your spying software.

Step 3 — Generating Their Monitoring Program

Now that you’ve set up the webhook, linked here you’ll go ahead and create your Bash software that will check the response signal of web sites. When all sites return a condition different from 200 okay , your own program will be sending a request on Discord webhook so you will receive a notification in your dissension station.

Note: you could utilize almost every other program coding language to construct a script in this way.

Very first SSH into your monitor-server that you’re using to perform their spying software.

Start by generating a file at home folder. We’ll name the file check_status.sh inside guide.

Along with your favorite book editor open the file:

For the program loader to distinguish this executable file as a Bash software, create these range to the top from the file:

All lines you start with a # were a remark. The statements include elective, but creating commentary within program can certainly make it easier for people to comprehend what the script do:

After that, establish your Discord webhook as a changeable. Put the URL you copied early in the day for the webhook:

As you’ll perhaps use this script to test the condition of several website, create a changeable called websites_list and shop the domain names or IP addresses of the web sites that you want to monitor. If you’re utilizing the elective test file within this information, remember to incorporate /test after your own domain or IP address:

In the case you are keeping track of more than one website, you can add additional names of domain or IP contact on websites_list changeable and use room as a separator:

Today you’ll want to loop through directory of web pages and check their own updates. To do so include these for circle your document:

This for loop will go through each product within the websites_list varying and check the condition in the website using the curl command.

The echo $status_code report will print-out the responses status of curl order. If the websites is actually operating as you expected the curl order will go back an answer rule 200 okay , meaning that the website is working. Usually you’ll see another impulse signal.

Inside the for loop, add an if statement to check if the response code is 200 or not. If the response laws are 200 next which means website is operating and also you wouldn’t need a Discord notice. Put this amazing conditional block your document:

If you will find any issues with the website then you’ll become another type of response rule, in this event you’ll wish to obtain an alerts via your Discord webhook.

To send the notification you should use the curl order to submit A BLOG POST demand towards the dissension webhook Address.

Incorporate the following curl request in your if statement:

Now let’s analyze various arguments: