Alerts are the types of conditions that will trigger Monika to send notifications. It is an array defined in the config file
monika.yml like so.
You can define two types of alerts: request alerts and probe alerts
Request alerts are
alerts configurations that are scoped under the
requests key. Alerts defined under a specific request will run for that specific request only. Take a look at the example below:
Probe alerts are
alerts configurations that are defined under the
probe key. Alerts scoped under the probe key will run for all requests for that probe. Take a look at the example below:
Probes are performed after every interval, and alerts are generated after a specified threshold. Monika can perform probes once a second, therefore a theoretical maximum rate of one alert a second. Please keep in mind that there may be some delays to your network, notification channels (slack, email, etc), so your result will vary.
In general it will be something like:
From above, the theoretical maximum resolution is one second.
Assertion contains any arbitrary expression that will trigger alert when it returns a truthy value
Inside the assertion expression you can get the response object.
These are values that are available:
response.body can be queried further with object access syntax.
For example, to trigger alert when content-type is not json you may use
Or to assertion value inside the body
Additionally you can have processing done in your queries. For instance, to ensure case insensitivity, you might want to convert to lowercase. It might look something like this:
These operators are available:
|x + y||Add|
|x - y||Subtract|
|x * y||Multiply|
|x / y||Divide|
|x % y||Modulo|
|x ^ y||Power|
|x == y||Equals|
|x != y||Does not equal|
|x < y||Less than|
|x <= y||Less than or equal to|
|x > y||Greater than|
|x >= y||Greater than or equal to|
|x ~= y||Regular expression match|
|x in (a, b, c)||Equivalent to (x == a or x == b or x == c)|
|x not in (a, b, c)||Equivalent to (x != a and x != b and x != c)|
|x or y||Boolean or|
|x and y||Boolean and|
|not x||Boolean not|
|x ? y : z||If boolean x, value y, else z|
|( x )||Explicit operator precedence|
There are also several helper functions available:
has(object, property): Checks whether an object has searched property.
has(response.body, "data") checks if there is "data" property inside response.body
lowerCase(string): Converts string to lowercase
lowerCase(response.body.message) converts message string value to lowercase
upperCase(string): Converts string to uppercase
upperCase(response.body.message) converts message string value to uppercase
startsWith(string, target): Checks if string starts with the given target string
startsWith(response.body.message, "Hello") checks if message string value starts with "Hello"
endsWith(string, target): Checks if string ends with the given target string
startsWith(response.body.message, "world!") checks if message string value ends with "world!"
includes(collection, value): Checks if value is in collection. If collection is a string, it's checked for a substring of value
includes(response.body.prizes, "gold") checks if "gold" exists in the prizes array.
includes(response.body.message, "ello") checks if "ello" is a substring of the message string.
size(collection): Gets length of array or string values.
size(response.body.data.items) gets the count of items.
isEmpty(value): Checks if value is an empty object, empty array, empty string, null, or undefined.
isEmpty(response.body.data) checks whether the data property is empty or not
This is the message that is used in the sent notification.
Inside the message string, you can also get the response object similar to assertion by surrounding the expression with double curly braces like the example above.
Monika will automatically issue an alert when it detects a probe is inaccessible. An incident and recovery alert will be sent to all configured notification channels. Note that explicit connection assertion and customized message strings are not yet supported.
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 © 2023 Hyperjump Tech. All Rights Reserved.