From 3c437ce73ab0f01f49f2ed4763f142158a113554 Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Wed, 6 Nov 2013 16:18:55 -0500 Subject: [PATCH 01/14] Should be name and not instance. --- templates/etc/init.d/lumberjack.erb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/templates/etc/init.d/lumberjack.erb b/templates/etc/init.d/lumberjack.erb index 3eff4b1..77d8b7c 100644 --- a/templates/etc/init.d/lumberjack.erb +++ b/templates/etc/init.d/lumberjack.erb @@ -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 From 7e7b485a92d4cc8aa63e892aa8f08e2e06dc1d87 Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Wed, 6 Nov 2013 16:56:58 -0500 Subject: [PATCH 02/14] Comment out stdlib because it pulls in a newer version than we're currently using and I don't want to deal with that now. --- Modulefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modulefile b/Modulefile index 2c38bf1..58f3f0d 100644 --- a/Modulefile +++ b/Modulefile @@ -6,4 +6,4 @@ license 'Apache License, Version 2.0' summary 'Module for managing and configuring lumberjack' description 'Module for managing and configuring lumberjack' project_page 'https://github.com/electrical/puppet-lumberjack' -dependency 'puppetlabs/stdlib', '>= 3.0.0' +#dependency 'puppetlabs/stdlib', '>= 3.0.0' From fe1773eeab918c0f1be72e1ef51525f34db1c9ca Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Wed, 6 Nov 2013 18:09:38 -0500 Subject: [PATCH 03/14] Create parent conf directory since our RPM does not. --- manifests/instance.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/instance.pp b/manifests/instance.pp index c5a3de3..4d9984e 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -151,7 +151,7 @@ } - file { "/etc/lumberjack/${name}": + file { [ '/etc/lumberjack', "/etc/lumberjack/${name}" ]: ensure => directory, } From 80a7a3e24fa65c0e7763de61d88c335cc1f66c17 Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Wed, 6 Nov 2013 19:12:37 -0500 Subject: [PATCH 04/14] Ensure if we don't want the service to reload on change that conf gets layed down beforehand Conflicts: manifests/instance.pp --- manifests/instance.pp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/manifests/instance.pp b/manifests/instance.pp index 4d9984e..f7235b8 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -78,17 +78,19 @@ 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 @@ -146,7 +148,8 @@ } else { - $notify_lumberjack = undef + $lumberjack_notify = undef + $lumberjack_before = undef } @@ -160,7 +163,8 @@ ensure => $ensure, source => $ssl_ca_file, require => File[ "/etc/lumberjack/${name}" ], - notify => $notify_lumberjack + notify => $lumberjack_notify, + before => $lumberjack_before } } From 86f56c97fe2e6bbf93b0c6aa04f744832bf84edb Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Wed, 6 Nov 2013 19:24:53 -0500 Subject: [PATCH 05/14] New attempt at creating a config for lumberjack --- manifests/instance.pp | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/manifests/instance.pp b/manifests/instance.pp index f7235b8..7147ca3 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -50,6 +50,7 @@ $port = undef, $files = undef, $fields = false, + $json_conf = false, $run_as_service = true, $ensure = $logstash::ensure ) { @@ -71,11 +72,13 @@ fail("\"${port}\" is not a valid port parameter value") } - validate_array($files) - $logfiles = join($files,' ') + if $json_conf == false { + validate_array($files) + $logfiles = join($files,' ') - if $fields { - validate_hash($fields) + if $fields { + validate_hash($fields) + } } if $lumberjack::restart_on_change == true { @@ -153,6 +156,28 @@ } + # Configuration + if $json_conf { + $conf_global_hash = { + network => { + 'servers' => $host, + 'ssl ca' => "/etc/lumberjack/${name}/ca.crt", + } + } + + $conf_hash_full = merge($conf_global_hash, $json_conf) + + file { "/etc/lumberjack/${name}/lumberjack.conf": + mode => '0640', + owner => 'root', + group => 'root', + content => sorted_json($conf_hash_full), + require => File["/etc/lumberjack/${name}"], + notify => $lumberjack_notify, + before => $lumberjack_before + } + } + file { [ '/etc/lumberjack', "/etc/lumberjack/${name}" ]: ensure => directory, From c62ae04e68c2ad87c75a1f29ca0c994d7d9af8c5 Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Wed, 6 Nov 2013 19:28:57 -0500 Subject: [PATCH 06/14] rename $json_conf to $conf_hash --- manifests/instance.pp | 8 ++++---- templates/etc/init.d/lumberjack.erb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/manifests/instance.pp b/manifests/instance.pp index 7147ca3..0849002 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -50,7 +50,7 @@ $port = undef, $files = undef, $fields = false, - $json_conf = false, + $conf_hash = undef, $run_as_service = true, $ensure = $logstash::ensure ) { @@ -72,7 +72,7 @@ fail("\"${port}\" is not a valid port parameter value") } - if $json_conf == false { + if $conf_hash == undef{ validate_array($files) $logfiles = join($files,' ') @@ -157,7 +157,7 @@ } # Configuration - if $json_conf { + if $conf_hash { $conf_global_hash = { network => { 'servers' => $host, @@ -165,7 +165,7 @@ } } - $conf_hash_full = merge($conf_global_hash, $json_conf) + $conf_hash_full = merge($conf_global_hash, $conf_hash) file { "/etc/lumberjack/${name}/lumberjack.conf": mode => '0640', diff --git a/templates/etc/init.d/lumberjack.erb b/templates/etc/init.d/lumberjack.erb index 77d8b7c..955c008 100644 --- a/templates/etc/init.d/lumberjack.erb +++ b/templates/etc/init.d/lumberjack.erb @@ -14,7 +14,7 @@ end DAEMON_PATH="/opt/lumberjack/" DAEMON="bin/lumberjack.sh" -<% if json_conf %> +<% if conf_hash %> DAEMONOPTS="-config /etc/lumberjack/<%= @name %>/lumberjack.conf" <% else %> DAEMONOPTS="--ssl-ca-path /etc/lumberjack/<%= @name %>/ca.crt --host <%= @host %> --port <%= @port %> <%= extra_fields %> <%= @logfiles %>" From 52c37eb28886b1ca2cf0610fcc256300d1a5e225 Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Wed, 6 Nov 2013 19:41:31 -0500 Subject: [PATCH 07/14] Ensure a different service per instance. --- manifests/instance.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/instance.pp b/manifests/instance.pp index 0849002..fb2f3b6 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -143,7 +143,7 @@ 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, From 6510dc1ba57d8c7d23e45a3e13dc2302339c7d1e Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Wed, 6 Nov 2013 20:04:29 -0500 Subject: [PATCH 08/14] Bring back $json_conf --- manifests/instance.pp | 14 +++++++------- templates/etc/init.d/lumberjack.erb | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifests/instance.pp b/manifests/instance.pp index fb2f3b6..c4aca0f 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -49,8 +49,8 @@ $host = undef, $port = undef, $files = undef, + $json_conf = false, $fields = false, - $conf_hash = undef, $run_as_service = true, $ensure = $logstash::ensure ) { @@ -72,7 +72,7 @@ fail("\"${port}\" is not a valid port parameter value") } - if $conf_hash == undef{ + if $json_conf == false { validate_array($files) $logfiles = join($files,' ') @@ -157,21 +157,21 @@ } # Configuration - if $conf_hash { - $conf_global_hash = { + if $json_conf { + $conf_hash = { network => { 'servers' => $host, 'ssl ca' => "/etc/lumberjack/${name}/ca.crt", - } + }, + files => $files } - $conf_hash_full = merge($conf_global_hash, $conf_hash) file { "/etc/lumberjack/${name}/lumberjack.conf": mode => '0640', owner => 'root', group => 'root', - content => sorted_json($conf_hash_full), + content => sorted_json($conf_hash), require => File["/etc/lumberjack/${name}"], notify => $lumberjack_notify, before => $lumberjack_before diff --git a/templates/etc/init.d/lumberjack.erb b/templates/etc/init.d/lumberjack.erb index 955c008..77d8b7c 100644 --- a/templates/etc/init.d/lumberjack.erb +++ b/templates/etc/init.d/lumberjack.erb @@ -14,7 +14,7 @@ end DAEMON_PATH="/opt/lumberjack/" DAEMON="bin/lumberjack.sh" -<% if conf_hash %> +<% 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 %>" From e4473a66da6181c99dd86adeeff9f4ae5685813a Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Wed, 6 Nov 2013 20:21:58 -0500 Subject: [PATCH 09/14] if $json_conf pass in an array for host. --- manifests/instance.pp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/manifests/instance.pp b/manifests/instance.pp index c4aca0f..331771a 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -158,6 +158,10 @@ # Configuration if $json_conf { + if !is_array($host) { + fail('When $json_conf is true $host must be an array of hostname:port values') + } + $conf_hash = { network => { 'servers' => $host, From add787d680898d7d530aa91494fbad0b78454b79 Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Wed, 6 Nov 2013 20:24:31 -0500 Subject: [PATCH 10/14] check host and port if we're not using $json_conf --- manifests/instance.pp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/manifests/instance.pp b/manifests/instance.pp index 331771a..859f04d 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -65,14 +65,14 @@ 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") + } - if $json_conf == false { validate_array($files) $logfiles = join($files,' ') From a40ecf45aa058d6c024a3e4be6005d8765782ae5 Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Thu, 7 Nov 2013 09:10:30 -0500 Subject: [PATCH 11/14] Add documentation --- manifests/instance.pp | 51 ++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/manifests/instance.pp b/manifests/instance.pp index 859f04d..5899198 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -1,26 +1,51 @@ # 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 ":" 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 -# Value type is number -# Default value: undef -# This variable is optional +# 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 # # [*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 From b1815687460cc5976b60f5bc9ca30bf5807e3342 Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Thu, 7 Nov 2013 09:23:14 -0500 Subject: [PATCH 12/14] Properly anchor lumberjack package --- manifests/init.pp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/manifests/init.pp b/manifests/init.pp index 7c63d7a..2be42d7 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -122,4 +122,8 @@ # package(s) class { 'lumberjack::package': } + Anchor['lumberjack::begin'] -> + Class['lumberjack::package'] -> + Anchor['lumberjack::end'] + } From 4a0793dcab0b59026312179930f2ed81066816be Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Thu, 7 Nov 2013 09:26:28 -0500 Subject: [PATCH 13/14] Move File['/etc/lumberjack'] out of lumberjack::instance to avoid a dupe resource. --- manifests/init.pp | 8 ++++++++ manifests/instance.pp | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index 2be42d7..f35526e 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -122,8 +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'] } diff --git a/manifests/instance.pp b/manifests/instance.pp index 5899198..4617bee 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -208,8 +208,9 @@ } - file { [ '/etc/lumberjack', "/etc/lumberjack/${name}" ]: + file { "/etc/lumberjack/${name}": ensure => directory, + require => File['/etc/lumberjack'] } # Setup certificate files From 2bbb82a3215258a75f99ae40a5480b837e2b6f45 Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Thu, 7 Nov 2013 14:00:41 -0500 Subject: [PATCH 14/14] Handle network timeout. --- manifests/instance.pp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/manifests/instance.pp b/manifests/instance.pp index 4617bee..6428407 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -30,6 +30,12 @@ # Default value: undef # This variable is unused # +# [*timeout*] +# Network timeout value when $json_conf is enabled. +# Value type is number +# Default value: 15 +# This value is optional +# # [*files*] # This value is affected by the value of $json_conf. # $json_conf = false @@ -73,6 +79,7 @@ $ssl_ca_file, $host = undef, $port = undef, + $timeout = '15', $files = undef, $json_conf = false, $fields = false, @@ -187,10 +194,15 @@ 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 }