Define 'Dictionary' Custom Attribute via Icinga Director


(Vish) #1

Hello Icinga Team,

I am stuck trying to configure Dictionary custom variable using Icinga Directory.

My use case is that I have two Host objects defined. Each of which have a dictionary variable called http_vhosts. Later in the services.conf I apply a custom http or https check Service by looping through http_vhosts. My main goal is check all the website links in all different zones and at the same time group the links using the Object Host structure.

So How can I represent dictionary variable (http_vhosts) in Icinga Directory ?

/** hosts.conf **/

object Host "APACHE-RESTRICTED-ZONE"
{
        import "generic-host-restricted-zone"
        import "generic-host-apache"

        display_name = "APACHE RESTRICTED"

        vars.http_vhosts["Site1"]= {
                http_uri = "http://mysite-intra-1/en/index.jsp"
                http_ssl = false
                check_enabled = true
        }
        vars.http_vhosts["Site2"] = {
                http_uri = "http://mysite-intra-2/en/index.jsp"
                http_ssl = false
                check_enabled = true
        }
        vars.http_vhosts["Site3"] = {
                http_uri = "https://mysite-intra-3/en/index.jsp"
                http_ssl = false
                check_enabled = true
        }


}

object Host "APACHE-PUBLIC-ZONE"
{
        import "generic-host-public-zone"
        import "generic-host-apache"

        display_name = "APACHE PUBLIC"

        vars.http_vhosts["Site1"]= {
                http_uri = "http://mysite-public-1/en/index.jsp"
                http_ssl = false
                check_enabled = true
        }
        vars.http_vhosts["Site2"] = {
                http_uri = "http://mysite-public-2/en/index.jsp"
                http_ssl = false
                check_enabled = true
        }
        vars.http_vhosts["Site3"] = {
                http_uri = "https://mysite-public-3/en/index.jsp"
                http_ssl = false
                check_enabled = true
        }


}

/** services.conf **/

apply Service for (displayName  => config in host.vars.http_vhosts) {
        import "generic-service-apache"

        name = displayName
        display_name = displayName
        check_command = "custom_check_http"

        vars += config

        assign where config.http_ssl == false && config.check_enabled != false
}

With Icinga Directory currently i couldn’t find the possibility to define a Dictionary custom attribute. I do not see any data type called “Dictionary” or some thing related to that in “Define Data Fields” Option.

I tried searching about this but couldn’t find a solution. Is Dictionary data type not implemented yet in the director or is there a way to configure this ? I am hoping that some one could help me regarding how to define a dictionary custom variables in Icinga Directory. Thank you very much for your time.

Thanks,
Vish


(Vinod Appukuttan) #2

I ran into this today and would like some help. Any updates/responses to this would help.

Found this on further searches: https://monitoring-portal.org/woltlab/index.php?thread/39276-how-to-realise-this-applyrule-with-the-director-dictionary/


(Cesar Gonzalez) #3

Director’s Custom Variables does not support Dictionaries. I went down that road a while ago and got disappointed as well.

I think, as an alternative, you could maybe create 2 Array Custom Variables (http and https) and 2 different services; one for each? That would be the more straightforward approach.

Topic seems to have stalled in Github, but I do agree it would be great to have a way to manage this:

I must say managing this with the Icinga2 API would probably be very straight forward too, so why not maybe take a lok at that route?

Hope these suggestion helps a lil bit


(Cesar Gonzalez) #4

Just to add, something interesting I found reading the thread above.

Just want to add some on my experience with the Director.

As longer as i use the director, the more i think i don’t need these dictionaries as much as i needed them in plain configfiles.

Why adding an interface configuration to a host when i can add them as service ? The hazzle to click on add service is far lower in the Director as it was on the console to add a service over and over again. You even can clone your service now.

And

The Director provides an abstraction of those configuration, but it is still good and required to understand the Icinga 2 configuration bits in case of errors. apply-for is especially useful if you don’t have the Director, and want to just generate host objects from your CMDB or any other information provider.

Basically, what I get from this is, if you’re already on Director, is better to just define a Service Template, HTTP in this case, and add Services to the Host (something the GUI allows, there’s a nice Service tab when editing a host).

In each Service Definition you basically have everything you need to define it´s attributes, just as if you were creating a Dctionary :slight_smile:


(Michael Friedrich) #5

