Nagios default files being overwritten

44 views
Skip to first unread message

druide...@gmail.com

unread,
Feb 11, 2014, 9:53:42 AM2/11/14
to puppet...@googlegroups.com
Hi,

I have a strange problem here. Most of my Nagios configuration are from file {} directive, but I also need to modify a couple of Nagios' default configuration. To do this, I use classes like this:

class nagios::gabarits { 

   nagios_host { 'linux-server': 
     use => 'generic-host', 
     check_period => '24x7', 
     check_interval => 5, 
     retry_interval => 1, 
     max_check_attempts => 10, 
     check_command => 'check-host-alive', 
     notification_period => 'notifications', 
     notification_interval => 120, 
     notification_options => 'd,u,r', 
     contact_groups => 'admins', 
     register => 0, 
     statusmap_image => 'linux40.png', 
     target => '/etc/nagios/objects/templates.cfg', 
     ensure => present, 
   }

 }

Problem is: it replace the content of /etc/nagios/objects/templates.cfg with the new host definition, but everything else in the file is gone! 


Matthias Saou

unread,
Feb 11, 2014, 11:14:44 AM2/11/14
to puppet...@googlegroups.com
On Tue, 11 Feb 2014 06:53:42 -0800 (PST)
druide...@gmail.com wrote:

> I have a strange problem here. Most of my Nagios configuration are
> from file {} directive, but I also need to modify a couple of Nagios'
> default configuration. To do this, I use classes like this:
>
> class nagios::gabarits {
>
> nagios_host { 'linux-server':
> use => 'generic-host',
[...]
> target => '/etc/nagios/objects/templates.cfg',
> ensure => present,
> }
>
> }
>
> Problem is: it replace the content
> of /etc/nagios/objects/templates.cfg with the new host definition,
> but everything else in the file is gone!

I think that's the expected behaviour.
The proper fix is to also declare the other nagios resources you want
to see in that file.

That's more or less how I solved it in my own module :
https://github.com/thias/puppet-nagios/blob/master/manifests/server.pp#L550
(feel free to copy/paste those lines!)

Though I did "move" all of the resources to their default files and
stopped using the objects/templates.cfg file.

HTH,
Matthias

--
Matthias Saou ██ ██
██ ██
Web: http://matthias.saou.eu/ ██████████████
Mail/XMPP: matt...@saou.eu ████ ██████ ████
██████████████████████
GPG: 4096R/E755CC63 ██ ██████████████ ██
8D91 7E2E F048 9C9C 46AF ██ ██ ██ ██
21A9 7A51 7B82 E755 CC63 ████ ████

Pascal Robert

unread,
Feb 11, 2014, 4:28:46 PM2/11/14
to puppet...@googlegroups.com
Hum. Since I only want to override 3 definitions, I think I'm simply going to stop using them.

Jason Antman

unread,
Feb 11, 2014, 5:38:29 PM2/11/14
to puppet...@googlegroups.com
Agreed with what Matthias said. Puppet's naginator stuff doesn't play
very well with non-Puppet nagios configurations. Essentially, you have
to pick one of:
- remove the default template from that file, and create it with Puppet
elsewhere
- put all of the contents of that file in Puppet
- totally remove all of the default object configuration, and have
Puppet do everything (what I do)

On the other hand, I don't use templates in Nagios anymore, I find them
to be redundant. I use a combination of defines and parameterized
classes (hiera would be good here too, though I don't use it) and have
Puppet write out complete definitions for hosts/services/etc without any
templates. I find that makes it much more clear to look at one resource
in Puppet and know what it does, and reduces the likelihood that a
template will get modified and have unintended consequences for objects
that use it.

-Jason
Reply all
Reply to author
Forward
0 new messages