Optional parameters in Nagios_host

47 views
Skip to first unread message

Jonathan Gazeley

unread,
May 1, 2014, 6:06:37 AM5/1/14
to Puppet Users
I'm struggling a little bit with this one.

Some of my puppet nodes have lights-out management. For those that do, I
want to put the IP address of their iLOM card in Hiera and have that
appear as the notes_url in nagios_host{}.

This works well for hosts that *do* have iLOM, but for those with no
Hiera variable called ilom I don't want notes_url to be defined at all.
Setting notes_url => undef doesn't work because it is still written out
in the nagios config and the url appears clickable, but with no link
behind it. Setting notes_url => absent actually sets it to the string
'absent'.

Is there an elegant way of handling this so my iLOM-able hosts have
clickable iLOM links in Nagios while the non-iLOM-able hosts don't have
anything at all?

Thanks,
Jonathan

jcbollinger

unread,
May 1, 2014, 9:18:23 AM5/1/14
to puppet...@googlegroups.com


On Thursday, May 1, 2014 5:06:37 AM UTC-5, Jonathan Gazeley wrote:
I'm struggling a little bit with this one.

Some of my puppet nodes have lights-out management. For those that do, I
want to put the IP address of their iLOM card in Hiera and have that
appear as the notes_url in nagios_host{}.

This works well for hosts that *do* have iLOM, but for those with no
Hiera variable called ilom I don't want notes_url to be defined at all.
Setting notes_url => undef doesn't work because it is still written out
in the nagios config and the url appears clickable, but with no link
behind it.


Can you present some example code?

Undef is not a value.  You cannot store it in a variable, and assigning the keyword undef as a parameter value is functionally equivalent to not assigning any value at all.  Using undef as a parameter default affirmatively expresses that the parameter is optional.  My guess, then, is that you have something like this:

define site::managed_host($ilom_ip = undef) {
  @@nagios_host{ $title:
    notes_url => $ilom_ip,
    ....
  }
}

site::managed_host { $hostname:
  ilom_ip => undef
}

# and/or

site::managed_host { $other_hostname:
}


Indeed that won't work.  Assigning a variable reference as a parameter value is never the same thing as assigning undef, even if the variable has not been assigned a value.

 
Setting notes_url => absent actually sets it to the string
'absent'.



Yes, Puppet DSL allows bareword strings.  You use them all the time on the left side of the =>, and other places. 

 
Is there an elegant way of handling this so my iLOM-able hosts have
clickable iLOM links in Nagios while the non-iLOM-able hosts don't have
anything at all?



I'd need to see your code.  The speculative example I present above could be fixed this way, though:

define site::managed_host($ilom_ip = 'NOTSET') {
  @@nagios_host{ $title:
    notes_url => $ilom_ip ? { 'NOTSET' => undef, default => $ilom_ip },
    ....
  }
}

or this way:

define site::managed_host($ilom_ip = 'NOTSET') {
  if $ilom_ip == 'NOTSET' {
    @@nagios_host{ $title:
      # no notes_url
      ....
    }
  } else {
    @@nagios_host{ $title:
      notes_url => $ilom_ip,
      ....
    }
  }
}

or in other, analogous ways.


John

Jonathan Gazeley

unread,
May 2, 2014, 11:03:05 AM5/2/14
to puppet...@googlegroups.com
On 01/05/14 14:18, jcbollinger wrote:


On Thursday, May 1, 2014 5:06:37 AM UTC-5, Jonathan Gazeley wrote:
I'm struggling a little bit with this one.

Some of my puppet nodes have lights-out management. For those that do, I
want to put the IP address of their iLOM card in Hiera and have that
appear as the notes_url in nagios_host{}.

This works well for hosts that *do* have iLOM, but for those with no
Hiera variable called ilom I don't want notes_url to be defined at all.
Setting notes_url => undef doesn't work because it is still written out
in the nagios config and the url appears clickable, but with no link
behind it.


Can you present some example code?

Thanks for your long and detailed response, that's extremely helpful. So far I've tried these ways:

  @@nagios_host { $::fqdn:
    ensure     => present,
    address    => $::ipaddress,
    action_url => "/nagios/pnp4nagios/graph?host=${::fqdn}",
    notes_url  => hiera('ilom', absent),
  }

or

  @@nagios_host { $::fqdn:
    ensure     => present,
    address    => $::ipaddress,
    action_url => "/nagios/pnp4nagios/graph?host=${::fqdn}",
    notes_url  => hiera('ilom', undef),
  }

or

  $ilom = hiera('ilom', undef)
  @@nagios_host { $::fqdn:
    ensure     => present,
    address    => $::ipaddress,
    action_url => "/nagios/pnp4nagios/graph?host=${::fqdn}",
    notes_url  => $ilom,
  }

The second and third ways "work" in that an undef value is written into the nagios config, which is valid. However when notes_url has an undef value the clickable icon still appears in nagios but has no link associated - which is why I'd like to be able to set notes_url to undef or absent, and have the icon not appear in nagios unless there is a non-blank value.

So I guess there are really two questions. Having seen your examples of defined types helps me understand how to handle this in puppet. But I think my main problem is that there isn't a way to cause action_url to be absent unless it is not mentioned at all in the @@nagios_host resource at all. It seems the only way to work around this is to have a defined type like this, but there is duplication.

define site::managd_host ($ilom_ip = undef) {
  if $ilom_ip {
    # Nagios_host with ilom parameter in notes_url
    @@nagios_host { $::fqdn:
      ensure     => present,
      address    => $::ipaddress,
      action_url => "/nagios/pnp4nagios/graph?host=${::fqdn}",
      notes_url  => $ilom_ip,
    }
  } else {
    # No notes_url
    @@nagios_host { $::fqdn:
      ensure     => present,
      address    => $::ipaddress,
      action_url => "/nagios/pnp4nagios/graph?host=${::fqdn}",
    }
  }
}

Thanks,
Jonathan

Reply all
Reply to author
Forward
0 new messages