Nagios cookbook requires non-standard attributes within the "users" data bag for admins?

Folks,

This is another one where I had opened a discussion on this subject at help.opscode.com, and where I am now moving this thread to this list instead.

Anyway, I have been following as best I can the Nagios quick start tutorial (seeing as I’m on CentOS 5.6 and not Ubuntu, this means there’s a lot of stuff I have to do differently), and it seems that the file nagios/templates/default/contacts.cfg.erb requires some non-standard attributes to be defined for the admins (I added line numbers to make it easier to see what error was happening where):

25 <% @admins.each do |a| -%>
26 define contact {
27 use default-contact
28 contact_name <%= a[‘id’] %>
29 email <%= a[‘nagios’][‘email’] %>
30 }

However, in the “users” data bag, the attribute [‘nagios’][‘email’] is not defined for any of our admins. So, this value is nil, and we get this error when trying to install this cookbook:

[Thu, 22 Sep 2011 17:52:14 +0000] INFO: Processing template[/etc/nagios3/conf.d/contacts.cfg] action create (nagios::server line 28)
[Thu, 22 Sep 2011 17:52:14 +0000] ERROR: template[/etc/nagios3/conf.d/contacts.cfg] (nagios::server line 28) has had an error
[Thu, 22 Sep 2011 17:52:14 +0000] ERROR: template[/etc/nagios3/conf.d/contacts.cfg] (/var/chef/cache/cookbooks/nagios/definitions/nagios_conf.rb:28:in block in from_file') had an error: Chef::Mixin::Template::TemplateError (undefined method[]’ for nil:NilClass) on line #29:

27: use default-contact
28: contact_name <%= a[‘id’] %>
29: email <%= a[‘nagios’][‘email’] %>
30: }
31:

Correct me if I’m wrong, but is this template assuming that all admins should get all nagios notices sent by e-mail? What if we have several admins defined on the machine but who should not get the notices?

Assuming I’m correct, then shouldn’t you test a[‘nagios’][‘email’] != nil before you try to use it in an assignment on line 29, and if it is nil then skip over this particular admin?

Unfortunately, this issue is preventing me from installing the Nagios cookbook from the Opscode repository. I’m now moving on to try the icinga cookbook, to see if that works any better.

Any and all advice or suggestions would be appreciated. Thanks!


Brad Knowles bknowles@ihiji.com
SAGE Level IV, Chef Level 0.0.1

On 09/22/2011 05:52 PM, Brad Knowles wrote:

Folks,

This is another one where I had opened a discussion on this subject at help.opscode.com, and where I am now moving this thread to this list instead.

Anyway, I have been following as best I can the Nagios quick start tutorial (seeing as I'm on CentOS 5.6 and not Ubuntu, this means there's a lot of stuff I have to do differently), and it seems that the file nagios/templates/default/contacts.cfg.erb requires some non-standard attributes to be defined for the admins (I added line numbers to make it easier to see what error was happening where):

25<% @admins.each do |a| -%>
26 define contact {
27 use default-contact
28 contact_name<%= a['id'] %>
29 email<%= a['nagios']['email'] %>
30 }

However, in the "users" data bag, the attribute ['nagios']['email'] is not defined for any of our admins. So, this value is nil, and we get this error when trying to install this cookbook:

[Thu, 22 Sep 2011 17:52:14 +0000] INFO: Processing template[/etc/nagios3/conf.d/contacts.cfg] action create (nagios::server line 28)
[Thu, 22 Sep 2011 17:52:14 +0000] ERROR: template[/etc/nagios3/conf.d/contacts.cfg] (nagios::server line 28) has had an error
[Thu, 22 Sep 2011 17:52:14 +0000] ERROR: template[/etc/nagios3/conf.d/contacts.cfg] (/var/chef/cache/cookbooks/nagios/definitions/nagios_conf.rb:28:in block in from_file') had an error: Chef::Mixin::Template::TemplateError (undefined method ' for nil:NilClass) on line #29:

27: use default-contact
28: contact_name<%= a['id'] %>
29: email<%= a['nagios']['email'] %>
30: }
31:

Correct me if I'm wrong, but is this template assuming that all admins should get all nagios notices sent by e-mail? What if we have several admins defined on the machine but who should not get the notices?

Assuming I'm correct, then shouldn't you test a['nagios']['email'] != nil before you try to use it in an assignment on line 29, and if it is nil then skip over this particular admin?

Unfortunately, this issue is preventing me from installing the Nagios cookbook from the Opscode repository. I'm now moving on to try the icinga cookbook, to see if that works any better.

Any and all advice or suggestions would be appreciated. Thanks!

It really shouldn't be too hard to change that. You could add another
field to the data bag indicating if this person should get
notifications. Then add some logic to add only those people to the
contact group. The rest of the users in the data bag will still be able
to log in to the interface because that access is set somewhere else.

Note that those users would still have admin access to the server. If
you want to create read-only users you'd have to modify it a bit more
and create a separate contact group for read only users.

I don't think that these community cookbooks are meant to be everything
to everyone, but rather a good starting point for most people to build on.

-erik

Hi Brad!

On Thu, Sep 22, 2011 at 2:52 PM, Brad Knowles bknowles@ihiji.com wrote:

27: use default-contact
28: contact_name <%= a['id'] %>
29: email <%= a['nagios']['email'] %>
30: }
31:

Correct me if I'm wrong, but is this template assuming that all admins should get all nagios notices sent by e-mail? What if we have several admins defined on the machine but who should not get the notices?

Assuming I'm correct, then shouldn't you test a['nagios']['email'] != nil before you try to use it in an assignment on line 29, and if it is nil then skip over this particular admin?

You're right, it probably should. Our use of the nagios cookbook is
closely coupled with the users cookbook, since both were used in our
own infrastructure for Hosted Chef. The test should actually be in the
recipe before it passes that variable into the template, so we reduce
the amount of logic embedded in the template.

Would you please open a ticket in the COOK project at
tickets.opscode.com if you have not done so already?

Thank you!

--
Opscode, Inc
Joshua Timberman, Director of Training and Services
IRC, Skype, Twitter, Github: jtimberman

On Sep 23, 2011, at 1:05 AM, Joshua Timberman wrote:

You're right, it probably should. Our use of the nagios cookbook is
closely coupled with the users cookbook, since both were used in our
own infrastructure for Hosted Chef. The test should actually be in the
recipe before it passes that variable into the template, so we reduce
the amount of logic embedded in the template.

Makes sense.

Would you please open a ticket in the COOK project at
tickets.opscode.com if you have not done so already?

Done. COOK-769. Thanks again!

--
Brad Knowles bknowles@ihiji.com
SAGE Level IV, Chef Level 0.0.1