1

What is best practice for configuring multiple HTTP checks for a host?

I know there is that "apply" method:

apply Service "http" for (http_vhost => config in host.vars.vhosts) {
    ...
}

But i do also need the "http_uri" value?!

How to do this via normal config files AND how to do this via the Director? Where and how i have to modify a template to get multiple HTTP checks linked to a specific host?

2 Answers2

2

I don't use the director, but I can tell you how I do this in normal code. Basically I'd create some dict / list, as you said (at various scopes). There you have to put variables there - those ones you want to change (so for example URL).

So you define a variable with your data. It can be under host, or you can create it in the global scope.

globals.http_urls = [ "/uril1", "/url2" ]

or

object Host "testhost" {
    host.address = 123.123.123.123
    vars.http_urls = [ "/url1", "/url2" ]
} 

then you can iterate over that variable

apply Service "http-url" for (url in globals.http_url) {
    command = http

    # ... other http check variables ...

    vars.http_url = url

    # ... other variables ...

    assign where host.name == "testhost"
}

you can also iterate over the dictionary, it works like that:

globals.testdict = {
    "server1" : "testdict",
    "server2" : "testweb",
    etc..
}

just use key => value format in for definition

apply Service "http-url" for (server => url in globals.testdict) {
    command = http
    display_name = "http check " + server

    vars.http_url = url
    .. etc

    assign where host.name == testserver
}
pershing
  • 66
  • 3
0

I'm not a huge fan of Icinga's documentation, but it's explained okayish how to do that in Director.

First, you need to create an array field as explained here: https://icinga.com/docs/icinga-director/latest/doc/14-Fields-example-interfaces-array/

Then you need to create a service apply rule with and add Apply For for your array field, as explained here: https://icinga.com/docs/icinga-director/latest/doc/15-Service-apply-for-example/

Regarding your question

But i do also need the "http_uri" value?!

That depends. If you leave it, the checked uri will be /. I am not sure if it's possible to configure check_http with different values for http_uri and http_vhost.

One thing that confused me a lot is that the parameter http_uri of the check_http is just the path component of the URI. Strange things happen if you try to use a complete URI.