Icinga Director: Cloning dictionary row entries for objects from import sources

by | Aug 29, 2024

Over use of dictionaries in monitoring leads to complex and ugly configurations. This in turn makes monitoring complicated. Hence, it is advisable to use it, only if it is needed or in special cases. Even in these cases it is worthwhile to keep it simple.

On that note, in this blogpost let me demonstrate how to clone dictionary row entries for objects from import sources to object properties in Icinga Director.

For this I will be importing the below hosts from a json file. This example is taken from the original Github issue opened for this particular feature.

{"Router1": {
    "hostname": "router.example.com",
    "if": {
        "GigabitEthernet0": {
            "link_local": "FE80::DEAD:BEEF:AFFE:110",
            "speed": 1000000
        },
        "GigabitEthernet1": {
            "link_local": "FE80::DEAD:BEEF:AFFE:111",
            "speed": 1000000
        }
    }
},
"Router2": {
    "hostname": "gw.example.com",
    "if": {
        "GigabitEthernet0": {
            "link_local": "FE80::DEAD:BEEF:AFFE:112",
            "speed": 1000000
        }
    }
}}

As shown in the configuration we have two example routers as hosts with their interface configuration (property if) in the form of a dictionary.

I want to first extract the rows in interface configuration as object properties and rewrite the interface configuration names (GigabitEthernetX) to a separate object property. So that it would seem like I am importing from host configurations as below.

{"Router1-0": {
    "hostname": "router.example.com",
    "ifName": "GigabitEthernet0",
    "link_local": "FE80::DEAD:BEEF:AFFE:110",
    "speed": 1000000
},
"Router1-1": {
    "hostname": "router.example.com",
    "ifName": "GigabitEthernet1",
    "link_local": "FE80::DEAD:BEEF:AFFE:111",
    "speed": 1000000
}, 
"Router2": {
    "hostname": "gw.example.com",
    "ifName": "GigabitEthernet0",
    "link_local": "FE80::DEAD:BEEF:AFFE:112",
    "speed": 1000000
}}

From the above configuration it is clear that I need to rewrite the interface configuration names (GigabitEthernetX) to a separate object property ifName. And split the first router to two different hosts for each of its interfaces. This way can monitor the two router interfaces belonging to the host ‘router.example.com’  separately.

Now, since I am clear what is needed, let me demonstrate how to accomplish this using the property modifiers in import source.

First, I will create the import source as shown below.

The preview for this import source before modifiers are applied looks as below.

Now, I will first use the property modifier Clone the row for every entry of a nested Dictionary/Hash structure to group the interface configuration and rewrite the configuration name to a key property as below.

Now I will use the property modifier Get a specific Array Element to extract the properties from the configuration as shown in the images below.

And since the host names should be unique here, I have used the Combine multiple properties modifier to combine the host name and interface name to generate unique host names.

After doing this, the properties are extracted as shown in the preview below.

Finally, now I could import these hosts and that is how it is done.

To know about how to synchronize and create/modify objects in Icinga Director, check this documentation on Import and Synchronization in Icinga Director.

 

You May Also Like…

Releasing Icinga Director v1.11.2

Releasing Icinga Director v1.11.2

We are pleased to announce the release of Icinga Director version 1.11.2, which addresses several important bug fixes...

Subscribe to our Newsletter

A monthly digest of the latest Icinga news, releases, articles and community topics.