Puppet: Nagios3 module

On my previous post I told how I got Windows monitoring working with Nagios. The post included a puppet module for the NSClient, which Nagios uses to communicate with Windows. The most important module in that setup is obviously the actual Nagios3 module. Which manages the Nagios server and all the hosts. I’ve been working on it for couple of days now and although it’s not complete, it works and is already available on our github.

You can find the module here:
https://github.com/awaseroot/awaseroot/blob/master/puppet/modules/nagios3/manifests/init.pp

UPDATE: This post doesn’t represent the current module very accurately anymore since I keep improving the module from time to time. If you want to see the original module, it can still be found from the git version history: Original
And the updated version of the module is here: Current

- – -

Only Ubuntu is supported and tested at the moment. I’ve tested the module with Ubuntu 12.10.

The packages that the module will install:
nagios3
nagios-nrpe-plugin
libapache2-mod-php
libgs2-xpm-dev
apache2

The module manages these services:
nagios3
apache2

The module manages these files:
/etc/nagios-plugins/config/nt.cfg
/etc/nagios3/nagios.cfg
/etc/nagios3/commands.cfg
/etc/nagios3/htpasswd.users
/etc/nagios3/objects
/etc/nagios3/objects/templates.cfg
/etc/init.d/nagios3

I had to include a modified version of the init.d/nagios3 as well since I had some trouble restarting the service with puppet using the original init.d/nagios3 script.

The nagios user and password is defined in the htpasswd.users file. Both username and password is nagiosadmin.
This is the user that is used when you log into your nagios3 website http://localhost/nagios3. (replace localhost with your server address)

In addition to those files, the module creates these config files using puppet’s own resources:
/etc/nagios3/objects/nagios_hostgroup.cfg
/etc/nagios3/objects/nagios_services.cfg
/etc/nagios3/objects/linux_hosts.cfg
/etc/nagios3/objects/windows_hosts.cfg

The puppet resources for managing above config files:

nagios_hostgroup
This one manages the hostgroups for nagios. I’ve included two groups, one for linux and one for windows hosts.

Nagios_hostgroup { require => Package['nagios3'], notify => Service['nagios3'], }

nagios_hostgroup { 'linuxhosts':
  target => '/etc/nagios3/objects/nagios_hostgroup.cfg',
}
nagios_hostgroup { 'winhosts':
  target => '/etc/nagios3/objects/nagios_hostgroup.cfg',
}

nagios_service
This resource manages nagios services for hosts. The services are stored in nagios_services.cfg.

Nagios_service {
  require => Package['nagios3'],
  notify  => Service['nagios3'],
  target  => '/etc/nagios3/objects/nagios_services.cfg',
  use     => 'generic-service'
}

nagios_service { 'check_load':
  hostgroup_name      => 'linuxhosts',
  check_command       => 'check_nrpe_1arg!check_load',
  service_description => 'CPU Load',
}

The check_load service is for the hosts which belong to the linuxhosts group.

You can find more nagios_service resources from the module.

linuxhost (nagios_host)
I’ve created this definition type for managing linux hosts. It uses nagios_host resource to create the nagios configuration. The hosts are stored in linux_hosts.cfg

define linuxhost ($name,$address) {

  nagios_host { $title:
    target  => '/etc/nagios3/objects/linux_hosts.cfg',
    use     => 'linux-box',
    alias   => $name,
    address => $address,
    require => Package['nagios3'],
    notify  => Service['nagios3'],
  }
}

winhosts
This is similiar to linuxhost but manages windows hosts instead.

define winhost ($name,address) {
  nagios_host { $title:
    target  => '/etc/nagios3/objects/windows_hosts.cfg',
    use     => 'windows-server',
    alias   => $name,
    address => $address,
    require => Package['nagios3'],
    notify  => Service['nagios3'],
  }
}

The objects directory is set as a configuration directory for nagios in the nagios.cfg with this line:

cfg_dir=/etc/nagios3/objects

This means that nagios will include all .cfg files in the objects directory in it’s configuration.

The templates.cfg has host templates for both Linux and Windows hosts.

How to use the module

You can get the module by copying our git repository. Find and copy the module from there to your /etc/puppet/modules/
tar.gz: https://github.com/awaseroot/awaseroot/archive/master.tar.gz
git: git clone https://github.com/awaseroot/awaseroot.git

In your puppet manifest you should define the hosts that you are about to monitor with nagios.

Example:

/etc/puppet/manifests/site.pp

node 'hngu.elisa' {
  class { 'nagios3':
    version => 'latest',
  }
  linuxhost { 'linux1':
    name    => 'Ubuntu Linux',
    address => 'my_linux.local',
  }
  linuxhost { 'linux2':
    name    => 'Xubuntu Linux',
    address => '192.168.100.111'
  }
  winhost { 'win1':
    name    => 'windows',
    address => 'my_windows.local',
  }
}

You also need to have the nagios-nrpe-server on your linux hosts and nsclient++ on your windows hosts so that your server can communicate with them.

I do have modules for both (you have them as well since you downloaded our git repo already):
nagios-nrpe-server
nsclient++

Then you just include them as well in your manifest:

site.pp

node 'my_linux.local' { include nagios_nrpe }

node 'my_windows.local' { include nscp }

Notice that you have to add your nagios server to the allowed hosts in the nagios_nrpe module: files/nagios.cfg
Failing to do this will result in “Connection refused by host” error message.

If you have problems with the nsclient, check my previous post.

I will keep updating this module in the coming days.

About these ads

4 responses to “Puppet: Nagios3 module

  1. cyberfrk January 30, 2013 at 5:47 pm

    Hello,

    Sorry for my bad english (I’m French).

    Despite my many searches, I can not properly configure Puppet on my server debian for windows nodes (xp or 7). I do not worry about copying a file server to a client debian in debian. This means that the DNS service and conf files are functional.

    It all works virtualized machine under virtualbox.

    Have you ever managed to use puppet (under debian) and windows 7′s client?

    Thanking you in advance,
    Franck

  2. Pingback: Page not found « awaseroot

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: