Puppet Class: nagios::server::notification::email

Defined in:
manifests/server/notification/email.pp

Overview

Class: nagios::server::notification::email

This is ensure that mailutils is installed and set up commands for emailing alerts to contacts. It will also build contacts with some simple defaults suitable for emails.

Parameters

contacts

A hash of contacts to build, that will build with some suitable defaults for emails - these can be overriden. Not required.

Authors

Ben Field <ben.field@concreteplatform.com>

Parameters:

  • contacts (Any) (defaults to: undef)


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
# File 'manifests/server/notification/email.pp', line 17

class nagios::server::notification::email ($contacts = undef) {
  include nagios::server::service

  ensure_packages('heirloom-mailx', {
    'ensure' => 'installed'
  }
  )

  nagios_command { 'notify_host_by_email':
    command_line => '/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mailx -r $ADMINEMAIL$ -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$',
    target       => '/etc/nagios3/conf.d/puppet/command_email.cfg',
    notify       => Exec['rechmod'],
  }

  nagios_command { 'notify_service_by_email':
    command_line => '/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mailx -r $ADMINEMAIL$ -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$',
    target       => '/etc/nagios3/conf.d/puppet/command_email.cfg',
    notify       => Exec['rechmod'],
  }

  $defaults = {
    ensure => present,
    service_notification_commands => 'notify_service_by_email',
    service_notification_period   => '24x7',
    service_notification_options  => 'u,c,r,f',
    host_notification_commands    => 'notify_host_by_email',
    host_notification_period      => '24x7',
    host_notification_options     => 'd,r,f',
    target => '/etc/nagios3/conf.d/puppet/contact_email.cfg',
    notify => Exec['rechmod'],
  }

  if $contacts != undef {
    create_resources('nagios_contact', $contacts, $defaults)
  }
}