Director: Splitting hostname from FQDN

Hello

I have a requirement where my log file that needs to be monitoring look like below

/path/hostname-instance_name.log

I was able to capture the instance_name path in a variable $host.vars.u_dbname$

Is there any way I can split the FQDN in Hostname* field and make it just Hostname something like split(Hostname)[0] :wink:

And then my path can be

/path/split(Hostname)[0]-$host.vars.u_dbname$.log

Regards

Anirban

This is not director specific, so Icinga 2 has some string functions (Library Reference - Icinga 2). I have not worked with them from within the director, but the director allows to use DSL for arguments, so it should be possible. In case of a tight name scheme I would prefer substring as a much easier option to work with strings.

A Director specific solution I have used many times when the import mechanism is used is to have a (regex) modifier which creates the hostname from the fqdn, but if this is an option depends on your environment.

Thank You :slight_smile:
Can you share an example please please please in a host or service / template definition.

Something like this:

apply Service "Test" {
  check_command = "dummy"

  vars.dummy_text = {{
    return "FQDN: $host.name$ - HOSTNAME:" + macro("$host.name$").split(".")[0]
  }}
  assign where host.name
}

If you need it more often you can look into custom functions to prettify it further!

I will try it in Director and see if that works :stuck_out_tongue:

Edit: Nope not able to make it work. I had a custom field - but it is string. I put the following and it did not work

image

Got
image

Hello

Can you share this please. Is this regex option within Director - or is it while importing externally using script? I am looking for something within Director

This is located at “Icinga Director” > “Automation” > “Import source” and when you select a import source, you can find it on the tab “Modifiers”. There are many modifiers which can strip the domain, so you can choose the one fitting best your scenario. But as I said it is only a option if you import the objects from some source.

Understood Dirk. Well it is not an option for us currently. We onboard using salt states :frowning:
So in Director no way to strip on the fly. That is really a bummer. May be @tgelf can help ?

Well in this case the best option would be to open directly an issue/feature request at the following place :slight_smile:

Regards

David

So are you saying this is not possible today - and can be safely going as a new feature request :slight_smile:
Just wanted to make sure. Don’t want @tgelf to say this is available feature today and I just don’t know of it

Hi! I don’t deny that @tgelf might be already on it but i wouldn’t rely on it either.
He also has other customers to satisfy and i think in the long run a feature request where other people can subscribe and show additional interest might be the best option.

On the other hand @tgelf is always good for a surprise :slight_smile:

Regards

David