Puppet push Nagios


With the storeconfigs enabled, I am able to push Naigos via Puppet. It is really simple and straighforward, as Puppet already support nagios_* type.

How it works? Below is my sample codes. It can be downloaded from here.

sys_nagios::client is the class for Nagios client, it sends the hosts’ facts to Puppet master then the data will be saved into the DB. sys_nagios::server is the class for Nagios server, it collects the latest data of the Nagios clients from the DB then generates the updated Nagios configuration files for host, hostgroup, service, servicegroup …

@@ means exporting the facts to DB
<<||>> means collecting the facts from DB.

class sys_nagios::client {

$cfgpath = “/etc/nagios/conf.d”

@@nagios_host { “$fqdn”:
ensure => present,
alias => $fqdn,
address => $ipaddress_eth1,
use => “linux-server”,
hostgroups => “$environment, linux-servers”,
target => “$cfgpath/host_$fqdn.cfg”,
}

}

class sys_nagios::server {

$cfgpath = “/etc/nagios/conf.d”

package { [
‘nagios’,
‘nagios-plugins-all’,
‘nagios-plugins-nrpe’
]:
ensure => installed,
}

service { ‘nagios’:
ensure => running,
enable => true,
hasrestart => true,
hasstatus => true,
require => Package[nagios],
}
###### hostgroup starts ######

@@nagios_hostgroup { ‘production’:
ensure => present,
alias => production,
target => “$cfgpath/hostgroups.cfg”
}

@@nagios_hostgroup { ‘development’:
ensure => present,
alias => development,
target => “$cfgpath/hostgroups.cfg”
}

###### hostgroup ends ######

###### commands starts ######

###### commands ends ######

###### servicegroup starts ######

@@nagios_servicegroup { ‘infrastructure’:
ensure => present,
alias => infrastructure,
target => “$cfgpath/servicegroups.cfg”
}

###### servicegroup ends ######

###### infrastructure services start ######

@@nagios_service { “check_ping_infrastructure”:
check_command => “check_ping!5.0,2%!10.0,10%”,
use => “generic-service”,
service_description => “check ping”,
hostgroup_name => “production,development”,
servicegroups => “infrastructure”,
target => “$cfgpath/service_check_infrastructure.cfg”,
}

@@nagios_service { “check_ssh_infrastructure”:
check_command => “check_ssh”,
use => “generic-service”,
service_description => “check ssh”,
hostgroup_name => “production,development”,
servicegroups => “infrastructure”,
target => “$cfgpath/service_check_infrastructure.cfg”,
}

###### infrastructure services end ######

###### collect starts ######

Nagios_host <<||>> {
notify => [ Exec[cfg_chmod], Service[nagios] ]

}

Nagios_service <<||>> {
notify => [ Exec[cfg_chmod], Service[nagios] ]
}

Nagios_command <<||>> {
notify => [ Exec[cfg_chmod], Service[nagios] ]
}

Nagios_hostgroup <<||>> {
notify => [ Exec[cfg_chmod], Service[nagios] ]
}

Nagios_servicegroup <<||>> {
notify => [ Exec[cfg_chmod], Service[nagios] ]
}

###### collect ends ######
exec { ‘cfg_chmod’:
command => “/bin/chmod 664 $cfgpath/*”,
}
}

Selection_002 Selection_003

References:

http://blog.gurski.org/index.php/2010/01/28/automatic-monitoring-with-puppet-and-nagios/
http://www.linuxjournal.com/content/puppet-and-nagios-roadmap-advanced-configuration?page=0,3

Advertisement

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 )

Connecting to %s