Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,16 @@
# package(s)
class { 'lumberjack::package': }

file { '/etc/lumberjack':
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755'
}

Anchor['lumberjack::begin'] ->
Class['lumberjack::package'] ->
File['/etc/lumberjack'] ->
Anchor['lumberjack::end']

}
129 changes: 100 additions & 29 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
@@ -1,26 +1,57 @@
# Define: lumberjack::instance
#
# This define allows you to setup an instance of lumberjack
# This define allows you to setup an instance of lumberjack.
#
# NOTE: The value of $json_conf will affect certain parameters.
#
# === Parameters
#
# [*host*]
# Host name or IP address of the Logstash instance to connect to
# Value type is string
# Default value: undef
# This variable is optional
# This value is affected by the value of $json_conf.
# $json_conf = false
# Host name or IP address of the Logstash instance to connect to.
# Value type is string
# Default value: undef
# This variable is optional
# $json_conf = true
# Array of "<hostname_or_ip>:<port>" values.
# Value type is an array of string
# Default value: undef
# This variable is required
#
# [*port*]
# Port number of the Logstash instance to connect to
# This value is affected by the value of $json_conf.
# $json_conf = false
# Port number of the Logstash instance to connect to
# Value type is number
# Default value: undef
# This variable is optional
# $json_conf = true
# Default value: undef
# This variable is unused
#
# [*timeout*]
# Network timeout value when $json_conf is enabled.
# Value type is number
# Default value: undef
# This variable is optional
# Default value: 15
# This value is optional
#
# [*files*]
# Array of files you wish to process
# Value type is array
# Default value: undef
# This variable is optional
# This value is affected by the value of $json_conf.
# $json_conf = false
# Array of files you wish to process.
# Value type is array
# Default value: undef
# This variable is optional
# $json_conf = true
# A hash of
# Value type is hash of files configuration.
# Default value: undef
# This variable is optional
#
# [*json_conf*]
# Create a JSON configuration file. This will affect how the $host, $port,
# and $files parameters are used.
#
# [*ssl_ca_file*]
# File to use for the SSL CA
Expand Down Expand Up @@ -48,7 +79,9 @@
$ssl_ca_file,
$host = undef,
$port = undef,
$timeout = '15',
$files = undef,
$json_conf = false,
$fields = false,
$run_as_service = true,
$ensure = $logstash::ensure
Expand All @@ -64,31 +97,35 @@

if ($run_as_service == true ) {

# Input validation
validate_string($host)
if $json_conf == false {
# Input validation
validate_string($host)

if ! is_numeric($port) {
fail("\"${port}\" is not a valid port parameter value")
}
if ! is_numeric($port) {
fail("\"${port}\" is not a valid port parameter value")
}

validate_array($files)
$logfiles = join($files,' ')
validate_array($files)
$logfiles = join($files,' ')

if $fields {
validate_hash($fields)
if $fields {
validate_hash($fields)
}
}

# Setup init file if running as a service
$notify_lumberjack = $lumberjack::restart_on_change ? {
true => Service["lumberjack-${name}"],
false => undef,
if $lumberjack::restart_on_change == true {
$lumberjack_notify = Service["lumberjack-${name}"]
$lumberjack_before = undef
} else {
$lumberjack_notify = undef
$lumberjack_before = Service["lumberjack-${name}"]
}

file { "/etc/init.d/lumberjack-${name}":
ensure => $ensure,
mode => '0755',
content => template("${module_name}/etc/init.d/lumberjack.erb"),
notify => $notify_lumberjack
notify => $lumberjack_notify
}

#### Service management
Expand Down Expand Up @@ -138,29 +175,63 @@
service { "lumberjack-${name}":
ensure => $service_ensure,
enable => $service_enable,
name => $lumberjack::params::service_name,
name => "${lumberjack::params::service_name}-${name}",
hasstatus => $lumberjack::params::service_hasstatus,
hasrestart => $lumberjack::params::service_hasrestart,
pattern => $lumberjack::params::service_pattern,
}

} else {

$notify_lumberjack = undef
$lumberjack_notify = undef
$lumberjack_before = undef

}

# Configuration
if $json_conf {
if !is_array($host) {
fail('When $json_conf is true $host must be an array of hostname:port values')
}

if ! is_numeric($timeout) {
fail("\"${timeout}\" is not a valid timeout parameter value")
}

$conf_hash = {
network => {
'servers' => $host,
'ssl ca' => "/etc/lumberjack/${name}/ca.crt",
'timeout' => $timeout,
},
files => $files
}


file { "/etc/lumberjack/${name}/lumberjack.conf":
mode => '0640',
owner => 'root',
group => 'root',
content => sorted_json($conf_hash),
require => File["/etc/lumberjack/${name}"],
notify => $lumberjack_notify,
before => $lumberjack_before
}
}


file { "/etc/lumberjack/${name}":
ensure => directory,
require => File['/etc/lumberjack']
}

# Setup certificate files
file { "/etc/lumberjack/${name}/ca.crt":
ensure => $ensure,
source => $ssl_ca_file,
require => File[ "/etc/lumberjack/${name}" ],
notify => $notify_lumberjack
notify => $lumberjack_notify,
before => $lumberjack_before
}

}
10 changes: 7 additions & 3 deletions templates/etc/init.d/lumberjack.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ end

DAEMON_PATH="/opt/lumberjack/"
DAEMON="bin/lumberjack.sh"
DAEMONOPTS="--ssl-ca-path /etc/lumberjack/<%= @instance %>/ca.crt --host <%= @host %> --port <%= @port %> <%= extra_fields %> <%= @logfiles %>"
<% if json_conf %>
DAEMONOPTS="-config /etc/lumberjack/<%= @name %>/lumberjack.conf"
<% else %>
DAEMONOPTS="--ssl-ca-path /etc/lumberjack/<%= @name %>/ca.crt --host <%= @host %> --port <%= @port %> <%= extra_fields %> <%= @logfiles %>"
<% end %>

NAME="lumberjack-<%= @instance %>"
DESC="Lumberjack-<%= @instance %>"
NAME="lumberjack-<%= @name %>"
DESC="Lumberjack-<%= @name %>"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

Expand Down