Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to allow logfile to work properly #4

Merged
merged 9 commits into from Apr 22, 2015

Refactor to allow logfile to work properly

  • Loading branch information
adamcrews committed Apr 17, 2015
commit 11702c5ab14743b37a7d21a7828e973f95d0f597
@@ -35,54 +35,46 @@
# Colin Moller <colin@unixarmy.com>
#
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
Class['loggly'] -> 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:
@@ -0,0 +1,64 @@
# == 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 <colin@unixarmy.com>
# Adam Crews <adam.crews@gmail.com>
#
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:
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.