Alerts

Star (0)

Alerts are the types of condition that will trigger Monika to send notification. It is an array located on probes defined in the config file monika.yml like so.

probes: [
- id: 1
name: Name of the probe
requests: [
...
...
- alerts: [
query: response.size >= 10000
message: Response size is {{ response.size }} expecting less than 10000
]
]
- alerts: [
query: response.status != 200
message: HTTP Status code is {{ response.status }} expecting 200
]
]

The alerts configuration can be put under probe or under each requests as displayed above. Alerts defined under probe will run for all requests, while the alerts defined under specific request will run for that request only.

Alert Query

Query contains any arbitrary expression that will trigger alert when it returns a truthy value

- alerts: [query: response.status == 500
...]

Inside the query expression you can get the response object.

These are values that are available:

  • response.status: HTTP status code of the reponse
  • response.time: the time it takes to perform a HTTP request
  • response.size: size of the response in bytes
  • response.headers: HTTP response headers
  • response.body: HTTP response body (if content-type is JSON, it will be parsed automatically)

The response.headers and response.body can be queried further with object access syntax.

For example, to trigger alert when content-type is not json you may use

alerts : [
- query: response.headers['content-type'] != "application/json"
...
]

Or to query value inside the body

alerts : [
- query: response.body.data.todos[0].title != "Drink water"
...
]

These operators are available:

Numeric arithmeticDescription
x + yAdd
x - ySubtract
x * yMultiply
x / yDivide
x % yModulo
x ^ yPower
ComparisonsDescription
x == yEquals
x != yDoes not equal
x < yLess than
x <= yLess than or equal to
x > yGreater than
x >= yGreater than or equal to
x ~= yRegular 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)
Boolean logicDescription
x or yBoolean or
x and yBoolean and
not xBoolean not
x ? y : zIf boolean x, value y, else z
( x )Explicity operator precedence

There are also several helper functions available:

  • has(object, property): Checks whether an object has searched property.

    example: has(response.body, "data") checks if there is "data" property inside response.body

  • lowerCase(string): Converts string to lower case

    example: lowerCase(response.body.message) converts message string value to lower case

  • upperCase(string): Converts string to upper case

    example: upperCase(response.body.message) converts message string value to upper case

  • startsWith(string, target): Checks if string starts with the given target string

    example: 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

    example: 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

    example 1: includes(response.body.prizes, "gold") checks if "gold" exists in prizes array.

    example 2: includes(response.body.message, "ello") checks if "ello" is substring of message string.

  • size(collection): Gets length of array or string values.

    example: 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.

    example: isEmpty(response.body.data) checks whether the data propery is empty or not

Alert Message

alerts: [
- query: response.status != 200
message: HTTP Status code is different, expecting 200
]

This is the message that is used in the sent notification.

Inside the message string, you can also get the response object similar to query by surrounding the expression with double curly braces like the example above.

Further reading

  1. Probes
  2. Notifications
← PrevNotifications
Was this page helpful?
Next →TLS Checkers

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 © 2021 Hyperjump Tech. All Rights Reserved.