Icinga Director - Import hosts from fileshipper - set location to field "Datacenter" if not empty

Hi guys,

let me first express what a fantastic piece of code the director and the import module is - mind-blowing, honestly.

I am actually playing around with some imports, like Meraki APs from a XML file, User from my Active Directory and my switches from a text file - which works pretty well.

But now I a stuck and have no idea how to realize this:

I have a csv-file with some MPLS router. I want to assign the geolocation automatically. Our hostnames start with 6 chars, beginning with the country and then the city, like UK-LON or DE-BER. Via a data list in director I can set the latitude and longitude into a field “location” which in the end get me a nice overview in Maps - so far so good.

But at one site I do have two datacenters, DE-BER-RZ1 and DE-BER-RZ2. This cannot be computed our of the hostname, so I added a field in the CSV file namd “dc”.

hostname;ip-address;dc;notes
DE-BER-MPLS-Router;10.0.0.1;DE-BER-RZ1;Main Router
DE-BER-MPLS-Backup;10.0.0.2;DE-BER-RZ2;Backup Router
UK-LON-MPLS-Router, 10.1.0.1;;Main Router

I also added this two location entries “DE-BER-RZ1” and “DE-BER-RZ2” to the data list.

What I want to do is this:

If ${dc} is not empty then

import ${dc} to site

elseif

import substring (hostname,0,6) to site

But I cannot find a conditionally modifier in “import Source”. I tried two import modifiers, but they just override each other.

Can someone please guide me in the right direction?

Best regards
Volker Dose

Hello Volker,

first you have to add an modifier during import that will generate the substring from hostname. Then in the sync job for this import, you have to add 2 rules, one to add the dc if it is not empty and one to add the substring if dc is empty.

Regards,
Carsten

Hi Carsten,

thanks for your quick reply. I am now working on this problem, but still cannot get it right.

I succeeded with one challenge though :wink:

Another property I want to set is the parent host.

All MPLS routers “depend” on the main-router where my icinga is running. So this object (MPLS-Router in main office" has a specific parent field set (“Core-Switch”) and this is imported.

The input file looks like this:

hostname;ip-address;parent;dc;notes;
DE-BER-MPLS-Router;10.0.0.1;DE-BER-RZ1;Main Router
DE-BER-MPLS-Backup;10.0.0.2;DE-BER-RZ2;Backup Router
UK-LON-MPLS-Router, 10.1.0.1;UK-LON-Core-Switch;Main Router

In the first step (Import Source) the parent is set only for the UK-LON-MPLS-Router, which is fine.

In the second step (Sync Rule) is have this property rule:

I set a Custom Expression “UK-LON-MPLS-Router” into the “parent” filed but this rule has a filter:

!${parent}

So it puts my Custom Expression only to parent IF the parent field is not set/empty.

And this works as expected, great.

But, as I said, I am stuck with the geolocation. I could use such a filter and set the site field, but would like to set the geolocation field from a data list and as far as I know, this is only possible in the Import Source step, right?

Hmm, maybe I could try something like this:

  1. put the geolocaton (LAT/LON) into a variable “geolocation_temp”
  2. set geolocation_temp if !${dc}

I hope I am on the right way.

Best regards
Volker

Hi Carsten,

I got it now… with the help of an auxiliary variable.

This is how I created the modifiers and rules:

So if a CSV-entry has a hostname like “DE-BER-MPLS-Router”,

  • extract the site (country and city) and put it into the field “site”
  • get the geolocation from a data list and put in into the field “location”

But if the CSV-Entry also as a field “dc” for DataCenter,

  • get the geolocation from a data list and put it into the field “dc_location”

After that the result looks like this:

In the second step, Sync Rules, I have setup two property rules:

The first one simply puts the content of the field “location” into the host object attribute “geolocation”:

The second one put the content of the field “dc_location” into the host object attribute “geolocation” only if the field dc is not empty:

This way, you have a great deal of flexibility when importing hosts via fileshipper.

Best regards
Volker

1 Like