Get another host's variable into service definition to be run on the master.

This forum was archived to /woltlab and is now in read-only mode.
  • Hi All,


    I don't know how to frame the question. So, let's consider that I have a number(dynamic) of hosts with a custom variable indicating its type. Now I have to run a check at my master to verify "something" about a certain type of hosts. This something is outside of the hosts, so there is no point in running this check on the remote server. To run this check I need to get the address of each hosts of that type. Is there a way I can do it with a single service object?


    These are the hosts


    Object Host "foo1"
    {
    address = "a2.baz.zap"
    vars.my_type = "bar"
    . . .
    }


    Object Host "foo2"
    {
    address = "a2.baz.zap"
    vars.my_type = "bar"
    . . .
    }


    .
    .
    .
    Object Host "fooxxx"
    {
    address = "axxx.baz.zap"
    vars.my_type = "bar"
    . . .
    }


    I want to do something like this,


    apply service "foobarbaz" for (host.vars.my_type == "bar")
    {
    // check something on host type bar
    // the check command requires an argument 'my_host'
    vars.my_host=host.address //where host is of the type bar
    . . .
    . . .
    assign where host.name == NodeName
    }


    This sounds stupid, but is there any way to do it than to write separate service objects for each host?


    Thanks in advance.


  • You can try something like this:


    Code
    1. apply service "foobarbaz"
    2. {
    3. // check something on host type bar
    4. // the check command requires an argument 'my_host'
    5. vars.my_host=host.address //where host is of the type bar
    6. . . .
    7. . . .
    8. assign where host.vars.my_type == "bar" && host.name == NodeName
    9. }
  • Thank you birkch for the reply.

    host.vars.my_type == "bar" && host.name == NodeName

    The above condition will return an empty set for me. Since 'NodeName' is my master and hosts with type 'bar' are remote servers which are being checked by my master (through ssh).


    I figured out that I have to write an external script that would write icinga config for this service and restart icinga whenever there is a config change.