This tutorial will show you how to integrate Monika with SMTP so you can receive notifications from Monika straight to your email.
In order to start using Google Mail as your Monika notification channel, you need to prepare these:
First, go to the Less secure app access section of your Google Account. You might need to sign in first using your Google account. Then, turn on the “Allow less secure apps” like so:
Now that we enabled the ‘Allow less secure apps’ option, it is time to create a Monika configuration. As an example, let’s use a configuration from our previous article: Be alerted when your authentication API is slow with Monika: A guide for chaining request
The configuration above will hit the /login endpoint with a JSON request body and hit an API using the token from the previous request’s response in the Authorization header. If you look closely in the notifications block, it only shows you desktop notifications when an alert is triggered. What we are going to do is to add a new notification channel, which is SMTP. Here is an example of an SMTP notification block:
\- id: unique-id-smtptype: smtpdata:recipients: \[RECIPIENT\_EMAIL\_ADDRESS\]hostname: smtp.mail.comport: 587username: SMTP\_USERNAMEpassword: SMTP\_PASSWORD
smtp
, desktop
, etc.)["monika@gmail.com", "symon@gmail.com"]
)smtp.gmail.com
as we are going to be using Google Mail SMTP465
or 587
Now that we know the structure of the SMTP notification block, it’s time to update our Monika configuration:
notifications:- id: unique-id-smtptype: smtpdata:recipients: ["recipient-1@example.com", "recipient-2@example.com"]hostname: smtp.gmail.comport: 587username: denny@example.compassword: p455w0rdprobes:- id: sample_loginname: Sample Loginrequests:- method: POSTurl: https://reqres.in/api/loginbody:email: "eve.holt@reqres.in"password: "cityslicka"headers:Content-Type: application/jsonalerts:- query: response.time > 600message: Login API Response time is {{ response.time }} ms, expecting less than 60>- query: response.status != 200message: Login API Status code is not 200. Please check the service status!- method: GETurl: https://reqres.in/api/users/2headers:Authorization: Bearer {{ response.[0].data.token }}alerts:- query: response.time > 500message: Get User API Response time is {{ response.time }} ms, expecting less than>- query: response.status != 200message: Get User API Status code is not 200. Please check the service status!alerts:- query: response.time > 10000message: Please check your internet connection
Save the configuration file as monika.yml
and run the configuration. When an alert is triggered, it should send a recovery or incident email to the recipients you have configured.
Congratulations! You can now send the alert notification using Google Mail SMTP!
PT Artha Rajamas Mandiri (Hyperjump) is an open-source-first company providing engineering excellence service. We aim to build and commercialize open-source tools to help companies streamline, simplify, and secure the most important aspects of its modern DevOps practices.
Copyright © 2024 Hyperjump Tech. All Rights Reserved.