Forget predefined alerts, now you can create your own alert when your API is down with Monika

Denny Pradipta
Hyperjump Tech
Published in
3 min readSep 22, 2021
Photo by Possessed Photography on Unsplash

Read part two of this article: Advanced Monika alert queries: A guide to operators and helpers

If you’ve been using Monika for the past few weeks, you may have seen status-not-2xx and response-time-greater-than-x-ms in one of our articles. It is the flag for detecting if our services are not returning status code 200 and their response time is greater than a specific milliseconds.

With Monika v1.6.0 has been released, those two flags are old news. We mentioned before in our previous article that we have some improvements in alerting. Now we could create more flexible queries according to your needs. Without further ado, let’s dig this feature deeper!

Source

Monika uses Filtrex for defining the query and uses Handlebars to render our custom alert message. To create an alert query, you need to understand the available properties you can use for creating an alert. Below is an example response from probing https://reqres.in/api/users/2 in Monika:

Example response

As you can see, there are five properties that you can use: response size, status code, time, body, and headers. With that said, let’s create a simple configuration to probe URL with these conditions:

  • We want to use the Desktop notification channel
  • We want to probe this URL: https://reqres.in/api/users/2. This URL will return a user with ID “2” and status code 200.
  • We would like to be notified when the response status code is not 200
  • We would like to be notified when the response time is larger than 200 milliseconds
  • We would like to be notified when the ID from the response body data is not 3 (this is just for testing purposes)
  • We want to be notified when the incident or recovery has been triggered two times

Yes, we can now use YAML for our configuration file. In the configuration above, you can see that you can now create your custom alert message. Instead of the plain “Response time is x ms, expecting less than x milliseconds,” we can define the alert message whatever we want. Save the configuration above as monika.yml

Now that we have our configuration created, time to run it using Monika by running monika -c monika.yml and let’s see what will happen:

The end result

Congratulations! Now you can create flexible alerts according to your specifications.

Conclusion

With the power of Filtrex and Handlebars, the capabilities of alert triggers are endless. Don’t forget to check out their documentation page so that you can experiment with the alert query and message.

Do you find any bugs or errors when experimenting? You can submit an issue on our Github page. Better yet, you can make a Pull Request if you want to contribute to Monika, considering next month is Hacktoberfest. Yes, we are looking at you, freebies hunters.

That is all for today. See you next article!

See ya! — Source

Read part two of this article: Advanced Monika alert queries: A guide to operators and helpers

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.

--

--

Denny Pradipta
Hyperjump Tech

Full-stack developer who loves to explore new technologies. Uses MongoDB, Express, React, and Node daily. Regularly writing for Hyperjump Technologies.