You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Assignee: mfriedrich
Status: Resolved (closed on 2016-03-17 14:53:53 +00:00)
Target Version: 2.4.5
Last Update: 2016-04-20 08:15:59 +00:00 (in Redmine)
Icinga Version: 2.4.4
Backport?: Already backported
Include in Changelog: 1
Hi,
I like to have host templates like
type1-printer-host
type2-printer-host
and assign a group of printer by
object HostGroup "printers-lexmark" {
display_name = "Lexmark Printers"
assign where host.vars.vendor == "lexmark" && match("*printer-host",host.templates))
}
the same with services
apply Service "Alerts" {
display_name = "Status"
import "printer-service"
match("*printer-host",host.templates))
check_command="check_printer"
vars.command="alerts"
}
icinga2 object list --name 'jip-060'
templates = [ "jip-060", "x950-printer-host", "generic-host" ]
% = modified in '/etc/icinga2/conf.d/printer-host.conf', lines 35:1-35:21
% = modified in '/etc/icinga2/conf.d/templates-host.conf', lines 167:1-167:33
% = modified in '/etc/icinga2/conf.d/templates.conf', lines 14:1-14:28
--
unfortunaltely it is not evaluated, even checkconfig is finw with it.
Updated by mfriedrich on 2016-03-17 14:52:27 +00:00
Subject changed from apply Service or assign Group with match *printer-host",host.templates not working to Explain how to use functions for wildcard matches for arrays and/or dictionaries in assign where expressions
Category changed from Configuration to Documentation
Status changed from New to Assigned
Assigned to set to mfriedrich
Target Version set to 2.4.5
Your match() call is wrong, this will never return true. You're comparing a wildcard string with an array of host templates.
match("*printer-host",host.templates)
You could go for a function which takes the host and the wildcard match as arguments.
template Host "lexmark-printer-host" {
vars.printer_type = "Lexmark"
}
object Host "myprinter" {
import "generic-host"
import "lexmark-printer-host"
address = "192.168.1.1"
}
/* register a global function for the assign where call */
globals.check_host_templates = function(host, search) {
/* iterate over all host templates and check if the search matches */
for (tmpl in host.templates) {
if (match(search, tmpl)) {
return true
}
}
/* nothing matched */
return false
}
object HostGroup "printers-lexmark" {
display_name = "Lexmark Printers"
/* call the global function and pass the arguments */
assign where check_host_templates(host, "lexmark*")
}
I've now converted this issue into a documentation issue adding such examples. This should help in the future.
Next time please consider discussing this topic in the community channels such as the forum. It is merely not a bug but a configuration problem.
This issue has been migrated from Redmine: https://dev.icinga.com/issues/11402
Created by dedkus on 2016-03-17 10:31:17 +00:00
Assignee: mfriedrich
Status: Resolved (closed on 2016-03-17 14:53:53 +00:00)
Target Version: 2.4.5
Last Update: 2016-04-20 08:15:59 +00:00 (in Redmine)
Hi,
I like to have host templates like
type1-printer-host
type2-printer-host
and assign a group of printer by
object HostGroup "printers-lexmark" {
display_name = "Lexmark Printers"
assign where host.vars.vendor == "lexmark" && match("*printer-host",host.templates))
}
the same with services
apply Service "Alerts" {
display_name = "Status"
import "printer-service"
match("*printer-host",host.templates))
check_command="check_printer"
vars.command="alerts"
}
icinga2 object list --name 'jip-060'
% = modified in '/etc/icinga2/conf.d/printer-host.conf', lines 35:1-35:21
% = modified in '/etc/icinga2/conf.d/templates-host.conf', lines 167:1-167:33
% = modified in '/etc/icinga2/conf.d/templates.conf', lines 14:1-14:28
--
unfortunaltely it is not evaluated, even checkconfig is finw with it.
Changesets
2016-03-17 14:49:13 +00:00 by mfriedrich e6f1439
2016-03-17 15:29:19 +00:00 by mfriedrich eeda5fe
2016-04-11 08:38:34 +00:00 by mfriedrich 24836a4
2016-04-20 08:06:59 +00:00 by mfriedrich 20cb2e4
Relations:
The text was updated successfully, but these errors were encountered: