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

Apply Notification "users" and "user_groups" as variable #208

Closed
n00by opened this issue Jan 19, 2017 · 2 comments · Fixed by #215
Closed

Apply Notification "users" and "user_groups" as variable #208

n00by opened this issue Jan 19, 2017 · 2 comments · Fixed by #215
Assignees
Labels
Milestone

Comments

@n00by
Copy link
Contributor

n00by commented Jan 19, 2017

What I want to do

from icinga2 docs, 4.2.3.4. notifications.conf - https://docs.icinga.com/icinga2/latest/doc/module/icinga2/toc#!/icinga2/latest/doc/module/icinga2/chapter/configuring-icinga2-first-steps#notifications-conf

apply Notification "mail-icingaadmin" to Host {
  import "mail-host-notification"

  user_groups = host.vars.notification.mail.groups
  users = host.vars.notification.mail.users

  assign where host.vars.notification.mail
}

That's my config

icinga2::object::notification { 'mail-host-notification_apply':
  notification_name => 'mail-icingaadmin',
  import            => [ 'mail-host-notification' ],
  apply             => true,
  user_groups       => 'host.vars.notification.mail.groups',
  users             => 'host.vars.notification.mail.users',
  assign            => [ 'host.vars.notification.mail' ],
  target            => '/etc/icinga2/conf.d/notifications.conf',
}

What I get

apply Notification "mail-icingaadmin" to Host {
 import "mail-host-notification"

 users = [ host.vars.notification.mail.users, ]
 user_groups = [ host.vars.notification.mail.groups, ]
 assign where host.vars.notification.mail
}

Problem is that icinga doesn't identify variables as variables when set in square brackets.

Possible solution

Check if the parameter is a variable in the puppet code. So any2array "users" and "user_groups" solely when not a variable.

n00by added a commit to n00by/puppet-icinga2 that referenced this issue Jan 19, 2017
n00by added a commit to n00by/puppet-icinga2 that referenced this issue Jan 19, 2017
@bobapple bobapple added the bug label Jan 20, 2017
@bobapple bobapple added this to the v1.0.2 milestone Jan 23, 2017
@n00by
Copy link
Contributor Author

n00by commented Jan 24, 2017

Hi, this issue is not fixed in v1.0.2.

Values for "users" and "user_groups" must be a string if you want to use them as variables. Therefore both string and array should be possible:

if !is_array($users) { validate_string($users) }
if !is_string($users) { validate_array($users) }

To keep things tidy there should be a check if a user really wants to use a variable if a string is used. So an additional check is necessary, sth. like if is_string($users) and !is_variable($users) then any2array($users).

Or just add to the documentation to use a string for setting a variable, else an array.

@lbetz
Copy link
Contributor

lbetz commented Jan 24, 2017

Done. Did the same for states and types attribute.

@lbetz lbetz closed this as completed Jan 24, 2017
@bobapple bobapple modified the milestones: v1.0.3, v1.0.2 Jan 25, 2017
@lbetz lbetz self-assigned this Feb 4, 2017
@bobapple bobapple modified the milestones: v1.1.0, v1.0.3 Mar 13, 2017
n00by pushed a commit to n00by/puppet-icinga2 that referenced this issue Apr 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants