Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add service name to service apply loops #227

Closed
fredrik-eriksson opened this issue Feb 3, 2017 · 4 comments
Closed

Add service name to service apply loops #227

fredrik-eriksson opened this issue Feb 3, 2017 · 4 comments
Assignees
Milestone

Comments

@fredrik-eriksson
Copy link

Hi,

When applying services by looping over a dict (and probably array as well) it seems that no service-name is prepended. I want to add two ping tests for each interface on a host; one over ipv4 and one over ipv6; but the result is the following two objects:

apply Service for (interface => opts in host.vars.network.interfaces) to Host {
  vars.ping_address = "opts.address"
  vars.ping_cpl = getvar(host.vars.ping_cpl, 40) 
  check_command = "ping4"
  assign where "opts.address"
}

apply Service for (interface => opts in host.vars.network.interfaces) to Host {
  vars.ping_address = "opts.addressv6"
  vars.ping_cpl = getvar(host.vars.ping_cpl, 40) 
  check_command = "ping6"
  assign where "opts.addressv6"
}

This fails since the service names will be the same for both checks (the interface name). What I really want is something like this:

apply Service "ping4_" for (interface => opts in host.vars.network.interfaces) to Host {
  vars.ping_address = "opts.address"
  vars.ping_cpl = getvar(host.vars.ping_cpl, 40) 
  check_command = "ping4"
  assign where "opts.address"
}

apply Service "ping6_" for (interface => opts in host.vars.network.interfaces) to Host {
  vars.ping_address = "opts.addressv6"
  vars.ping_cpl = getvar(host.vars.ping_cpl, 40) 
  check_command = "ping6"
  assign where "opts.addressv6"
}

Which would give all objects unique names; but it doesn't seem to be supported currently.

@lbetz lbetz closed this as completed in 8ea41d5 Feb 4, 2017
@lbetz lbetz added this to the v1.0.3 milestone Feb 4, 2017
@lbetz lbetz added the bug label Feb 4, 2017
@lbetz lbetz self-assigned this Feb 4, 2017
@fredrik-eriksson
Copy link
Author

Actually, this one isn't fixed yet. You fixed the bug with using the variables in the service; but the template still needs to be updated to allow for a unique service name when the first loop variable (interface in the example) is the same for more than one service.

apply Service for (...) to Host {
Should be
apply Service "<service_name>" for (...) to Host {

@lbetz
Copy link
Contributor

lbetz commented Feb 6, 2017

Sorry that's a syntax I donno.

'apply Service for' thru a hash is a for each loop (desc => config in host.vars.hash), desc is taken as service name by default.

@fredrik-eriksson
Copy link
Author

you can see it in the example here:
https://docs.icinga.com/icinga2/latest/doc/module/icinga2/chapter/monitoring-basics#using-apply-for

Look at the example for apply Service "if-" for (interface_name => interface_config in host.vars.interfaces)

In my example above it's necessary to add a prefix string as both services are iterating over the same hash, but add different services: one for ipv4 and one for ipv6. Without the prefix string icinga complains about duplicate service definition.

@lbetz
Copy link
Contributor

lbetz commented Feb 6, 2017

It's not supported by the module.

You can also omit the "if-" string, then all generated service names are directly taken from the if_name variable value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants