# Install Nagios server. # class nagios::server { case $operatingsystem { "centos","redhat","fedora": { $etcdir = "/etc/nagios" $confdir = "${etcdir}/conf.d" $private = "${etcdir}/private.d" $package = "nagios" $service = "nagios" $scriptalias = "/nagios/cgi-bin/" $libdir = $architecture ? { "x86_64" => "/usr/lib64/nagios/plugins", default => "/usr/lib/nagios/plugins", } $cgibin = $architecture ? { "x86_64" => "/usr/lib64/nagios/cgi-bin", default => "/usr/lib/nagios/cgi-bin", } $htdocs = "/usr/share/nagios/html" } "ubuntu","debian": { $etcdir = "/etc/nagios3" $confdir = "${etcdir}/conf.d" $private = "${etcdir}/private.d" $package = "nagios3" $service = "nagios3" $scriptalias = "/cgi-bin/nagios3/" $libdir = "/usr/lib/nagios/plugins" $cgibin = "/usr/lib/cgi-bin/nagios3" $htdocs = "/usr/share/nagios3/htdocs" } default: { fail("nagios::server not supported on ${::operatingsystem}") } } package { "nagios": name => $package, ensure => installed, } case $operatingsystem { "centos","redhat","fedora": { package { [ "nagios-plugins-all", "nagios-plugins-nrpe", ]: ensure => installed, } } "ubuntu","debian": { package { [ "nagios-plugins", "nagios-nrpe-plugin", ]: ensure => installed, } file { "/usr/share/nagios3/htdocs/stylesheets": ensure => link, target => "/etc/nagios3/stylesheets", } } } service { "nagios": name => $service, ensure => running, enable => true, } apache::configfile { "nagios.conf": content => template("nagios/nagios-httpd.conf.erb"), } file { [ "${htdocs}/.htaccess", "${cgibin}/.htaccess" ]: ensure => present, mode => "0644", owner => "root", group => "root", source => [ "puppet:///files/nagios/htaccess", "puppet:///modules/nagios/htaccess.${osfamily}", ], require => Package["nagios"], } file { "/etc/nagios/nagios.cfg": name => "${etcdir}/nagios.cfg", ensure => present, mode => "0644", owner => "root", group => "root", source => "puppet:///modules/nagios/nagios.cfg.${osfamily}", require => Package["nagios"], notify => Service["nagios"], } file { "/etc/nagios/cgi.cfg": name => "${etcdir}/cgi.cfg", ensure => present, mode => "0644", owner => "root", group => "root", content => template("nagios/cgi.cfg.erb"), require => Package["nagios"], notify => Service["nagios"], } file { "/etc/nagios/commands.cfg": name => "${etcdir}/commands.cfg", ensure => present, mode => "0644", owner => "root", group => "root", source => "puppet:///modules/nagios/commands.cfg", require => Package["nagios"], notify => Service["nagios"], } file { "/etc/nagios/conf.d": name => $confdir, ensure => directory, mode => "0640", owner => "root", group => "nagios", purge => true, force => true, recurse => true, source => "puppet:///modules/custom/empty", require => Package["nagios"], } file { "/etc/nagios/private.d": name => $private, ensure => directory, mode => "0640", owner => "root", group => "nagios", purge => true, force => true, recurse => true, source => "puppet:///modules/custom/empty", require => Package["nagios"], } file { "${confdir}/contactgroup_all.cfg": ensure => present, mode => "0640", owner => "root", group => "nagios", before => Nagios_Contactgroup["all"], require => File["/etc/nagios/conf.d"], } nagios_contactgroup { "all": target => "${confdir}/contactgroup_all.cfg", members => "*", notify => Service["nagios"], } file { "${confdir}/hostgroup_all.cfg": ensure => present, mode => "0640", owner => "root", group => "nagios", before => Nagios_Hostgroup["all"], require => File["/etc/nagios/conf.d"], } nagios_hostgroup { "all": target => "${confdir}/hostgroup_all.cfg", members => "*", notify => Service["nagios"], } file { "${confdir}/host_default.cfg": ensure => present, mode => "0640", owner => "root", group => "nagios", before => Nagios_Host["default"], require => File["/etc/nagios/conf.d"], } nagios_host { "default": target => "${confdir}/host_default.cfg", register => "0", notifications_enabled => "1", event_handler_enabled => "1", flap_detection_enabled => "1", failure_prediction_enabled => "1", process_perf_data => "1", retain_status_information => "1", retain_nonstatus_information => "1", check_command => "check-host-alive", max_check_attempts => "5", notification_interval => "0", notification_period => "24x7", notification_options => "d,u,r", contact_groups => "all", notify => Service["nagios"], } file { "${confdir}/service_default.cfg": ensure => present, mode => "0640", owner => "root", group => "nagios", before => Nagios_Service["default"], require => File["/etc/nagios/conf.d"], } nagios_service { "default": target => "${confdir}/service_default.cfg", register => "0", active_checks_enabled => "1", passive_checks_enabled => "1", parallelize_check => "1", obsess_over_service => "1", check_freshness => "0", notifications_enabled => "1", event_handler_enabled => "1", flap_detection_enabled => "1", failure_prediction_enabled => "1", process_perf_data => "1", retain_status_information => "1", retain_nonstatus_information => "1", notification_interval => "0", is_volatile => "0", check_period => "24x7", normal_check_interval => "5", retry_check_interval => "1", max_check_attempts => "2", notification_period => "24x7", notification_options => "w,u,c,r", contact_groups => "all", notify => Service["nagios"], } file { "${confdir}/timeperiod_24x7.cfg": ensure => present, mode => "0640", owner => "root", group => "nagios", before => Nagios_Timeperiod["24x7"], require => File["/etc/nagios/conf.d"], } nagios_timeperiod { "24x7": target => "${confdir}/timeperiod_24x7.cfg", alias => "24x7", monday => "00:00-24:00", tuesday => "00:00-24:00", wednesday => "00:00-24:00", thursday => "00:00-24:00", friday => "00:00-24:00", saturday => "00:00-24:00", sunday => "00:00-24:00", notify => Service["nagios"], } Nagios::Host <<||>> { confdir => $confdir, notify => Service["nagios"], } Nagios::Service <<||>> { confdir => $confdir, notify => Service["nagios"], } } # Define nagios email contact. # # === Parameters # # $name: # Email address. # define nagios::contact::email($confdir=$nagios::server::confdir) { file { "${confdir}/contact_${name}.cfg": ensure => present, mode => "0640", owner => "root", group => "nagios", before => Nagios_Contact[$name], require => File["/etc/nagios/conf.d"], } nagios_contact { $name: target => "${confdir}/contact_${name}.cfg", host_notification_commands => "notify-host-by-email", host_notification_options => "d,r", host_notification_period => "24x7", service_notification_commands => "notify-service-by-email", service_notification_options => "w,u,c,r", service_notification_period => "24x7", email => $name, notify => Service["nagios"], } } # Define nagios prowl contact. # # === Parameters # # $name: # Prowl API key. # define nagios::contact::prowl($confdir=$nagios::server::confdir) { file { "${confdir}/contact_${name}.cfg": ensure => present, mode => "0640", owner => "root", group => "nagios", before => Nagios_Contact[$name], require => File["/etc/nagios/conf.d"], } nagios_contact { $name: target => "${confdir}/contact_${name}.cfg", host_notification_commands => "notify-host-by-prowl", host_notification_options => "d,r", host_notification_period => "24x7", service_notification_commands => "notify-service-by-prowl", service_notification_options => "w,u,c,r", service_notification_period => "24x7", address1 => $name, notify => Service["nagios"], } } # Define nagios target host. # # === Parameters # # $name: # Hostname of target. # $osname: # Operating system name for hostextinfo. # $osicon: # Operating system icon name for hostextinfo. # define nagios::host($confdir, $osname="NONE", $osicon="NONE") { file { "${confdir}/host_${name}.cfg": ensure => present, mode => "0640", owner => "root", group => "nagios", before => Nagios_Host[$name], require => File["/etc/nagios/conf.d"], } nagios_host { $name: ensure => present, use => "default", target => "${confdir}/host_${name}.cfg" } if $osicon != "NONE" { case $::operatingsystem { "debian","ubuntu": { $iconpath = "base/" } default: { $iconpath = "" } } file { "${confdir}/hostextinfo_${name}.cfg": ensure => present, mode => "0640", owner => "root", group => "nagios", before => Nagios_Hostextinfo[$name], require => File["/etc/nagios/conf.d"], } nagios_hostextinfo { $name: ensure => present, icon_image_alt => $osname, icon_image => "${iconpath}${osicon}.png", statusmap_image => "${iconpath}${osicon}.gd2", target => "${confdir}/hostextinfo_${name}.cfg" } } } # Define nagios target service. # # === Parameters # # $host: # Target hostname. # $command: # Check command. # $description: # Service description. # define nagios::service($confdir, $host, $command, $description) { file { "${confdir}/service_${name}.cfg": ensure => present, mode => "0640", owner => "root", group => "nagios", before => Nagios_Service[$name], require => File["/etc/nagios/conf.d"], } nagios_service { $name: host_name => $host, check_command => $command, service_description => $description, use => "default", target => "${confdir}/service_${name}.cfg" } } # Configure nagios target. # class nagios::target { @@nagios::host { $fqdn: osname => $::operatingsystem, osicon => $::osfamily ? { "" => "NONE", default => inline_template("<%= osfamily.downcase %>") }, } } # Configure nagios nrpe target. # class nagios::target::nrpe { if !$nagios_allow { $nagios_allow = "127.0.0.1" } include nagios::target case $operatingsystem { "centos","redhat","fedora": { package { [ "nrpe", "nagios-plugins-disk", "nagios-plugins-load", "nagios-plugins-procs", "nagios-plugins-users", ]: ensure => installed, before => [ Augeas["nrpe-allow"], Service["nrpe"] ], } $service = "nrpe" } "ubuntu","debian": { package { [ "nagios-nrpe-server", "nagios-plugins-basic", ]: ensure => installed, before => [ Augeas["nrpe-allow"], Service["nrpe"] ], } $service = "nagios-nrpe-server" } } service { "nrpe": name => $service, ensure => running, enable => true, } augeas { "nrpe-allow": context => "/files/etc/nagios/nrpe.cfg", changes => "set allowed_hosts '${nagios_allow}'", notify => Service["nrpe"], } @@nagios::service { "${fqdn}_load": host => $fqdn, command => "check_nrpe!check_load", description => "Load", } } # Configure ssh service target. # class nagios::target::ssh { include nagios::target @@nagios::service { "${fqdn}_ssh": host => $fqdn, command => "check_ssh", description => "SSH", } } # Configure http service target. # class nagios::target::http { include nagios::target @@nagios::service { "${fqdn}_http": host => $fqdn, command => "check_http", description => "HTTP", } } # Configure https service target. # class nagios::target::https { include nagios::target @@nagios::service { "${fqdn}_https": host => $fqdn, command => "check_http!--ssl", description => "HTTPS", } } # Configure smtp service target. # class nagios::target::smtp { include nagios::target @@nagios::service { "${fqdn}_smtp": host => $fqdn, command => "check_smtp", description => "SMTP", } } # Install check_esxi_hardware.py plugin. # class nagios::plugin::esxi { package { "pywbem": ensure => installed, name => $::operatingsystem ? { "debian" => "python-pywbem", "ubuntu" => "python-pywbem", default => "pywbem", }, } file { "${nagios::server::libdir}/check_esxi_hardware.py": ensure => present, mode => "0755", owner => "root", group => "root", source => "puppet:///files/nagios/check_esxi_hardware.py", require => Package["nagios"], } } # Define ESXi target host. # # === Parameters # # $name: # Target hostname. # $user: # ESXi host username. # $pass: # ESXi host password. # $vendor: # ESXi host vendor. Defaults to "auto". # define nagios::host::esxi($user, $pass, $vendor="auto") { file { "${nagios::server::private}/esxi_${name}.cfg": ensure => present, mode => "0640", owner => "root", group => "nagios", content => "${user} ${pass}\n", require => File["/etc/nagios/private.d"], } nagios::host { $name: confdir => $nagios::server::confdir, notify => Service["nagios"], } nagios::service { "${name}_esxi": host => $name, command => "check_esxi_hardware!${nagios::server::private}/esxi_${name}.cfg!${vendor}", description => "ESXi", confdir => $nagios::server::confdir, notify => Service["nagios"], } }