From c605175376c4ad198d158d8e141df8a31a9c23bf Mon Sep 17 00:00:00 2001 From: Tom Mitchell Date: Sun, 15 Dec 2013 07:40:07 -0500 Subject: added support for /etc/apcupsd/change, which is a script designed to email someone when the UPS battery needs to be changed. Added two defaulted paramters to the apcupsd class, admin (the email address of the admin to receive the mail (defaults to root)), and mail (the program used to send the email (defaults to mail)). --- manifests/init.pp | 12 ++++++++++++ templates/changeme.erb | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 templates/changeme.erb diff --git a/manifests/init.pp b/manifests/init.pp index 2035f47..9c963f6 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -22,6 +22,8 @@ class apcupsd( $device = '/dev/ttyS0', $ensure = 'present', $nisip = '127.0.0.1', + $admin = 'root', + $mail = 'mail', $polltime = '60' ) { @@ -56,6 +58,16 @@ class apcupsd( content => template('apcupsd/apcupsd.conf.erb'), } + file { "/etc/apcupsd/changeme": + ensure => present, + owner => root, + group => root, + mode => 0755, + notify => Service["apcupsd"], + require => File["/etc/apcupsd"], + content => template('apcupsd/changeme.erb'), + } + file { "/etc/default/apcupsd": ensure => present, owner => root, diff --git a/templates/changeme.erb b/templates/changeme.erb new file mode 100644 index 0000000..13cc553 --- /dev/null +++ b/templates/changeme.erb @@ -0,0 +1,25 @@ +#!/bin/sh +# +# THIS FILE IS BEING MANAGED BY PUPPET +# ANY MODIFICATIONS MADE MANUALLY WILL BE OVERWRITTEN +# ON THE NEXT PUPPET RUN +# +# This shell script if placed in /etc/apcupsd +# will be called by /etc/apcupsd/apccontrol when apcupsd +# detects that the battery should be replaced. +# We send an email message to root to notify him. +# +SYSADMIN=<%= admin %> +APCUPSD_MAIL=<%= mail %> + +HOSTNAME=`hostname` +MSG="$HOSTNAME UPS battery needs changing NOW." +# +( + echo "Subject: $MSG" + echo " " + echo "$MSG" + echo " " + /sbin/apcaccess status +) | $APCUPSD_MAIL -s "$MSG" $SYSADMIN +exit 0 -- cgit v1.2.3