I've been working for the past two days on transforming a Nagios module
to make it "hostgroup"-aware, that is, to include hosts in groups to
reuse services intead of always redefining them for every host.
I tested giving a list of strings to the "hostgroups" attribute to the
nagios_host resource but it only considers the first element of the list.
Is there a way to "collect" unique group names for a single host and to
concatenate the final result in a comma separated string? The purpose of
this would be to make modules add nagios groups to the hosts if they
have those services installed.
--
Gabriel Filion
That's exactly what I'd like to do. Trying this generates a host config
for nagios with only "group1" in the "hostgroups" line.
> I haven't tried what youre doing, but sounds like it might be a Type/
> Provider bug.
>
bug or missing feature.. I haven't tried it with 0.25.5, though. I'm on
Debian unstable, using the puppet/puppetmaster packages, so the version
is 0.25.4
should I open a bug report about this?
>> Is there a way to "collect" unique group names for a single host and to
>> concatenate the final result in a comma separated string? The purpose of
>> this would be to make modules add nagios groups to the hosts if they
>> have those services installed.
>
> You might be able to use a template or function to join() your array.
>
> class bar{
> $nagios_hostgroups += ["group1"]
> }
>
> class foo {
> include bar
> $nagios_hostgroups += ["group2"]
> nagios_host {
> "$fqdn":
> address => "$ipaddress",
> hostgroups => template("join_hostgroups.erb")
> }
> }
>
> join_host_groups.erb:
> <%= nagios_hostgroups.join(',') %>
>
Interesting. I'll try this out in the next few days and give you
feedback on whether this workaround does the job.
--
Gabriel Filion
The trick with the template did the job for transforming an array into a
comma-separated string.
However, concatenating groups with "$nagios_hostgroups += ['something']"
in each included class is too restrictive: because of the scope of
variables, I never get the entire list during the call to the define
that exports the "nagios_host" resource. Also, with qualified variable
names, I cannot modify the value in higher scopes.
I've tried figuring out virtual resources but they don't seem to be of
any help here either for simple arrays..
Any other ideas of how to acumulate values in an array for the entire node?
--
Gabriel Filion
On 2010-06-15 21:17, donavan wrote:
> On Jun 14, 11:07 pm, Gabriel Filion <lelu...@gmail.com> wrote:
>> bug or missing feature.. I haven't tried it with 0.25.5, though. I'm on
>> Debian unstable, using the puppet/puppetmaster packages, so the version
>> is 0.25.4
>>
>> should I open a bug report about this?
>
> Take a look on puppet-dev group and the issues db. If there's nothing
> found I'd just open a bug. Worst case it's a no action and youre in
> the same spot.
>
For those interested, I've opened a feature request for supporting lists
with the "hostgroups" argument to nagios_host:
http://projects.puppetlabs.com/issues/4020
There is also a possibility that this feature could be useful with other
nagios resource values. If you think of any other that you'd like to see
support lists of strings, then please comment on this feature request.
>> Interesting. I'll try this out in the next few days and give you
>> feedback on whether this workaround does the job.
>
> If you use a variable, like $nagios_hostgroups, you may also need to
> specify the namespace. As an example ${nagios::nagios_hostgroups}
> provides a way to access your variable from any other class. Don't
> recall how that works with templates though.
>
Maybe using an external function to store the collected values could be
a solution.. but then, we would be somewhat reimplementing puppet's
virtual resource realization feature.
Does anyone see an interest in making puppet able to collect values into
a list from arbitrary sub-scopes, other than for implementing host-based
nagios configuration?
--
Gabriel Filion