Puppet & Nagios

89 views
Skip to first unread message

guerremdq

unread,
Jun 28, 2013, 2:26:05 PM6/28/13
to example42-pu...@googlegroups.com
Hi !
 
I'm using the module puppet-nagios to add the host on the monitor server. I need to define differents templates.
It's possible to change the $nagios_baseservices_template  with diferents templates according the Puppet manifest?



Thanks.

Alessandro Franceschi

unread,
Jun 28, 2013, 5:41:24 PM6/28/13
to example42-pu...@googlegroups.com
You can set the template to use for a node with the top scope $::nagios_baseservices_template variable , so either you evaluate it in /etc/puppet/manifests/site.pp (or in any case in the top scope, before declaring nodes) on in an External Node Classifier, like The Foreman.
It's up to you to decide the logic and the template to apply to different nodes.

guerremdq

unread,
Jun 28, 2013, 7:57:49 PM6/28/13
to example42-pu...@googlegroups.com
So, if i'm no using a External Node Classifier i can not set a different $::nagios_baseservices_template. ?

This is my site.pp =

# site.pp
#
$nagios_customconfigdir = '/etc/nagios3/auto.d'
import "nodes/varnish1.pp"
import "nodes/web-servers.pp"

and the web-server.pp  =


$nagios_baseservices_template = 'nagios/webbaseservices.erb'

node webserver1   {

......
}


and the varnish1.pp =

$nagios_baseservices_template = 'nagios/varnishbaseservices.erb'

node varnish1   {
......
}



Alessandro Franceschi

unread,
Jun 29, 2013, 2:40:06 AM6/29/13
to example42-pu...@googlegroups.com
Sadly you can't redefine the variable so you'll have to do something like (if you have a variable called role, for example):
$nagios_baseservices_template = $role { 
  varnish => 'my_site/nagios/varnishbaseservices.erb', # Better to place custom templates outside the module
  webserver => 'my_site/nagios/webbaseservices.erb',
...
}
In this case you need to have a role variable somehow assigned as fact, or you can use in the selector the hostname and ground using regular expressions.

Note also that you might decide to keep a single commong template for the base services and add, n another file, specific services for the different kind of servers (roles).

guerremdq

unread,
Jun 29, 2013, 12:06:19 PM6/29/13
to example42-pu...@googlegroups.com
The selector goes on the site.pp or in the module? 
It's possible to add extra files with the specific services with this module?


Alessandro Franceschi

unread,
Jun 29, 2013, 2:55:39 PM6/29/13
to example42-pu...@googlegroups.com
Yes, the selector goes on site.pp, the basic point is that all the variables that refer to resources exported by a node and collected on the Nagios server have to be defined at top scope.
You can add specific service checks for a node (on the node, or in the "role" class or here you want) using the nagios::service define (https://github.com/example42/puppet-nagios/blob/master/manifests/service.pp).
Note that you are not supposed to modify anything of the nagios module, the logic behind all the Example42 modules is that they should be reusable as is, allowing you to customized their behaviours according to your needs without changing anything inside the module: if you have to do it, either the module has some missing feature or you are not using it in the "right" way.


al

guerremdq

unread,
Jun 30, 2013, 6:46:48 PM6/30/13
to example42-pu...@googlegroups.com
Ok, Thanks for the explanation .
So, this is correct :

site.pp =


$nagios_baseservices_template = $role { 
  varnish => 'my_site/nagios/varnishbaseservices.erb', # Better to place custom templates outside the module
  webserver => 'my_site/nagios/webbaseservices.erb',
}

node webserver {
         $role='webserver'
}

node varnish {
         $role = 'varnish'

}



Thanks

Alessandro Franceschi

unread,
Jul 1, 2013, 4:49:00 AM7/1/13
to example42-pu...@googlegroups.com
Actually not, not in this way.
You can use the $role in the selector if the value is already defined.
So either you set it via a fact or (but I'm not sure it will work) first you define the nodes (and the role variable) and then you use it in the selector and only at the end you can include a common class where all your resources are managed:

node webserver {
         $role='webserver'
}

node varnish {
         $role = 'varnish'
}
$nagios_baseservices_template = $role { 
  varnish => 'my_site/nagios/varnishbaseservices.erb', # Better to place custom templates outside the module
  webserver => 'my_site/nagios/webbaseservices.erb',
}

include my_class # Here you can include the role classes and all the common resources.

Anyway note that setting the $role in the node won't allow you to refer to the $role variable in other classes (with Puppet 3).
So you might prefere a "nodeless" setup, like the one shown here:
https://github.com/example42/puppet-infrastructures/blob/master/site.pp

guerremdq

unread,
Jul 1, 2013, 8:24:51 PM7/1/13
to example42-pu...@googlegroups.com
I try using the 'nodeless' setup but is not working
this is the site.pp :

case $::hostname {

    /^lucene/: {
      $role = 'lucene'
      $env = 'prod'
    }

    /^web/: {
      $role = 'web'
      $env = 'prod'
    }

  }

$nagios_baseservices_template = $role ? {
  lucene => 'nagios/lucene1.erb',
  web => 'my_site/nagios/webbaseservices.erb',
  default => 'nagios/baseservices.erb'
}


it's possible to include a subtemplate? may be a can do this logic on the baseservice.erb .



Alessandro Franceschi

unread,
Jul 2, 2013, 3:44:56 AM7/2/13
to example42-pu...@googlegroups.com
Uhm, that code should work, even if it's not probably the most appropriate.
You can follow an alternative approach, moving as you suggested, the logic in a single baseservices template.
You could set a single custom nagios_baseservices_template and place there (with if statements) the different basic  settings for the different roles.
Remember also that you can place any custom extra service check at the role level, either using the monitor defines (check the monitor role for that) or directly the nagios::service define in the specific role classes.

guerremdq

unread,
Jul 3, 2013, 9:25:51 AM7/3/13
to example42-pu...@googlegroups.com
Yes, i'm think that i going to pass all the logic to the templates. It's possible to add sub Templates ?
So i can use the selector in the base services template and include others templates for differentes roles?

Thanks

Alessandro Franceschi

unread,
Jul 3, 2013, 9:34:37 AM7/3/13
to example42-pu...@googlegroups.com
The baseservices template is just a nagios configuration file with some service checks, so you can definitively add other custom files where you add specific checks for specific roles.

If I were you:
1- I'd provide a custom baseservice template for all the nodes with only checks that are appropriate for all the nodes.
2a- In the role classes (if you have them) I'd add either nagios::process or monitor::* defines that add specific checks for the role
2b- Alternatively to 2a, I'd provide, in the role class, a single custom file with all the Nagios cofnigurations you want to add to that role

Note that this file has to be exported by the node and collected by the Nagios server, so you would need something like (this has been copied from https://github.com/example42/puppet-nagios/blob/master/manifests/baseservices.pp you will have to change the title and the content:
      @@file { "${nagios::target::customconfigdir}/services/${hostname}-00-baseservices.cfg":
        ensure => $ensure,
        mode => '0644',
        owner => 'root',
        group => 'root',
        notify => Service['nagios'],
        content => template( $template ),
        tag => "nagios_check_${nagios::target::magic_tag}",
      }
Reply all
Reply to author
Forward
0 new messages