summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README1
-rw-r--r--manifests/base.pp7
-rw-r--r--manifests/debian.pp7
-rw-r--r--manifests/defaults/templates.pp1
-rw-r--r--manifests/init.pp1
-rw-r--r--manifests/irc_bot.pp44
-rw-r--r--manifests/irc_bot/base.pp94
-rw-r--r--manifests/irc_bot/centos.pp10
-rw-r--r--manifests/irc_bot/debian.pp8
-rw-r--r--manifests/service.pp114
-rw-r--r--manifests/service/dns.pp19
-rw-r--r--manifests/service/dns_host.pp22
-rw-r--r--manifests/service/mysql.pp5
-rw-r--r--templates/irc_bot/nsa.cfg.erb23
14 files changed, 207 insertions, 149 deletions
diff --git a/README b/README
index 551738f..7fd1f02 100644
--- a/README
+++ b/README
@@ -185,6 +185,7 @@ For the irc_bot class:
'notice' if you would prefer them to be sent as IRC
NOTICE messages.
+
PNP4Nagios Nagios Grapher integration
=====================================
diff --git a/manifests/base.pp b/manifests/base.pp
index d4d6590..0f8b777 100644
--- a/manifests/base.pp
+++ b/manifests/base.pp
@@ -26,13 +26,6 @@ class nagios::base {
mode => 0644, owner => root, group => root;
}
- file { 'nagios_commands_cfg':
- path => "${nagios::defaults::vars::int_nagios_cfgdir}/commands.cfg",
- ensure => present,
- notify => Service['nagios'],
- mode => 0644, owner => root, group => root;
- }
-
file { 'nagios_cgi_cfg':
path => "${nagios::defaults::vars::int_cfgdir}/cgi.cfg",
source => [ "puppet:///modules/site_nagios/configs/${::fqdn}/cgi.cfg",
diff --git a/manifests/debian.pp b/manifests/debian.pp
index bb9bb38..0f451e3 100644
--- a/manifests/debian.pp
+++ b/manifests/debian.pp
@@ -14,6 +14,13 @@ class nagios::debian inherits nagios::base {
File['nagios_htpasswd', 'nagios_cgi_cfg'] { group => 'www-data' }
+ file { 'nagios_commands_cfg':
+ path => "${nagios::defaults::vars::int_cfgdir}/commands.cfg",
+ ensure => present,
+ notify => Service['nagios'],
+ mode => 0644, owner => root, group => root;
+ }
+
file { "${nagios::defaults::vars::int_cfgdir}/stylesheets":
ensure => directory,
purge => false,
diff --git a/manifests/defaults/templates.pp b/manifests/defaults/templates.pp
index 0e73c97..9711dd4 100644
--- a/manifests/defaults/templates.pp
+++ b/manifests/defaults/templates.pp
@@ -11,5 +11,4 @@ class nagios::defaults::templates {
notify => Service['nagios'],
mode => 0644, owner => root, group => root;
}
-
}
diff --git a/manifests/init.pp b/manifests/init.pp
index 12d3db2..5cbd3f3 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -14,6 +14,7 @@
# the Free Software Foundation.
#
+# manage nagios
class nagios(
$httpd = 'apache',
$allow_external_cmd = false,
diff --git a/manifests/irc_bot.pp b/manifests/irc_bot.pp
index a034fe0..7e934ef 100644
--- a/manifests/irc_bot.pp
+++ b/manifests/irc_bot.pp
@@ -1,17 +1,45 @@
-class nagios::irc_bot {
- if ( ! ($nsa_server and $nsa_nickname and $nsa_channel) ) {
- fail("Please provide values at least for \$nsa_server, \$nsa_nickname and \$nsa_channel")
+class nagios::irc_bot(
+ $nsa_socket = 'absent',
+ $nsa_server,
+ $nsa_port = 6667,
+ $nsa_nickname,
+ $nsa_password = '',
+ $nsa_channel,
+ $nsa_pidfile = 'absent',
+ $nsa_realname = 'Nagios',
+ $nsa_usenotices = false,
+ $nsa_commandfile = 'absent'
+) {
+ $real_nsa_socket = $nsa_socket ? {
+ 'absent' => $::operatingsystem ? {
+ centos => '/var/run/nagios-nsa/nsa.socket',
+ default => '/var/run/nagios3/nsa.socket'
+ },
+ default => $nsa_socket,
+ }
+ $real_nsa_pidfile = $nsa_pidfile ? {
+ 'absent' => $::operatingsystem ? {
+ centos => '/var/run/nagios-nsa/nsa.pid',
+ default => '/var/run/nagios3/nsa.pid'
+ },
+ default => $nsa_pidfile,
+ }
+ $real_nsa_commandfile = $nsa_commandfile ? {
+ 'absent' => $::operatingsystem ? {
+ centos => '/var/spool/nagios/cmd/nagios.cmd',
+ default => '/var/lib/nagios3/rw/nagios.cmd'
+ },
+ default => $nsa_commandfile,
}
- case $operatingsystem {
+ case $::operatingsystem {
centos: {
- $nsa_default_socket = '/var/run/nagios-nsa/nsa.socket'
- $nsa_default_pidfile = '/var/run/nagios-nsa/nsa.pid'
include nagios::irc_bot::centos
}
+ debian,ubuntu: {
+ include nagios::irc_bot::debian
+ }
default: {
- $nsa_default_socket = '/var/run/nagios3/nsa.socket'
- $nsa_default_pidfile = '/var/run/nagios3/nsa.pid'
include nagios::irc_bot::base
}
}
diff --git a/manifests/irc_bot/base.pp b/manifests/irc_bot/base.pp
index 6fab2ac..fff9da4 100644
--- a/manifests/irc_bot/base.pp
+++ b/manifests/irc_bot/base.pp
@@ -1,69 +1,41 @@
class nagios::irc_bot::base {
+ file {
+ '/usr/local/bin/riseup-nagios-client.pl':
+ source => 'puppet:///modules/nagios/irc_bot/riseup-nagios-client.pl',
+ owner => root, group => 0, mode => '0755';
- # Default values for the two first variables are defined in nagios::irc_bot
- $nsa_socket = $nsa_socket ? {
- '' => $nsa_default_socket,
- default => $nsa_socket,
- }
- $nsa_pidfile = $nsa_pidfile ? {
- '' => $nsa_default_pidfile,
- default => $nsa_pidfile,
- }
- $nsa_port = $nsa_port ? {
- '' => '6667',
- default => $nsa_port,
- }
- $nsa_realname = $nsa_realname ? {
- '' => 'Nagios',
- default => $nsa_realname,
- }
+ '/usr/local/bin/riseup-nagios-server.pl':
+ source => 'puppet:///modules/nagios/irc_bot/riseup-nagios-server.pl',
+ owner => root, group => 0, mode => '0755';
- if (! $nsa_password) {
- $nsa_password = ''
- }
+ '/etc/init.d/nagios-nsa':
+ content => template("nagios/irc_bot/${::operatingsystem}/nagios-nsa.sh.erb"),
+ require => File['/usr/local/bin/riseup-nagios-server.pl'],
+ owner => root, group => 0, mode => '0755';
- if (! $nsa_usenotices) {
- $nsa_usenotices = ''
- }
-
- file { "/usr/local/bin/riseup-nagios-client.pl":
- owner => root, group => 0, mode => 0755,
- source => "puppet:///modules/nagios/irc_bot/riseup-nagios-client.pl",
- }
- file { "/usr/local/bin/riseup-nagios-server.pl":
- owner => root, group => 0, mode => 0755,
- source => "puppet:///modules/nagios/irc_bot/riseup-nagios-server.pl",
- }
- file { "/etc/init.d/nagios-nsa":
- owner => root, group => 0, mode => 0755,
- content => template("nagios/irc_bot/${operatingsystem}/nagios-nsa.sh.erb"),
- require => File["/usr/local/bin/riseup-nagios-server.pl"],
- }
- file { "/etc/nagios_nsa.cfg":
- ensure => present,
- owner => nagios, group => 0, mode => 0400,
- content => template('nagios/irc_bot/nsa.cfg.erb'),
- notify => Service["nagios-nsa"],
- }
+ '/etc/nagios_nsa.cfg':
+ ensure => present,
+ content => template('nagios/irc_bot/nsa.cfg.erb'),
+ owner => nagios, group => 0, mode => '0400',
+ notify => Service['nagios-nsa'];
+ }
- package { "libnet-irc-perl":
- ensure => present,
- }
+ package { 'libnet-irc-perl':
+ ensure => present,
+ }
- service { "nagios-nsa":
- ensure => "running",
- hasstatus => true,
- enable => true,
- require => [File["/etc/nagios_nsa.cfg"],
- File["/etc/init.d/nagios-nsa"],
- Package["libnet-irc-perl"],
- Service['nagios'] ],
- }
+ service { 'nagios-nsa':
+ ensure => 'running',
+ hasstatus => true,
+ require => [ File['/etc/nagios_nsa.cfg'],
+ Package['libnet-irc-perl'],
+ Service['nagios'] ],
+ }
- nagios_command {
- "notify-by-irc":
- command_line => '/usr/local/bin/riseup-nagios-client.pl "$HOSTNAME$ ($SERVICEDESC$) $NOTIFICATIONTYPE$ $SERVICEATTEMPT$/$MAXSERVICEATTEMPTS$ $SERVICESTATETYPE$ $SERVICEEXECUTIONTIME$s $SERVICELATENCY$s $SERVICEOUTPUT$ $SERVICEPERFDATA$"';
- "host-notify-by-irc":
- command_line => '/usr/local/bin/riseup-nagios-client.pl "$HOSTNAME$ ($HOSTALIAS$) $NOTIFICATIONTYPE$ $HOSTATTEMPT$/$MAXHOSTATTEMPTS$ $HOSTSTATETYPE$ took $HOSTEXECUTIONTIME$s $HOSTOUTPUT$ $HOSTPERFDATA$ $HOSTLATENCY$s"';
- }
+ nagios_command {
+ 'notify-by-irc':
+ command_line => '/usr/local/bin/riseup-nagios-client.pl "$HOSTNAME$ ($SERVICEDESC$) $NOTIFICATIONTYPE$ n.$SERVICEATTEMPT$ $SERVICESTATETYPE$ $SERVICEEXECUTIONTIME$s $SERVICELATENCY$s $SERVICEOUTPUT$ $SERVICEPERFDATA$"';
+ 'host-notify-by-irc':
+ command_line => '/usr/local/bin/riseup-nagios-client.pl "$HOSTNAME$ ($HOSTALIAS$) $NOTIFICATIONTYPE$ n.$HOSTATTEMPT$ $HOSTSTATETYPE$ took $HOSTEXECUTIONTIME$s $HOSTOUTPUT$ $HOSTPERFDATA$ $HOSTLATENCY$s"';
+ }
}
diff --git a/manifests/irc_bot/centos.pp b/manifests/irc_bot/centos.pp
index e77e93a..d7b1906 100644
--- a/manifests/irc_bot/centos.pp
+++ b/manifests/irc_bot/centos.pp
@@ -1,7 +1,9 @@
class nagios::irc_bot::centos inherits nagios::irc_bot::base {
+ Package['libnet-irc-perl']{
+ name => 'perl-Net-IRC',
+ }
- Package['libnet-irc-perl']{
- name => 'perl-Net-IRC',
- }
-
+ Service['nagios-nsa']{
+ enable => true,
+ }
}
diff --git a/manifests/irc_bot/debian.pp b/manifests/irc_bot/debian.pp
new file mode 100644
index 0000000..93ea64b
--- /dev/null
+++ b/manifests/irc_bot/debian.pp
@@ -0,0 +1,8 @@
+class nagios::irc_bot::debian inherits nagios::irc_bot::base {
+ exec { "nagios_nsa_init_script":
+ command => "/usr/sbin/update-rc.d nagios-nsa defaults",
+ unless => "/bin/ls /etc/rc3.d/ | /bin/grep nagios-nsa",
+ require => File["/etc/init.d/nagios-nsa"],
+ before => Service['nagios-nsa'],
+ }
+}
diff --git a/manifests/service.pp b/manifests/service.pp
index 71f78b0..134d1f7 100644
--- a/manifests/service.pp
+++ b/manifests/service.pp
@@ -1,82 +1,88 @@
define nagios::service (
- $ensure = present,
- $host_name = $::fqdn,
- $check_command,
- $check_period = '',
- $normal_check_interval = '',
- $retry_check_interval = '',
- $max_check_attempts = '',
- $notification_interval = '',
- $notification_period = '',
- $notification_options = '',
- $contact_groups = '',
- $use = 'generic-service',
- $service_description = 'absent',
- $use_nrpe = '',
- $nrpe_args = '',
- $nrpe_timeout = 10 )
-{
+ $ensure = present,
+ $host_name = $::fqdn,
+ $check_command = 'absent',
+ $check_period = '',
+ $normal_check_interval = '',
+ $retry_check_interval = '',
+ $max_check_attempts = '',
+ $notification_interval = '',
+ $notification_period = '',
+ $notification_options = '',
+ $contact_groups = '',
+ $use = 'generic-service',
+ $service_description = 'absent',
+ $use_nrpe = '',
+ $nrpe_args = '',
+ $nrpe_timeout = 10
+) {
- # TODO: this resource should normally accept all nagios_host parameters
+ # TODO: this resource should normally accept all nagios_host parameters
- $real_name = "${::hostname}_${name}"
+ $real_name = "${::hostname}_${name}"
- if ($use_nrpe == 'true') {
- include nagios::command::nrpe_timeout
+ @@nagios_service { "${real_name}":
+ ensure => $ensure,
+ notify => Service[nagios];
+ }
- if ($nrpe_args != '') {
- $real_check_command = "check_nrpe_timeout!$nrpe_timeout!$check_command!\"$nrpe_args\""
- }
- else {
- $real_check_command = "check_nrpe_1arg_timeout!$nrpe_timeout!$check_command"
- }
+ if $ensure != 'absent' {
+ if $check_comand == 'absent' {
+ fail("Must pass a check_command to ${name} if it should be present")
}
- else {
- $real_check_command = "$check_command"
+ if ($use_nrpe == 'true') {
+ include nagios::command::nrpe_timeout
+
+ if ($nrpe_args != '') {
+ $real_check_command = "check_nrpe_timeout!$nrpe_timeout!$check_command!\"$nrpe_args\""
+ } else {
+ $real_check_command = "check_nrpe_1arg_timeout!$nrpe_timeout!$check_command"
+ }
+ } else {
+ $real_check_command = "$check_command"
}
- @@nagios_service { "${real_name}":
- ensure => $ensure,
- check_command => $real_check_command,
- host_name => $host_name,
- use => $use,
- notify => Service[nagios],
- service_description => $service_description ?{
- 'absent' => $name,
- default => $service_description
- }
+ Nagios_service["${real_name}"] {
+ check_command => $check_command,
+ host_name => $host_name,
+ use => $use,
+ service_description => $service_description ?{
+ 'absent' => $name,
+ default => $service_description
+ }
}
if ($check_period != '') {
- Nagios_service["${real_name}"] { check_period => $check_period }
+ Nagios_service["${real_name}"] { check_period => $check_period }
}
-
+
if ($normal_check_interval != '') {
- Nagios_service["${real_name}"] { normal_check_interval => $normal_check_interval }
+ Nagios_service["${real_name}"] { normal_check_interval => $normal_check_interval }
}
-
+
if ($retry_check_interval != '') {
- Nagios_service["${real_name}"] { retry_check_interval => $retry_check_interval }
+ Nagios_service["${real_name}"] { retry_check_interval => $retry_check_interval }
}
-
+
if ($max_check_attempts != '') {
- Nagios_service["${real_name}"] { max_check_attempts => $max_check_attempts }
+ Nagios_service["${real_name}"] { max_check_attempts => $max_check_attempts }
}
-
+
if ($notification_interval != '') {
- Nagios_service["${real_name}"] { notification_interval => $notification_interval }
+ Nagios_service["${real_name}"] { notification_interval => $notification_interval }
}
-
+
if ($notification_period != '') {
- Nagios_service["${real_name}"] { notification_period => $notification_period }
+ Nagios_service["${real_name}"] { notification_period => $notification_period }
}
-
+
if ($notification_options != '') {
- Nagios_service["${real_name}"] { notification_options => $notification_options }
+ Nagios_service["${real_name}"] { notification_options => $notification_options }
}
-
+
if ($contact_groups != '') {
- Nagios_service["${real_name}"] { contact_groups => $contact_groups }
+ Nagios_service["${real_name}"] { contact_groups => $contact_groups }
}
+ }
}
diff --git a/manifests/service/dns.pp b/manifests/service/dns.pp
new file mode 100644
index 0000000..5ef6e3e
--- /dev/null
+++ b/manifests/service/dns.pp
@@ -0,0 +1,19 @@
+define nagios::service::dns(
+ $host_name = $::fqdn,
+ $comment = $name,
+ $check_domain = $name,
+ $ip
+){
+ if $name != $comment {
+ $check_name = "${comment}_${name}_${::hostname}"
+ } else {
+ $check_name = "${name}_${::hostname}"
+ }
+
+ nagios::service{
+ $check_name:
+ check_command => "check_dns2!${check_domain}!${ip}",
+ host_name => $host_name,
+ service_description => "check if ${::host_name} is resolving ${check_domain}";
+ }
+}
diff --git a/manifests/service/dns_host.pp b/manifests/service/dns_host.pp
new file mode 100644
index 0000000..d88f373
--- /dev/null
+++ b/manifests/service/dns_host.pp
@@ -0,0 +1,22 @@
+# add a special host and monitor
+# it's dns service
+define nagios::service::dns_host(
+ $check_domain,
+ $host_alias,
+ $parent,
+ $ip
+){
+ @@nagios_host{$name:
+ address => $ip,
+ alias => $host_alias,
+ use => 'generic-host',
+ parents => $parent,
+ }
+
+ nagios::service::dns{$name:
+ host_name => $name,
+ comment => 'public_ns',
+ check_domain => $check_domain,
+ ip => $ip,
+ }
+}
diff --git a/manifests/service/mysql.pp b/manifests/service/mysql.pp
index 94881d8..9559b17 100644
--- a/manifests/service/mysql.pp
+++ b/manifests/service/mysql.pp
@@ -1,11 +1,10 @@
# Checks a mysql instance via tcp or socket
-
define nagios::service::mysql(
$ensure = present,
$check_host = 'absent',
$check_port = '3306',
$check_username = 'nagios',
- $check_password = trocla("mysql_nagios_${::fqdn}",'plain','length: 32'),
+ $check_password,
$check_database = 'information_schema',
$check_warning = undef,
$check_critical = undef,
@@ -54,6 +53,6 @@ define nagios::service::mysql(
nagios::service { "mysql_health_${name}":
ensure => $ensure,
- check_command => "check_mysql_health!${real_check_host}!${check_port}!${check_username}!${check_password}!${check_health_mode}!${check_database}${real_check_name}${real_check_warning}${real_check_critical}",
+ check_command => "check_mysql_health!${real_check_host}!${check_port}!${check_username}!'${check_password}'!${check_health_mode}!${check_database}${real_check_name}${real_check_warning}${real_check_critical}",
}
}
diff --git a/templates/irc_bot/nsa.cfg.erb b/templates/irc_bot/nsa.cfg.erb
index a3bb2b1..c999c2b 100644
--- a/templates/irc_bot/nsa.cfg.erb
+++ b/templates/irc_bot/nsa.cfg.erb
@@ -1,14 +1,15 @@
-%Nsa = (
- 'socket' => '<%= scope.lookupvar('nagios::irc_bot::base::nsa_socket') %>',
- 'server' => '<%= scope.lookupvar('nagios::irc_bot::base::nsa_server') %>',
- 'port' => '<%= scope.lookupvar('nagios::irc_bot::base::nsa_port') %>',
- 'nickname' => '<%= scope.lookupvar('nagios::irc_bot::base::nsa_nickname') %>',
- 'password' => '<%= scope.lookupvar('nagios::irc_bot::base::nsa_password') %>',
+%%Nsa = (
+ 'socket' => '<%= scope.lookupvar('nagios::irc_bot::real_nsa_socket') %>',
+ 'server' => '<%= scope.lookupvar('nagios::irc_bot::nsa_server') %>',
+ 'port' => '<%= scope.lookupvar('nagios::irc_bot::nsa_port') %>',
+ 'nickname' => '<%= scope.lookupvar('nagios::irc_bot::nsa_nickname') %>',
+ 'password' => '<%= scope.lookupvar('nagios::irc_bot::nsa_password') %>',
# this needs libio-socket-ssl-perl
# doesn't actually works because Net::IRC is braindead and tries to use IO::Socket::SSL->read/write instead of the builtin print, see http://search.cpan.org/dist/IO-Socket-SSL/SSL.pm
- #'SSL' => 0,
- 'channel' => '<%= scope.lookupvar('nagios::irc_bot::base::nsa_channel') %>',
- 'pidfile' => '<%= scope.lookupvar('nagios::irc_bot::base::nsa_pidfile') %>', # set to undef to disable
- 'realname' => '<%= scope.lookupvar('nagios::irc_bot::base::nsa_realname') %>',
- 'usenotices' => '<%= scope.lookupvar('nagios::irc_bot::base::nsa_usenotices') %>',
+ #'SSL' => 0,
+ 'channel' => '<%= scope.lookupvar('nagios::irc_bot::nsa_channel') %>',
+ 'pidfile' => '<%= scope.lookupvar('nagios::irc_bot::real_nsa_pidfile') %>', # set to undef to disable
+ 'realname' => '<%= scope.lookupvar('nagios::irc_bot::nsa_realname') %>',
+ 'usenotices' => '<%= scope.lookupvar('nagios::irc_bot::nsa_usenotices') %>',
+ 'commandfile' => '<%= scope.lookupvar('nagios::irc_bot::real_nsa_commandfile') %>',
);