Skip to content

Commit 555be0c

Browse files
author
John Cooper
committed
Added cron email address parameter to job
1 parent d532d90 commit 555be0c

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@ Cron. Minute of the hour to schedule the cron entry
369369

370370
Default: 10
371371

372+
#####`cron_email`
373+
374+
Cron. Set the email address MAILTO field for the errors from the cron job
375+
376+
Default: undef
372377

373378
### Private classes
374379

manifests/job.pp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
$cron_weekday = '*',
6363
$cron_hour = 1,
6464
$cron_minute = 10,
65+
$cron_email = undef,
6566
){
6667

6768
include ::curator
@@ -280,15 +281,22 @@
280281
$auth_string = undef
281282
}
282283

284+
if $cron_email {
285+
$cron_environment = "MAILTO=${cron_email}"
286+
} else {
287+
$cron_environment = undef
288+
}
289+
283290
$index_options = join(delete_undef_values([$_prefix, $_suffix, $_regex, $_time_unit, $_exclude, $_index, $_snapshot, $_older_than, $_newer_than, $_timestring]), ' ')
284291
$options = join(delete_undef_values([$mo_string, $ssl_string, $ssl_certificate, $ssl_no_validate, $auth_string]), ' ')
285292

286293
cron { "curator_${name}":
287-
ensure => $ensure,
288-
command => "${bin_file} --logfile ${logfile} --loglevel ${log_level} --logformat ${logformat} ${options} --host ${host} --port ${port} ${exec} ${index_options} >/dev/null",
289-
hour => $cron_hour,
290-
minute => $cron_minute,
291-
weekday => $cron_weekday,
294+
ensure => $ensure,
295+
command => "${bin_file} --logfile ${logfile} --loglevel ${log_level} --logformat ${logformat} ${options} --host ${host} --port ${port} ${exec} ${index_options} >/dev/null",
296+
hour => $cron_hour,
297+
minute => $cron_minute,
298+
weekday => $cron_weekday,
299+
environment => $cron_environment,
292300
}
293301

294302
}

spec/defines/curator_job_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@
156156
end
157157
end
158158

159+
context 'not setting email' do
160+
let (:params) {{:command => 'snapshot', :repository => 'archive'}}
161+
it { should contain_cron('curator_myjob').with(:environment => nil)}
162+
end
163+
164+
context 'setting email' do
165+
let (:params) {{:command => 'snapshot', :repository => 'archive', :cron_email => 'admin@example.com'}}
166+
it { should contain_cron('curator_myjob').with(:environment => 'MAILTO=admin@example.com')}
167+
end
168+
159169
context 'set all other params' do
160170
let(:params) do
161171
{

0 commit comments

Comments
 (0)