wiki:how-to/servers/puppet/setup-nagios-monitor

Version 3 (modified by Ross, 6 years ago) (diff)

--

Creating a nagios monitor

This page explains how to create a nagios monitor configuration in puppet. You will need to make changes to get the correct configuration for the specific type of monitoring needed.

Set up an executable

These files are stored in puppet/modules/mayfirst/files/monitor-utils/ you can find examples of different versions of monitoring scripts there.

Set up a cronjob

projects/puppet/modules/mayfirst/templates/monitor-utils/cron.d/mf-monitor

You'll need to add your script to this directory.

Add to utils.pp

puppet/modules/mayfirst/manifests/utils.pp

The code should look something like this, with the correct file from the executable specified.:

  file { "/usr/local/sbin/mf-monitor-mailq":
    source => "puppet:///modules/mayfirst/monitor-utils/mf-monitor-mailq",
    ensure => present,
    mode => 755,
    owner => "root",
    group => "root"
  }

Define hostgroup

projects/puppet/modules/mayfirst/files/nagios/nagios3/conf.d/

This code section should look something like this:

define hostgroup {
  hostgroup_name  mailq-servers
  alias           Mail Check Servers
}

Define nagios command

puppet/modules/mayfirst/files/nagios/nagios3/commands.cfg

Should look like this:

define command{
  command_name    check-upgrade
  command_line    /usr/local/share/nagios/plugins/mf-nagios-check-upgrade '$HOSTNAME$'
}

Create parsing script

You will also need to create a script that parses the output of the monitoring files.

puppet/modules/mayfirst/files/nagios/nagios-plugins/plugins/mf-SCRIPT-NAME

You can model scripts that already exist to check this.

Add the check as a service

The service part of the infrastructure is the display component for nagios.

puppet/modules/mayfirst/files/nagios/nagios3/conf.d/services_nagios2.cfg

Copy a pre-existing stanza and make the necessary changes. It will look something like this:

define service{
        hostgroup_name                  upgrade-servers
        service_description             Upgrade 
        check_command                   check-upgrade
        notification_interval           0
        use                             generic-service
}

Finally add the hostgroup to nagios manifest

projects/puppet/modules/mayfirst/manifests/nagios.pp

One example for standard_hostgroups is:

  if ( $include_standard_hostgroups == true ) {
    $standard_hostgroups = [ 'df-servers', 'upgrade-servers', 'mailq-servers' ]
    $assigned_hostgroups = concat($hostgroups, $standard_hostgroups)
  } else {
    $assigned_hostgroups = $hostgroups
    
  }

This is from 'define m_nagios_host'.

Make sure all executable scripts have execute permissions