diff --git a/nagios/files/commands.cfg b/nagios/files/commands.cfg index b6cdcc6..b08ad52 100644 --- a/nagios/files/commands.cfg +++ b/nagios/files/commands.cfg @@ -287,6 +287,18 @@ define command{ } +# 'notify-host-by-sms' command definition +define command{ + command_name notify-host-by-sms + command_line /bin/echo "Nagios: $HOSTNAME$ is $HOSTSTATE$ '$HOSTOUTPUT$'" > "/var/spool/smsd/OUT$CONTACTPAGER$.txt" +} +# 'notify-service-by-sms' command definition +define command{ + command_name notify-service-by-sms + command_line /bin/echo "Nagios: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ '$SERVICEOUTPUT$'" > "/var/spool/smsd/OUT$CONTACTPAGER$.txt" +} + + # 'check_esxi_hardware' command definition define command{ command_name check_esxi_hardware diff --git a/nagios/manifests/init.pp b/nagios/manifests/init.pp index 50ec061..b0c0dcc 100644 --- a/nagios/manifests/init.pp +++ b/nagios/manifests/init.pp @@ -411,6 +411,48 @@ define nagios::contact::pushover($token, $group=["all"], } +# Define nagios sms contact. +# +# This requires gammu::smsd running on same host. +# +# === Parameters +# +# $name: +# Descriptive name for contact. +# $number: +# Phone number where to send messages. +# $group: +# List of contact groups. Defaults to "all". +# +define nagios::contact::sms($number, $group=["all"], + $confdir=$nagios::common::confdir) { + + $contactgroups = inline_template('<%= @group.join(",") -%>') + + file { "${confdir}/contact_sms_${name}.cfg": + ensure => present, + mode => "0640", + owner => "root", + group => "nagios", + before => Nagios_Contact["sms-${name}"], + require => File["/etc/nagios/conf.d"], + } + nagios_contact { "sms-${name}": + target => "${confdir}/contact_sms_${name}.cfg", + contactgroups => $contactgroups, + host_notification_commands => "notify-host-by-sms", + host_notification_options => "d,u", + host_notification_period => "24x7", + service_notification_commands => "notify-service-by-sms", + service_notification_options => "c", + service_notification_period => "24x7", + pager => $number, + notify => Service["nagios"], + } + +} + + # Define nagios target host. # # === Parameters