Added nagios module
This commit is contained in:
parent
eaa42c7398
commit
0f4bbae2e9
8 changed files with 3694 additions and 0 deletions
395
nagios/manifests/init.pp
Normal file
395
nagios/manifests/init.pp
Normal file
|
@ -0,0 +1,395 @@
|
|||
class nagios::server {
|
||||
|
||||
case $operatingsystem {
|
||||
"centos","redhat","fedora": {
|
||||
$etcdir = "/etc/nagios"
|
||||
$confdir = "${etcdir}/conf.d"
|
||||
$package = "nagios"
|
||||
$service = "nagios"
|
||||
$scriptalias = "/nagios/cgi-bin/"
|
||||
$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"
|
||||
$package = "nagios3"
|
||||
$service = "nagios3"
|
||||
$scriptalias = "/cgi-bin/nagios3/"
|
||||
$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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
purge => true,
|
||||
force => true,
|
||||
recurse => true,
|
||||
owner => "root",
|
||||
group => "root",
|
||||
mode => "0644",
|
||||
source => "puppet:///modules/custom/empty",
|
||||
require => Package["nagios"],
|
||||
notify => Service["nagios"],
|
||||
}
|
||||
|
||||
file { "${confdir}/contactgroup_all.cfg":
|
||||
ensure => present,
|
||||
mode => "0644",
|
||||
owner => "root",
|
||||
group => "root",
|
||||
before => Nagios_Contactgroup["all"],
|
||||
}
|
||||
nagios_contactgroup { "all":
|
||||
target => "${confdir}/contactgroup_all.cfg",
|
||||
members => "*",
|
||||
notify => Service["nagios"],
|
||||
}
|
||||
|
||||
file { "${confdir}/host_default.cfg":
|
||||
ensure => present,
|
||||
mode => "0644",
|
||||
owner => "root",
|
||||
group => "root",
|
||||
before => Nagios_Host["default"],
|
||||
}
|
||||
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 => "0644",
|
||||
owner => "root",
|
||||
group => "root",
|
||||
before => Nagios_Service["default"],
|
||||
}
|
||||
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 => "0644",
|
||||
owner => "root",
|
||||
group => "root",
|
||||
before => Nagios_Timeperiod["24x7"],
|
||||
}
|
||||
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::contact::email($confdir=$nagios::server::confdir) {
|
||||
|
||||
file { "${confdir}/contact_${name}.cfg":
|
||||
ensure => present,
|
||||
mode => "0644",
|
||||
owner => "root",
|
||||
group => "root",
|
||||
before => Nagios_Contact[$name],
|
||||
}
|
||||
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::host($confdir, $operatingsystem) {
|
||||
|
||||
file { "${confdir}/host_${name}.cfg":
|
||||
ensure => present,
|
||||
mode => "0644",
|
||||
owner => "root",
|
||||
group => "root",
|
||||
before => Nagios_Host[$name],
|
||||
}
|
||||
nagios_host { $name:
|
||||
ensure => present,
|
||||
use => "default",
|
||||
target => "${confdir}/host_${name}.cfg"
|
||||
}
|
||||
|
||||
# file { "${confdir}/hostextinfo_${name}.cfg":
|
||||
# ensure => present,
|
||||
# mode => "0644",
|
||||
# owner => "root",
|
||||
# group => "root",
|
||||
# before => Nagios_Hostextinfo[$name],
|
||||
# }
|
||||
# nagios_hostextinfo { $name:
|
||||
# ensure => present,
|
||||
# icon_image_alt => $operatingsystem,
|
||||
# icon_image => "base/${operatingsystem}.png",
|
||||
# statusmap_image => "base/${operatingsystem}.gd2",
|
||||
# target => "${confdir}/hostextinfo_${name}.cfg"
|
||||
# }
|
||||
|
||||
}
|
||||
|
||||
|
||||
define nagios::service($confdir, $host, $command, $description) {
|
||||
|
||||
file { "${confdir}/service_${name}.cfg":
|
||||
ensure => present,
|
||||
mode => "0644",
|
||||
owner => "root",
|
||||
group => "root",
|
||||
before => Nagios_Service[$name],
|
||||
}
|
||||
nagios_service { $name:
|
||||
host_name => $host,
|
||||
check_command => $command,
|
||||
service_description => $description,
|
||||
use => "default",
|
||||
target => "${confdir}/service_${name}.cfg"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class nagios::target {
|
||||
|
||||
@@nagios::host { $fqdn:
|
||||
operatingsystem => inline_template("<%= operatingsystem.downcase %>")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
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",
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class nagios::target::ssh {
|
||||
|
||||
include nagios::target
|
||||
|
||||
@@nagios::service { "${fqdn}_ssh":
|
||||
host => $fqdn,
|
||||
command => "check_ssh",
|
||||
description => "SSH",
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class nagios::target::http {
|
||||
|
||||
include nagios::target
|
||||
|
||||
@@nagios::service { "${fqdn}_http":
|
||||
host => $fqdn,
|
||||
command => "check_http",
|
||||
description => "HTTP",
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class nagios::target::https {
|
||||
|
||||
include nagios::target
|
||||
|
||||
@@nagios::service { "${fqdn}_https":
|
||||
host => $fqdn,
|
||||
command => "check_http!--ssl",
|
||||
description => "HTTPS",
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue