In this blog post I will introduce you to filtering, based on deep custom variables in Icinga DB Web. In Icinga Web 2 monitoring module, it is not possible to filter deep custom variables.
Example of deep custom variables involving dictionaries and arrays:
vars.dummy = { test = { foo = ["bar", "foo bar"] } }
This is because in the database (IDO) the suitable structure for the custom variables is not available. The dictionaries and arrays in the custom variables are saved in json format as shown below. It is impractical to fetch the deep custom variables in this format and it is not possible to support it across different database versions.
Hence, it is not possible for the user to filter the objects on deep custom variables. This is where the Icinga DB Web module comes to save the day.
The deep custom variables are saved as flat resolved custom variables (dot-separated format) in Icinga DB. In Icinga DB Web, these flat resolved custom variables are used for filtering the objects. For example, we can filter for objects on dummy.test.foo[0]
.
To demonstrate this, the following two dummy host objects with deep custom variable as shown below are created in Icinga 2:
object Host "dummy-test1" { check_command = "random fortune" address = "127.0.0.1" address6 = "::1" vars.dummy = { test = { foo = ["bar", "foo bar"] } } vars.is_dummy = true } object Host "dummy-test2" { check_command = "random fortune" address = "127.0.0.1" address6 = "::1" vars.dummy = { test = { foo = ["bar"] } } vars.is_dummy = true }
Now in the Icinga DB Web module, let’s filter the host objects with the deep custom variable dummy.test.foo[0]
value as bar
and see the result.
Before filter:
After filter:
In case of the arrays in the deep custom variables, we can also filter the objects based on whether the array in deep custom variable contains an element.
To demonstrate this, I will give another example. I will use the filter host.vars.dummy.test.foo[*] = foo bar
. This filters the host objects where their deep custom variable host.vars.dummy.test.foo
contains an element foo bar
in the array.
After filter:
Checkout more on Icinga DB Web and get to know more about its features.