From db9b47560068218125cfb82b0a19a491cffba002 Mon Sep 17 00:00:00 2001 From: Gabriel Filion Date: Thu, 14 Jul 2011 07:03:12 -0400 Subject: IRC-bot: split up manifests by OS This gives us the possibility of using the nagios::irc_bot::disable class without having any config variable set. When using nagios::irc_bot, we still get yelled at when we didn't define the appropriate variables. While we're moving the code around, change the group applied on the different files from 'root' to '0' for better portability. --- manifests/irc_bot.pp | 81 +++++---------------------------------------- manifests/irc_bot/base.pp | 65 ++++++++++++++++++++++++++++++++++++ manifests/irc_bot/centos.pp | 7 ++++ 3 files changed, 81 insertions(+), 72 deletions(-) create mode 100644 manifests/irc_bot/base.pp create mode 100644 manifests/irc_bot/centos.pp (limited to 'manifests') diff --git a/manifests/irc_bot.pp b/manifests/irc_bot.pp index 494f0c3..59f7ed4 100644 --- a/manifests/irc_bot.pp +++ b/manifests/irc_bot.pp @@ -3,80 +3,17 @@ class nagios::irc_bot { fail("Please provide values at least for \$nagios_nsa_server, \$nagios_nsa_nickname and \$nagios_nsa_channel") } - $nagios_nsa_socket = $nagios_nsa_socket ? { - '' => $operatingsystem ? { - centos => '/var/run/nagios-nsa/nsa.socket', - default => '/var/run/nagios3/nsa.socket' - }, - default => $nagios_nsa_socket, - } - $nagios_nsa_pidfile = $nagios_nsa_pidfile ? { - '' => $operatingsystem ? { - centos => '/var/run/nagios-nsa/nsa.pid', - default => '/var/run/nagios3/nsa.pid' - }, - default => $nagios_nsa_pidfile, - } - $nagios_nsa_port = $nagios_nsa_port ? { - '' => '6667', - default => $nagios_nsa_port, - } - $nagios_nsa_realname = $nagios_nsa_realname ? { - '' => 'Nagios', - default => $nagios_nsa_realname, - } - - if (! $nagios_nsa_password) { - $nagios_nsa_password = '' - } - - file { "/usr/local/bin/riseup-nagios-client.pl": - owner => root, group => root, mode => 0755, - source => "puppet:///modules/nagios/irc_bot/riseup-nagios-client.pl", - } - file { "/usr/local/bin/riseup-nagios-server.pl": - owner => root, group => root, mode => 0755, - source => "puppet:///modules/nagios/irc_bot/riseup-nagios-server.pl", - } - file { "/etc/init.d/nagios-nsa": - owner => root, group => root, 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 => root, mode => 0400, - content => template('nagios/irc_bot/nsa.cfg.erb'), - notify => Service["nagios-nsa"], - } - - 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'] ], - } - case $operatingsystem { - centos: { - Package['libnet-irc-perl']{ - name => 'perl-Net-IRC', + centos: { + $nagios_nsa_default_socket = '/var/run/nagios-nsa/nsa.socket' + $nagios_nsa_default_pidfile = '/var/run/nagios-nsa/nsa.pid' + include nagios::irc_bot::centos + } + default: { + $nagios_nsa_default_socket = '/var/run/nagios3/nsa.socket' + $nagios_nsa_default_pidfile = '/var/run/nagios3/nsa.pid' + include nagios::irc_bot::base } - } - } - - 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"'; } if $use_shorewall { diff --git a/manifests/irc_bot/base.pp b/manifests/irc_bot/base.pp new file mode 100644 index 0000000..2c9b27b --- /dev/null +++ b/manifests/irc_bot/base.pp @@ -0,0 +1,65 @@ +class nagios::irc_bot::base { + + # Default values for the two first variables are defined in nagios::irc_bot + $nagios_nsa_socket = $nagios_nsa_socket ? { + '' => $nagios_nsa_default_socket, + default => $nagios_nsa_socket, + } + $nagios_nsa_pidfile = $nagios_nsa_pidfile ? { + '' => $nagios_nsa_default_pidfile, + default => $nagios_nsa_pidfile, + } + $nagios_nsa_port = $nagios_nsa_port ? { + '' => '6667', + default => $nagios_nsa_port, + } + $nagios_nsa_realname = $nagios_nsa_realname ? { + '' => 'Nagios', + default => $nagios_nsa_realname, + } + + if (! $nagios_nsa_password) { + $nagios_nsa_password = '' + } + + 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"], + } + + 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'] ], + } + + 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"'; + } +} diff --git a/manifests/irc_bot/centos.pp b/manifests/irc_bot/centos.pp new file mode 100644 index 0000000..e77e93a --- /dev/null +++ b/manifests/irc_bot/centos.pp @@ -0,0 +1,7 @@ +class nagios::irc_bot::centos inherits nagios::irc_bot::base { + + Package['libnet-irc-perl']{ + name => 'perl-Net-IRC', + } + +} -- cgit v1.2.3