service rhysd reload

Building Nagios Config With Puppet

Dragging up a half finished post from the past AFAIK its still relevant and no less awesome

Building nagios config with puppet!!1

This setup uses exported resources and this requires your puppetmaster to be setup to use stored configuration. So we need to turn it on and install puppetdb.

puppet.conf
1
2
3
[puppetmasterd]
storeconfigs = true
dbadapter = puppetdb

Use the Puppet labis puppetdb module (because its easy and maintained)

puppet module install puppetlabs-puppetdb

or

wget https://forgeapi.puppetlabs.com/v3/files/puppetlabs-puppetdb-3.0.1.tar.gz

site.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 node puppetmaster.rhysd.co.nz
  class { 'puppetdb::server':
    database => postgres,
    database_name     => puppetdb,
    database_username => 'puppet',
    database_password => 'use_pwgen_you_monkey',
    database_host     => 'localhost',
    database_port     => '5432',
   }

  class { 'puppetdb::master::config':
    puppetdb_server => 'puppetmaster.rhysd.co.nz',
    puppetdb_port   => 8081,
    puppet_conf => '/etc/puppet/puppet.conf',
  }

Yes you should use puppet to manage puppet!!!!!!!

Now for the good stuff

nagios.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class nagios::checks {
      @@nagios_host { $fqdn:
         ensure => present,
         alias => $hostname,
         address => $ipaddress,
         use => "generic-host",
         target => "/etc/puppet/modules/nagios/files/host_${::fqdn}.cfg"
      }

      @@nagios_hostextinfo { $fqdn:
         ensure => present,
         icon_image_alt => $operatingsystem,
         icon_image => "base/$operatingsystem.png",
         statusmap_image => "base/$operatingsystem.gd2",
         target => "/etc/puppet/modules/nagios/files/host_${::fqdn}.cfg"
      }

      @@nagios_service { "check_ping_${hostname}":
         use => "check_ping",
         host_name => "$fqdn",
         target => "/etc/puppet/modules/nagios/files/host_${::fqdn}.cfg"
      }
}
site.pp
1
2
3
4
node 'nagios.rhysd.co.nz' {
  Nagios_Host <<||>>
  Nagios_Service <<||>>
}

This is a basic example setting a nagios host and a ping check. In this each host has its own nagios configation file into the nagios modules file directory.

Where this technique becomes powerful is when you start adding nagios service checks to other modules to mantain total monitoring coverage. RAWR

Comments