This issue has been migrated from Redmine: https://dev.icinga.com/issues/7282
Created by dgoetz on 2014-09-19 14:06:57 +00:00
Assignee: _(none)_
Status: _Closed_ (closed on _2015-01-08 11:06:16 +00:00_)
Target Version: _(none)_
Last Update: _2016-02-09 04:00:48 +00:00 (in Redmine)_
Icinga Version: 2.1.1-7-g954deb
Trying to do something like that:
Using checks specific for virtual machines needs vmware_api_datacenter and vmware_api_vmname set, so everthing fine when I set it on the host.
Using checks specific for esxi clusters needs vmware_api_datacenter and vmware_api_cluster , but now vcenter is a virtual machine too, so it results in all three set and doing the wrong check. So setting the vmware_api_name to null on the check results in an unset value but does not remove it from the command line.
debug.log with removed clustername and ip
[2014-09-19 15:51:21 +0200] notice/Process: PID 12313 ('/usr/lib/nagios/plugins/check_vmware_api.pl' '-C' '######' '-D' '10.49.97.84' '-N' '' '-f' '/etc/icinga2/scripts/vmware.auth' '-l' 'runtime') terminated with exit code 2
[2014-09-19 15:51:21 +0200] debug/DbEvents: add service check history for 'vcenter!VMware Cluster ######'
[2014-09-19 15:51:21 +0200] debug/DbObject: Updating object vars for 'vcenter!VMware Cluster ######'
[2014-09-19 15:51:21 +0200] debug/DbObject: object customvar key: 'pnp_check_name' value: 'check_$service.check_command$' overridden: 0
[2014-09-19 15:51:21 +0200] debug/DbObject: object customvar key: 'vmware_api_authfile' value: '/etc/icinga2/scripts/vmware.auth' overridden: 0
[2014-09-19 15:51:21 +0200] debug/DbObject: object customvar key: 'vmware_api_cluster' value: '######' overridden: 0
[2014-09-19 15:51:21 +0200] debug/DbObject: object customvar key: 'vmware_api_command' value: 'runtime' overridden: 0
[2014-09-19 15:51:21 +0200] debug/DbObject: object customvar key: 'vmware_api_datacenter' value: '##.##.##.##' overridden: 0
[2014-09-19 15:51:21 +0200] debug/DbObject: object customvar key: 'vmware_api_vmname' value: '' overridden: 0
Relations:
Updated by dgoetz on 2014-12-18 11:08:55 +00:00
Is this also fixed by https://dev.icinga.org/issues/8066?
Updated by gbeutner on 2015-01-08 11:06:16 +00:00
Yes, it is.
Updated by gbeutner on 2015-01-08 11:06:31 +00:00
Updated by dgoetz on 2015-01-27 10:51:41 +00:00
Sorry, but I have to reopen this bug, because it is not fixed.
This configuration snippet:
object Host "vcenter" {
import "generic-host"
address = "####"
display_name = "####"
groups = [ "servers" ]
vars.vmware_api_vmname = "####"
}
object Service "VMware Cluster DMZ: Runtime" {
import "generic-service"
host_name = "vcenter"
check_command = "vmware_api"
vars.vmware_api_authfile = "/etc/icinga2/scripts/vmware.auth"
vars.vmware_api_cluster = "DMZ"
vars.vmware_api_command = "runtime"
vars.vmware_api_datacenter = "####"
vars.vmware_api_vmname = null
}
results in:
[2015-01-27 11:38:25 +0100] notice/Process: PID 30259 ('/usr/lib/nagios/plugins/check_vmware_api.pl' '-C' 'DMZ' '-D' '####' '-N' '' '-f' '/etc/icinga2/scripts/vmware.auth' '-l' 'runtime') terminated with exit code 2
[2015-01-27 11:38:25 +0100] debug/DbEvents: add service check history for 'vcenter!VMware Cluster DMZ: Runtime'
[2015-01-27 11:38:25 +0100] debug/DbObject: Updating object vars for 'vcenter!VMware Cluster DMZ: Runtime'
[2015-01-27 11:38:25 +0100] debug/DbObject: object customvar key: 'pnp_check_name' value: 'check_$service.check_command$' overridden: 0
[2015-01-27 11:38:25 +0100] debug/DbObject: object customvar key: 'vmware_api_authfile' value: '/etc/icinga2/scripts/vmware.auth' overridden: 0
[2015-01-27 11:38:25 +0100] debug/DbObject: object customvar key: 'vmware_api_cluster' value: 'DMZ' overridden: 0
[2015-01-27 11:38:25 +0100] debug/DbObject: object customvar key: 'vmware_api_command' value: 'runtime' overridden: 0
[2015-01-27 11:38:25 +0100] debug/DbObject: object customvar key: 'vmware_api_datacenter' value: '####' overridden: 0
[2015-01-27 11:38:25 +0100] debug/DbObject: object customvar key: 'vmware_api_vmname' value: '' overridden: 0
So vmware_api_vmname is overwritten but instead of removing it from the command line only its value is set to null which results in the wrong check. Have I misunderstood this feature?
Updated by gbeutner on 2015-01-27 10:57:01 +00:00
This is the intended behavior. You can use the remove() method to remove dictionary items.
Updated by ziesemer on 2016-02-09 04:00:48 +00:00
Sorry - how is this actually called?
I see the remove() method and other array methods were added in #8065 - and #8066 removed the documentation about being able to "unset" variables by setting them to null, but didn't replace it with documentation for how remove() can be used.
I.E., should this be:
vars.remove("vmware_api_vmname")
(... which doesn't work.)
For now, setting to an empty array appears to work - but I'm assuming this is an ugly hack that should be avoided:
vars.vmware_api_vmname = []
I have the same problem with the integrated dns check. I want to unset/remove vars.dns_expected_answer, so that the check only goes for any result. How can I do this without rewriting the dns check completely?
@cycloon: What I do for such use cases is creating me own wrapper (or if I expect it to be useful for others send it upstream).
For dns you could do something like this:
````
object CheckCommand "my_dns" {
import "dns"
attributes += {
"-a" = {
value = "$dns_expected_answers$"
set_if = "$dns_expect_answer$
description = "Optional ip address or host you expect the DNS server to return. Host must end with a dot (.). This option can be repeated multiple times (Returns OK if any value match). If multiple addresses are returned at once, you have to match the whole string of addresses separated with commas (sorted alphabetically)."
}
vars.dns_expect_answer = true
}
}
````
Then use my_dns for your dns checks and set dns_expect_answer to false where you simply want any answer.
And one last thing: It would be better to create a new issue referencing the old one instead of commenting in an already closed one.
I also have the issue, I have 2 different "apply for" , for the same object array.
How can get rid of a variable ?
config.test = [] fixed it for now...
config.remove(test) however is not working.
So what is the right solution to completely get rid of it for a certain service check? :)
Most helpful comment
@cycloon: What I do for such use cases is creating me own wrapper (or if I expect it to be useful for others send it upstream).
For dns you could do something like this:
````
object CheckCommand "my_dns" {
import "dns"
attributes += {
"-a" = {
value = "$dns_expected_answers$"
set_if = "$dns_expect_answer$
description = "Optional ip address or host you expect the DNS server to return. Host must end with a dot (.). This option can be repeated multiple times (Returns OK if any value match). If multiple addresses are returned at once, you have to match the whole string of addresses separated with commas (sorted alphabetically)."
}
vars.dns_expect_answer = true
}
}
````
Then use my_dns for your dns checks and set dns_expect_answer to false where you simply want any answer.
And one last thing: It would be better to create a new issue referencing the old one instead of commenting in an already closed one.