summaryrefslogtreecommitdiff
path: root/manifests/irc_bot.pp
blob: 5d684f8e5a0b263765793bfc8cfb33df1fdbd3dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
class nagios::irc_bot(
  $nsa_socket = hiera('nagios_nsa_socket','absent'),
  $nsa_server = hiera('nagios_nsa_server'),
  $nsa_port = hiera('nagios_nsa_port',6667),
  $nsa_nickname = hiera('nagios_nsa_nickname'),
  $nsa_password = hiera('nagios_nsa_password',''),
  $nsa_channel = hiera('nagios_nsa_channel'),
  $nsa_pidfile = hiera('nagios_nsa_pidfile','absent'),
  $nsa_realname = hiera('nagios_nsa_realname','Nagios')
) {
    $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,
    }

    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'),
    }

    package { "libnet-irc-perl":
        ensure => present,
    }

    service { "nagios-nsa":
        ensure => "running",
        hasstatus => true,
        require => [File["/etc/nagios_nsa.cfg"],
                    Package["libnet-irc-perl"],
                    Service['nagios'] ],
    }

    case $::operatingsystem {
      centos: {
        Package['libnet-irc-perl']{
          name => 'perl-Net-IRC',
        }
        Service['nagios-nsa']{
          enable => true,
        }
      }
      debian,ubuntu: {
        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'],
        }
      }
    }

    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"';
    }

    if hiera('use_shorewall',false) {
      include shorewall::rules::out::irc
    }
}