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

[dev.icinga.com #11402] Explain how to use functions for wildcard matches for arrays and/or dictionaries in assign where expressions #4041

Closed
icinga-migration opened this issue Mar 17, 2016 · 4 comments
Labels
area/documentation End-user or developer help bug Something isn't working
Milestone

Comments

@icinga-migration
Copy link

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)

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.

Changesets

2016-03-17 14:49:13 +00:00 by mfriedrich e6f1439

Docs: Explain how to use functions for wildcard matches for arrays and/or dictionaries

... in assign where expressions

fixes #11402

2016-03-17 15:29:19 +00:00 by mfriedrich eeda5fe

Docs: Explain how to use functions for wildcard matches for arrays and/or dictionaries

... in assign where expressions

fixes #11402

2016-04-11 08:38:34 +00:00 by mfriedrich 24836a4

Docs: Explain how to use functions for wildcard matches for arrays and/or dictionaries

... in assign where expressions

fixes #11402

2016-04-20 08:06:59 +00:00 by mfriedrich 20cb2e4

Docs: Explain how to use functions for wildcard matches for arrays and/or dictionaries

... in assign where expressions

fixes #11402

Relations:

@icinga-migration
Copy link
Author

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.

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2016-03-17 14:53:53 +00:00

  • Status changed from Assigned to Resolved
  • Done % changed from 0 to 100

Applied in changeset e6f1439.

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2016-03-17 14:57:54 +00:00

  • Relates set to 11106

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2016-03-17 15:29:36 +00:00

  • Backport? changed from Not yet backported to Already backported

@icinga-migration icinga-migration added bug Something isn't working area/documentation End-user or developer help labels Jan 17, 2017
@icinga-migration icinga-migration added this to the 2.4.5 milestone Jan 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/documentation End-user or developer help bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant