Added automatic host and contact group generation for nagios

This commit is contained in:
Ossi Salmi 2012-11-22 02:37:17 +02:00
parent 2febffe8e8
commit cf1565f88a
2 changed files with 227 additions and 195 deletions

View file

@ -182,21 +182,6 @@ class nagios::server::manual inherits nagios::common {
} }
nagios_contactgroup { "all": nagios_contactgroup { "all":
target => "${confdir}/contactgroup_all.cfg", 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"], notify => Service["nagios"],
} }
@ -308,8 +293,13 @@ class nagios::server inherits nagios::server::manual {
# #
# $name: # $name:
# Email address. # Email address.
# $group:
# List of contact groups. Defaults to "all".
# #
define nagios::contact::email($confdir=$nagios::common::confdir) { define nagios::contact::email($group=["all"],
$confdir=$nagios::common::confdir) {
$contactgroups = inline_template('<%= group.join(",") -%>')
file { "${confdir}/contact_${name}.cfg": file { "${confdir}/contact_${name}.cfg":
ensure => present, ensure => present,
@ -321,6 +311,7 @@ define nagios::contact::email($confdir=$nagios::common::confdir) {
} }
nagios_contact { $name: nagios_contact { $name:
target => "${confdir}/contact_${name}.cfg", target => "${confdir}/contact_${name}.cfg",
contactgroups => $contactgroups,
host_notification_commands => "notify-host-by-email", host_notification_commands => "notify-host-by-email",
host_notification_options => "d,r", host_notification_options => "d,r",
host_notification_period => "24x7", host_notification_period => "24x7",
@ -340,8 +331,13 @@ define nagios::contact::email($confdir=$nagios::common::confdir) {
# #
# $name: # $name:
# Prowl API key. # Prowl API key.
# $group:
# List of contact groups. Defaults to "all".
# #
define nagios::contact::prowl($confdir=$nagios::common::confdir) { define nagios::contact::prowl($group=["all"],
$confdir=$nagios::common::confdir) {
$contactgroups = inline_template('<%= group.join(",") -%>')
file { "${confdir}/contact_${name}.cfg": file { "${confdir}/contact_${name}.cfg":
ensure => present, ensure => present,
@ -353,6 +349,7 @@ define nagios::contact::prowl($confdir=$nagios::common::confdir) {
} }
nagios_contact { $name: nagios_contact { $name:
target => "${confdir}/contact_${name}.cfg", target => "${confdir}/contact_${name}.cfg",
contactgroups => $contactgroups,
host_notification_commands => "notify-host-by-prowl", host_notification_commands => "notify-host-by-prowl",
host_notification_options => "d,r", host_notification_options => "d,r",
host_notification_period => "24x7", host_notification_period => "24x7",
@ -372,20 +369,23 @@ define nagios::contact::prowl($confdir=$nagios::common::confdir) {
# #
# $name: # $name:
# Hostname of target. # Hostname of target.
# $group:
# Hostgroup name.
# $osname: # $osname:
# Operating system name for hostextinfo. # Operating system name for hostextinfo.
# $osicon: # $osicon:
# Operating system icon name for hostextinfo. # Operating system icon name for hostextinfo.
# #
define nagios::host($confdir, $osname="NONE", $osicon="NONE") { define nagios::host($group="NONE", $osname="NONE", $osicon="NONE",
$confdir=$nagios::common::confdir) {
file { "${confdir}/host_${name}.cfg": file { "${confdir}/host_${name}.cfg":
ensure => present, ensure => present,
mode => "0640", mode => "0640",
owner => "root", owner => "root",
group => "nagios", group => "nagios",
before => Nagios_Host[$name], before => Nagios_Host[$name],
require => File["/etc/nagios/conf.d"], require => File["/etc/nagios/conf.d"],
} }
nagios_host { $name: nagios_host { $name:
ensure => present, ensure => present,
@ -419,6 +419,41 @@ define nagios::host($confdir, $osname="NONE", $osicon="NONE") {
} }
} }
if $group != "NONE" {
if !defined(Nagios_Contactgroup[$group]) {
file { "${confdir}/contactgroup_${group}.cfg":
ensure => present,
mode => "0640",
owner => "root",
group => "nagios",
before => Nagios_Contactgroup[$group],
require => File["/etc/nagios/conf.d"],
}
nagios_contactgroup { $group:
target => "${confdir}/contactgroup_${group}.cfg",
notify => Service["nagios"],
}
}
if !defined(Nagios_Hostgroup[$group]) {
file { "${confdir}/hostgroup_${group}.cfg":
ensure => present,
mode => "0640",
owner => "root",
group => "nagios",
before => Nagios_Hostgroup[$group],
require => File["/etc/nagios/conf.d"],
}
nagios_hostgroup { $group:
target => "${confdir}/hostgroup_${group}.cfg",
notify => Service["nagios"],
}
}
Nagios_Host[$name] {
contact_groups => "all,${group}",
hostgroups => $group,
}
}
} }
@ -432,8 +467,11 @@ define nagios::host($confdir, $osname="NONE", $osicon="NONE") {
# Check command. # Check command.
# $description: # $description:
# Service description. # Service description.
# $group:
# Hostgroup name.
# #
define nagios::service($confdir, $host, $command, $description) { define nagios::service($host, $command, $description, $group="NONE",
$confdir=$nagios::common::confdir) {
file { "${confdir}/service_${name}.cfg": file { "${confdir}/service_${name}.cfg":
ensure => present, ensure => present,
@ -448,180 +486,14 @@ define nagios::service($confdir, $host, $command, $description) {
check_command => $command, check_command => $command,
service_description => $description, service_description => $description,
use => "default", use => "default",
target => "${confdir}/service_${name}.cfg" target => "${confdir}/service_${name}.cfg",
require => Nagios_Host[$host],
} }
} if $group != "NONE" {
Nagios_Service[$name] {
contact_groups => "all,${group}",
# 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::common
include nagios::target
case $operatingsystem {
"centos","redhat","fedora": {
$service = "nrpe"
$nrpedir = "/etc/nrpe.d"
package { [ "nrpe",
"nagios-plugins-disk",
"nagios-plugins-load",
"nagios-plugins-procs",
"nagios-plugins-users", ]:
ensure => installed,
before => [ File["/etc/nrpe.d"],
Augeas["nrpe-allow"],
Service["nrpe"], ],
}
} }
"ubuntu","debian": {
$service = "nagios-nrpe-server"
$nrpedir = "/etc/nagios/nrpe.d"
package { [ "nagios-nrpe-server",
"nagios-plugins-basic", ]:
ensure => installed,
before => [ File["/etc/nrpe.d"],
Augeas["nrpe-allow"],
Service["nrpe"], ],
}
}
}
file { "/etc/nrpe.d":
ensure => directory,
mode => "0644",
owner => "root",
group => "root",
purge => true,
force => true,
recurse => true,
source => "puppet:///modules/custom/empty",
}
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"],
}
file { "${nrpedir}/check_disk.cfg":
ensure => present,
mode => "0644",
owner => "root",
group => "root",
content => "command[check_disk] = ${nagios::common::libdir}/check_disk -c 10% -w 20% -p /\n",
require => File["/etc/nrpe.d"],
notify => Service["nrpe"],
}
@@nagios::service { "${fqdn}_disk":
host => $fqdn,
command => "check_nrpe!check_disk",
description => "Disk",
}
@@nagios::service { "${fqdn}_load":
host => $fqdn,
command => "check_nrpe!check_load",
description => "Load",
}
@@nagios::service { "${fqdn}_users":
host => $fqdn,
command => "check_nrpe!check_users",
description => "Users",
}
@@nagios::service { "${fqdn}_procs":
host => $fqdn,
command => "check_nrpe!check_total_procs",
description => "Processes",
}
}
# 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",
} }
} }

160
nagios/manifests/target.pp Normal file
View file

@ -0,0 +1,160 @@
# Configure nagios target.
#
class nagios::target {
@@nagios::host { $fqdn:
group => $::domain,
osname => $::operatingsystem,
osicon => $::osfamily ? {
"" => "NONE",
default => inline_template("<%= osfamily.downcase %>")
},
}
Nagios::Service {
host => $::fqdn,
group => $::domain,
}
}
# Configure ssh service target.
#
class nagios::target::ssh inherits nagios::target {
@@nagios::service { "${fqdn}_ssh":
command => "check_ssh",
description => "SSH",
}
}
# Configure http service target.
#
class nagios::target::http inherits nagios::target {
@@nagios::service { "${fqdn}_http":
command => "check_http",
description => "HTTP",
}
}
# Configure https service target.
#
class nagios::target::https inherits nagios::target {
@@nagios::service { "${fqdn}_https":
command => "check_http!--ssl",
description => "HTTPS",
}
}
# Configure smtp service target.
#
class nagios::target::smtp inherits nagios::target {
@@nagios::service { "${fqdn}_smtp":
command => "check_smtp",
description => "SMTP",
}
}
# Configure nagios nrpe target.
#
class nagios::target::nrpe inherits nagios::target {
if !$nagios_allow {
$nagios_allow = "127.0.0.1"
}
include nagios::common
case $operatingsystem {
"centos","redhat","fedora": {
$service = "nrpe"
$nrpedir = "/etc/nrpe.d"
package { [ "nrpe",
"nagios-plugins-disk",
"nagios-plugins-load",
"nagios-plugins-procs",
"nagios-plugins-users", ]:
ensure => installed,
before => [ File["/etc/nrpe.d"],
Augeas["nrpe-allow"],
Service["nrpe"], ],
}
}
"ubuntu","debian": {
$service = "nagios-nrpe-server"
$nrpedir = "/etc/nagios/nrpe.d"
package { [ "nagios-nrpe-server",
"nagios-plugins-basic", ]:
ensure => installed,
before => [ File["/etc/nrpe.d"],
Augeas["nrpe-allow"],
Service["nrpe"], ],
}
}
}
file { "/etc/nrpe.d":
ensure => directory,
mode => "0644",
owner => "root",
group => "root",
purge => true,
force => true,
recurse => true,
source => "puppet:///modules/custom/empty",
}
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"],
}
file { "${nrpedir}/check_disk.cfg":
ensure => present,
mode => "0644",
owner => "root",
group => "root",
content => "command[check_disk] = ${nagios::common::libdir}/check_disk -c 10% -w 20% -p /\n",
require => File["/etc/nrpe.d"],
notify => Service["nrpe"],
}
@@nagios::service { "${fqdn}_disk":
command => "check_nrpe!check_disk",
description => "Disk",
}
@@nagios::service { "${fqdn}_load":
command => "check_nrpe!check_load",
description => "Load",
}
@@nagios::service { "${fqdn}_users":
command => "check_nrpe!check_users",
description => "Users",
}
@@nagios::service { "${fqdn}_procs":
command => "check_nrpe!check_total_procs",
description => "Processes",
}
}