diff --git a/manifests/rsyslog.pp b/manifests/rsyslog.pp index dba073f..89fe9ea 100644 --- a/manifests/rsyslog.pp +++ b/manifests/rsyslog.pp @@ -33,56 +33,49 @@ # === Authors # # Colin Moller +# Adam Crews # class loggly::rsyslog ( - $customer_token + $customer_token, ) inherits loggly { - # Bring the TLS and certificate directory configuration into the current - # Puppet scope so that templates have access to it - $enable_tls = $loggly::enable_tls - $cert_path = $loggly::cert_path + # Bring the TLS and certificate directory configuration into the current + # Puppet scope so that templates have access to it + $enable_tls = $loggly::enable_tls + $cert_path = $loggly::cert_path - # Emit a configuration snippet that submits events to Loggly by default - file { '/etc/rsyslog.d/22-loggly.conf': - owner => 'root', - group => 'root', - mode => '0644', - content => template('loggly/rsyslog/22-loggly.conf.erb'), - notify => Exec['restart_rsyslogd'], - } - - # TLS configuration requires an extra package to be installed - if $enable_tls == true { - package { 'rsyslog-gnutls': - ensure => 'installed', - notify => Exec['restart_rsyslogd'], - } + # Emit a configuration snippet that submits events to Loggly by default + file { '/etc/rsyslog.d/22-loggly.conf': + owner => 'root', + group => 'root', + mode => '0644', + content => template("${module_name}/rsyslog/22-loggly.conf.erb"), + notify => Exec['restart_rsyslogd'], + } - # Add a dependency on the rsyslog-gnutls package to the configuration - # snippet so that it will be installed before we generate any config - File['/etc/rsyslog.d/22-loggly.conf'] -> Package['rsyslog-gnutls'] + # TLS configuration requires an extra package to be installed + if $enable_tls == true { + package { 'rsyslog-gnutls': + ensure => 'installed', + notify => Exec['restart_rsyslogd'], } - # Call an exec to restart the syslog service instead of using a puppet - # managed service to avoid external dependencies or conflicts with modules - # that may already manage the syslog daemon. - # - # Note that this will only be called on configuration changes due to the - # 'refreshonly' parameter. - exec { 'restart_rsyslogd': - command => 'service rsyslog restart', - path => [ '/usr/sbin', '/sbin', '/usr/bin/', '/bin', ], - refreshonly => true, - } - - define logfile($logname,$filepath,$severity='info') { - file { "/etc/rsyslog.d/$logname.conf": - content => template("loggly/log.conf.erb"), - notify => Exec["restart_rsyslogd"], - } - } + # Add a dependency on the rsyslog-gnutls package to the configuration + # snippet so that it will be installed before we generate any config + Class['loggly'] -> File['/etc/rsyslog.d/22-loggly.conf'] -> Package['rsyslog-gnutls'] + } + # Call an exec to restart the syslog service instead of using a puppet + # managed service to avoid external dependencies or conflicts with modules + # that may already manage the syslog daemon. + # + # Note that this will only be called on configuration changes due to the + # 'refreshonly' parameter. + exec { 'restart_rsyslogd': + command => 'service rsyslog restart', + path => [ '/usr/sbin', '/sbin', '/usr/bin/', '/bin', ], + refreshonly => true, + } } -# vi:syntax=puppet:filetype=puppet:ts=4:et: +# vi:syntax=puppet:filetype=puppet:ts=2:sw=2:et: diff --git a/manifests/rsyslog/logfile.pp b/manifests/rsyslog/logfile.pp new file mode 100644 index 0000000..d6c9cab --- /dev/null +++ b/manifests/rsyslog/logfile.pp @@ -0,0 +1,63 @@ +# == Define: loggly::rsyslog::logfile +# +# Adds the monitoring of a file. +# +# === Parameters +# +# [*logname*] +# The label to be applied to this log file. +# If it is not present it will default to the short name of the file +# +# [*filepath*] +# The fully qualified path to the file to monitor. +# +# [*severity*] +# Standard syslog severity levels. Default: info +# +# === Variables +# +# [*valid_levels*] +# A list of valid severity levels. +# +# [*_t*] +# An internal temp variable used for string parsing +# +# === Examples +# +# loggly::rsyslog::logfile { '/opt/customapp/log': +# logname => 'MY_App', +# } +# +# === Authors +# +# Colin Moller +# +define loggly::rsyslog::logfile ( + $logname = undef, + $filepath = $title, + $severity = 'info' +) { + + $valid_levels = [ + 'emerg', 'alert', 'crit', 'error', + 'warning', 'notice', 'info', 'debug', + ] + + validate_absolute_path($filepath) + validate_re($severity, $valid_levels, "severity value of ${severity} is not valid") + + if ! $logname { + $_t = split($filepath, '/') + $logname = $_t[-1] + } + + validate_string($logname) + + # This template uses $logname and $filepath + file { "/etc/rsyslog.d/${logname}.conf": + content => template("${module_name}/log.conf.erb"), + notify => Exec['restart_rsyslogd'], + } +} + +# vi:syntax=puppet:filetype=puppet:ts=4:et: diff --git a/manifests/syslog_ng.pp b/manifests/syslog_ng.pp index 7c502db..b67123a 100644 --- a/manifests/syslog_ng.pp +++ b/manifests/syslog_ng.pp @@ -50,13 +50,14 @@ # Ensure our configuration snippet directory exists before putting # configuration snippets there - file { '/etc/syslog-ng/conf.d': - ensure => 'directory', - owner => 'root', - group => 'root', - mode => '0755', + if !defined(File['/etc/syslog-ng/conf.d']){ + file { '/etc/syslog-ng/conf.d': + ensure => 'directory', + owner => 'root', + group => 'root', + mode => '0755', + } } - # Ensure we are using the correct source name on each distro $syslog_source = $::osfamily ? { 'RedHat' => 's_sys',