I’d advise on asking on the Github issue, everytime, even if there is no progress. Or as said in another topic already, consider sponsoring the implementation.

Remember one thing: If you are a developer who looks into more than a thousand issues (guess that is true for Icinga), you don’t remember every single feature request or issue. Especially not when you’re a consultant or bound into other projects :wink:


(Pablo Venturini) #6

I think dictionaries are needed. For example, in my manual Icinga2 setup I am monitoring disks using dictionaries as shown below. The nice thing about this is when this gets written to InfluxDB it all goes into ONE time series. If we, instead, create a separate service for each partition, a separate time series would be created for each partition. This complicates queries in Grafana, for example.
vars.disks[" /"] = {
disk_to_check = “/”
warn_percent = “70%”
crit_percent = “89%”
}

vars.disks[" /boot"] = {
disk_to_check = “/boot”
warn_percent = “70%”
crit_percent = “89%”
}

vars.disks[" /var"] = {
disk_to_check = “/var”
warn_percent = “70%”
crit_percent = “89%”
}


(Andreas Albert) #7

I totally agree with that. I also would like to have that feature in director


(Pablo Venturini) #8

turns out my assumption is wrong. The default settings for the Influxdb writer sets the measurement (time series) to the check command. So even though different services are being used for each disk (as in my example), all of the metrics for all of the disks are written tot he same time series.
So while support for dictionary types would be good and perhaps simplify things a bit I’m able to achieve the same result using service templates and setting variables to different values for each service I need to monitor.


(Vinod Appukuttan) #9

Hello Pablo, could you please describe how you did this with using different services, did you use arrays and if you can just give an example that would be great.


(Rasp8e) #10

I would also be interested in how you managed to do this


(Pablo Venturini) #11

There are two parts to this problem. First Director currently won’t allow you to create dictionary variables. The other problem is that it also can’t apply a service based on a dictionary variable.
For the first part, we worked around this problem by using the Director API. The API allows you to add hosts by passing it host JSON objects. So we simply build the object how we want with all variables including the dictionary variables (for disk partitions as I showed in my previous post).
Next, to actually apply the service check based on those dictionary variables, since we can’t do it in director, we just do it in Icinga2. So in /etc/icinga2/conf.d/services.conf we define the check command and apply to rules.

object CheckCommand "snmp_disk" {
  import "plugin-check-command"
  command = [ PluginDir + "/check_disk_snmp.pl" ]

  arguments = {
    "-H" = {
      value = "$address$"
      description = "Host address"
    }
    "-s" = {
      value = "snmp"
      description = "SNMP community (Make this a variable)"
    }
    "-w" = {
      value = "$warn_percent$"
      description = "Warning Percent"
    }
    "-c" = {
      value = "$crit_percent$"
      description = "Critical Percent"
    }
    "-d" = {
      value = "$disk_to_check$"
      description = "Disk to Check"
    }
  }
}

apply Service "snmp_disk" for ( disk => config in host.vars.disks ) {
  import "generic-service"
  check_command = "snmp_disk"
  vars += config
  icon_image = "disk.png"
  assign where host.vars.disks
}

I think the part of the apply to rule that Director still can’t support is the “for ( disk => config in host.vars.disks )” which is essentially a for each.
In our case, this was the only service for which we needed dictionary variables. For everything else we were able to just use string variables and those are easily supported in Director.
I will also add this. In our case, we are using distributed monitoring. This morning I discovered that disk checks were not being executed on satellite nodes. I had to copy the services.conf file to all of the satellites and the checks began to work again. This is because in my case, the disk service check is not being managed by Director. So it makes sense.
Setting up Distributing monitoring with Director is a whole other animal but what you’ll find is that Director currently can’t do everything and sometimes you need to find workarounds or fill in the gaps using the standard Icinga2 config files.


(Vish) #12

Extremely Sorry for responding VERY late. I was away for a while .
And thanks you all very much for your responses.


(Vish) #13

I tried to solve this by converting each dictionary item in to a Host object

vars.http_vhosts["Site1"]= {
                http_uri = "http://mysite-intra-1/en/index.jsp"
                http_ssl = false
                check_enabled = true
        }

TO

object Host "Site1" {
    import "watchurl-type-apache-22"

    vars.priority = "A"
    vars.url = "http://bzo.bosch.com/en/index.jsp"
    vars.http_ssl  = false
    vars.check_enabled = true
}