Geek Culture
Published in

Geek Culture

Monitoring Websites Part-2 Email Alerting

Introduction:

In this article, we are going to integrate the google SMTP mail server. Also, we will see how to create an email notification if the website goes down or the website TLS certificate expiry is less than a month. If you are visiting for the first time then please go through the first part of this article here.

Audience

Developer, System admin, DevOps. This is a practical hands-on article to monitor websites and email alerts.

Network Setup

  • Blackbox exporter setup, Grafana, Prometheus setup.
  • SMTP server setup with Grafana.
  • Email notification creation for website status.
  • Email notification creation for TLS certificate expiry.

Folder Structure

  • Let’s clone the repo which contains the source code.
git clone https://github.com/cmjagtap/Website-Monitoring

Blackbox exporter setup, Grafana, Prometheus setup.

I have already explained this setup in previous article. I am skipping this step.

SMTP server setup with Grafana

  • If you have followed the correct steps in the above article then, You should be ready with the following dashboard.
Dashboard
  • Now, navigate to grafana.ini and edit the SMTP section as shown in the below picture.
SMTP Server Setup
  • Replace the user with your Gmail address
  • Replace from_address with your Gmail address
  • Add your Gmail password in the password section
  • Restart the Grafana container using the following command, Then
    Grafana will pick your new configuration.
docker restart grafana
Gmail Setting
  • Let’s test our email integration as follows.
  • Navigate to the Grafana dashboard and click on the Bell icon then click on the contact points tab.
Alert Contact Tab
  • Edit the grafana-default-email and add the email address that you want to get notifications.
  • You can add multiple email addresses using comma separation as follows.
Alert Contact Points
  • Now click on the test button on the right side, then click on send notification.
  • Now you should receive the test email from Grafana on your emails as follows.
Grafana email
  • Clicked on save contact point.
  • We have completed Gmail SMTP server integration.

Email notification creation for website status.

  • Let’s create an email notification for websites, Go to the Grafana dashboard and add a new panel.
  • In the panel metric browser add the following command with the website you want to create notification
  • probe_success{instance=”https://github.com"}
  • In legend add {{instance}}
  • Right side top corner select time series

If you won’t see the data by copy-pasting above commands , then try by typing manually.

Create Web Panel
  • Click on save then click on the Alert tab in the same panel and create an alert rule for this panel.
Create Notification Rule
  • Now you should see the following tab
Create Notification Rule
  • In Folder create a new folder name grafana(You are free to select any name)
  • Then see the highlighted condition, it’s basically an HTTP probe value if it goes to zero or below zero then you will be notified.
Create Notification Condition
  • In section 4 you can add custom messages as follows.
Notification Message
  • Now save and exit.
  • We have enabled the email notification for the single website, similarly, you can replicate it for as many you want.

Email notification creation for TLS certificate expiry.

  • Let’s create an email notification for TLS certificate expiry, Go to the Grafana dashboard and add a new panel.
  • In the panel metric browser add the following command with the website you want to track TLS.
  • (probe_ssl_earliest_cert_expiry{instance=”https://github.com"} — time()) /86400
  • In legend add {{instance}}
  • Right side top corner select time series
  • The graph represents UNIX timestamp of the certificate and we are subtracting the current UNIX timestamp using the time(). So, will get the exact remaining seconds of the certificate. then we are dividing 86400 after this will get the remaining days of certificate expiry.
  • Click on save then click on the Alert tab in the same panel and create an alert rule for this panel.
  • In Folder create a new folder name grafana(You are free to select any name)
  • Then see the highlighted condition, it’s basically a condition if the certificate expiry is less than 30 days then you will be notified.

Note: The highlighted value is 30 days.

  • In section 4 you can add custom messages as follows.
  • Now save and exit.
  • We have enabled the email notification for the single website's TLS, similarly, you can replicate it for as many you want.
  • Now You should see the below Dashboard. The green Heart represents notification status. if the website goes down then it will turn to red heartbreak and you will be notified via email.

Clean up

Execute the following shell script to clean all docker containers and remove the BlackBox exporter.

./clean.sh

Summary

We have seen how to monitor websites and TLS certificates. Also, seen how to integrate the SMTP mail server and enable email notifications for the various services.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store