Puppet Class: simp_logstash::clean
- Defined in:
- manifests/clean.pp
Overview
Create a cron job to clean your ElasticSearch indices on a regular basis using elasticsearch-curator.
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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'manifests/clean.pp', line 53
class simp_logstash::clean (
$ensure = 'present',
$host = '127.0.0.1',
$keep_days = '356',
$keep_hours = '',
$keep_space = '',
$prefix = 'logstash-',
$port = '9199',
$separator = '.',
$es_timeout = '30',
$log_file = '/var/log/logstash/curator_clean.log',
$cron_hour = '1',
$cron_minute = '15',
$cron_month = '*',
$cron_monthday = '*',
$cron_weekday = '*'
) {
validate_array_member($ensure,['present','absent'])
if defined('$::simp_logstash::auto_clean') and getvar('::simp_logstash::auto_clean') {
$_simp_ls_auto_clean = true
}
else {
$_simp_ls_auto_clean = false
}
if ($ensure == 'present') and $_simp_ls_auto_clean {
validate_string($prefix)
validate_port($port)
validate_string($separator)
validate_integer($es_timeout)
validate_absolute_path($log_file)
if ($cron_hour != '*') { validate_integer($cron_hour) }
if ($cron_minute != '*') { validate_integer($cron_minute) }
if ($cron_month != '*') { validate_integer($cron_month) }
if ($cron_monthday != '*') { validate_integer($cron_monthday) }
if ($cron_weekday != '*') { validate_integer($cron_weekday) }
if size(reject([$keep_days, $keep_hours, $keep_space],'^\s*$')) > 1 {
fail('You may only specify one of $keep_days, $keep_hours, or $keep_space')
}
if !empty($keep_hours) {
validate_integer($keep_hours)
$_limit = "-T hours --older-than ${keep_hours}"
}
elsif ! empty($keep_days) {
validate_integer($keep_days)
$_limit = "-T days --older-than ${keep_days}"
}
elsif ! empty($keep_space) {
validate_integer($keep_space)
$_limit = "--disk-space ${keep_space}"
}
else {
fail('You must specify one of $keep_days, $keep_hours, or $keep_space')
}
cron { 'logstash_index_cleanup' :
ensure => $ensure,
command => "/usr/bin/curator --host ${host} --port ${port} -t ${es_timeout} delete -p '${prefix}' -s '${separator}' ${_limit} >> ${log_file} 2>&1",
hour => $cron_hour,
minute => $cron_minute,
month => $cron_month,
monthday => $cron_monthday,
weekday => $cron_weekday,
require => Class['simp_logstash::curator']
}
}
else {
cron { 'logstash_index_cleanup' : ensure => 'absent' }
}
}
|