Closed czstrfr closed 5 years ago
vars.sid2watch
is undefined in this scope, and as such an empty value is assigned to parent_service_name
. When it is empty, Icinga assumes that the parent object is of the Host type - whereas the filter type with OK
is invalid.
apply Dependency "disable-ssh-checks-if-sid-down" to Service {
parent_service_name = vars.sid2watch
In order to fix this, use service.vars.sid2watch
which actually involves the service object in this scope.
Good afternoon Michael,
many thanks for super quick reply, appreciate that. Unfortunately I already tried that before with the same result:
[2019-06-19 14:03:55 +0200] critical/config: Error: Validation failed for object 'host1.example.net!oracle-tablespace-usage-monitoring.shdwhuqa!sid-up' of type 'Dependency'; Attribute 'states': State filter is invalid for host dependency.
Location: in /etc/icinga2/zones.d/global-templates/dependencies.conf: 8:3-8:17
/etc/icinga2/zones.d/global-templates/dependencies.conf(6): apply Dependency "sid-up" to Service {
/etc/icinga2/zones.d/global-templates/dependencies.conf(7): parent_service_name = service.vars.sid2watch
/etc/icinga2/zones.d/global-templates/dependencies.conf(8): states = ["OK"]
^^^^^^^^^^^^^^^
/etc/icinga2/zones.d/global-templates/dependencies.conf(9): disable_checks = true
/etc/icinga2/zones.d/global-templates/dependencies.conf(10): disable_notifications = true
Hm, ok. I'm little out of time now, but you can try to use the script debugger in order to analyse why and if the parent_service_name is not populated here.
apply Dependency "disable-ssh-checks-if-sid-down" to Service {
parent_service_name = service.vars.sid2watch
debugger //add the statement breakpoint
states = ["OK"]
disable_checks = true
disable_notifications = true
ignore_soft_states = false
assign where service.check_command == "by_ssh" && host.vars.os == "Solaris" && host.vars.sids2watch
}
Invoke the script debugger.
icinga2 daemon -X -C
Print this
, service
, and so on in the local scope. Maybe the service variable is empty for that specific object where the apply rule matches.
Hint: The assign where expression doesn't check for its existence.
assign where service.check_command == "by_ssh" && host.vars.os == "Solaris" && host.vars.sids2watch
Hi Michael,
my apologies since there is already relevant open tiket under icingaweb2-module-director, which I think is not the right place since this is not director issue. Shall I close this one?
Many thanks for your help and great work.
Regards
Frantisek
The linked issue is a feature request to allow object references in apply rules inside the Director - that's a different one. Your problem is with static config files and some of your services don't provide the data - as such the validation fails. Fix that, and it will work.
Dear Michael,
many thanks for your hints, but the variable stayed empty no matter what I tried. After bit of digging I found another elegant way how to automatize it, so I am sharing my findings for others since I am really loving this project and I want to participate tiny bit too:
object Host "solariszone1.example.net" {
import "generic-host"
display_name = "DWH Test1 QA"
address = "10.20.30.40"
vars.os = "Solaris"
vars.parents = ["solarisldom1.example.net"]
vars.sids2watch ["dwhsid1"]={
procs_user = "oracle",
procs_warning = "",
procs_critical = "1:1",
procs_argument = "ora_pmon_dwhsid1"}
vars.sids2watch ["dwhsid2"]={
procs_user = "oracle",
procs_warning = "",
procs_critical = "1:1",
procs_argument = "ora_pmon_dwhsid2"}
}
apply Service "sids2watch" for (sidname => config in host.vars.sids2watch){
import "solaris-checks-service"
display_name = "oracle SID status: " + sidname
vars.by_ssh_command = "/opt/icinga/nagios-plugins/check_procs"
vars += config
vars.by_ssh_arguments = {
"-w" = {
value = "$procs_warning$",
}
"-c" = {
value = "$procs_critical$",
}
"-u" = {
value = "$procs_user$",
}
"-a" = {
value = "$procs_argument$",
}
}
assign where host.vars.sids2watch
}
apply Service "oracle-active-session-count-check" for (sidname => config in host.vars.sids2watch) {
import "oracledb-check-service"
vars.by_ssh_command = "sudo su - oracle /u01/icinga/oracle-active-session-count-check.sh " +sidname
vars += config
assign where host.vars.os == "Solaris" && host.vars.sids2watch
}
apply Dependency "Parent" for (parent in host.vars.parents) to Host {
parent_host_name = parent
assign where host.address && host.vars.parents
}
apply Dependency "disabel-ssh-checks-if-sid-down" for (sidname => config in host.vars.sids2watch) to Service {
parent_service_name = "sids2watch" +sidname
states = ["OK"]
disable_checks = true
disable_notifications = true
ignore_soft_states = false
assign where match("*"+sidname, service.name)
}
Dear all,
I think we found a bug trying to dynamically declare service to service dependency using custom variable in
parent_service_name
receiving errorState filter is invalid for host dependency.
To Reproduce
1.
2.
3.
4.
5.
6.
Expected behavior
Config validation should evaluate the variable in the very same way as explicitly declared service name, which pass the config validation and works as expected.
Your Environment
icinga2 --version
): r2.10.4-1icinga2 feature list
): api checker command ido-pgsql mainlog notification perfdatadirector 1.6.2
doc 2.6.1
ipl v0.2.1
monitoring 2.6.1
pnp 1.0.1
setup 2.6.1
translation 2.6.1
vsphere 1.1.0
Additional context
If the
parent_service_name
is declared directly as servicename, config validation is successful and dependency is triggered if parent service change state from OK to any other state: 1.2.
3.