From 357bfe55e1bbb881b1a9c8831ab07a0b9fe1f5c6 Mon Sep 17 00:00:00 2001 From: Sergio Oliveira Date: Wed, 30 Nov 2016 18:14:08 -0200 Subject: [PATCH] Added tag support to rsyslog --- README.markdown | 17 +++++++++++++++++ manifests/init.pp | 4 +++- manifests/params.pp | 2 ++ manifests/rsyslog.pp | 2 ++ templates/rsyslog/22-loggly.conf.erb | 4 ++-- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/README.markdown b/README.markdown index 8895fc7..45966ed 100644 --- a/README.markdown +++ b/README.markdown @@ -160,6 +160,23 @@ node 'my_server_node.example.net' { ``` TLS enabled by default in the Loggly rsyslog module, so data sent from your systems to Loggly is encrypted and safe from unwanted eavesdropping. +Optionally you can also add tags to your setup using the tags argument: +For example: +```puppet +node 'my_server_node.example.net' { + # Send syslog events to Loggly + class { 'loggly::rsyslog': + customer_token => 'de7b5ccd-04de-4dc4-fbc9-501393600000', + tags => [ + 'application-server', + 'production', + 'ny2', + ] + } +} +``` + + #### If you use the syslog-ng daemon syslog-ng is not installed by default on Red Hat-style distributions, so ensure that the syslog-ng package is installed (a perfect job for Puppet!) before including the Loggly syslog-ng module. You will need your Customer Token you obtained from the Finding your Customer Token section of this guide. diff --git a/manifests/init.pp b/manifests/init.pp index eec7377..7d17165 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -18,7 +18,7 @@ # Enables or disables TLS encryption for shipped log events. # # [*cert_path*] -# Directory to store the Loggly TLS certs in. Normally this would be +# Directory to store the Loggly TLS certs in. Normally this would be # relative to $base_dir. # # === Authors @@ -30,6 +30,7 @@ $base_dir = $loggly::params::base_dir, $enable_tls = $loggly::params::enable_tls, $cert_path = undef, + $tags = $loggly::params::tags, ) inherits loggly::params { $_cert_path = pick($cert_path, "${base_dir}/certs") @@ -37,6 +38,7 @@ validate_absolute_path($base_dir) validate_absolute_path($_cert_path) validate_bool($enable_tls) + validate_array($tags) # create directory for loggly support files file { $base_dir: diff --git a/manifests/params.pp b/manifests/params.pp index 86a7329..889668f 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -23,6 +23,8 @@ fail("$operatingsystem not supported") } } + + $tags = [] } # vim: syntax=puppet ft=puppet ts=2 sw=2 nowrap et diff --git a/manifests/rsyslog.pp b/manifests/rsyslog.pp index e98841c..87fd498 100644 --- a/manifests/rsyslog.pp +++ b/manifests/rsyslog.pp @@ -38,11 +38,13 @@ $customer_token, $cert_path = $loggly::_cert_path, $enable_tls = $loggly::enable_tls, + $tags = $loggly::tags, ) inherits loggly { validate_string($customer_token) validate_absolute_path($cert_path) validate_bool($enable_tls) + validate_array($tags) # Emit a configuration snippet that submits events to Loggly by default file { '/etc/rsyslog.d/22-loggly.conf': diff --git a/templates/rsyslog/22-loggly.conf.erb b/templates/rsyslog/22-loggly.conf.erb index c5bc03b..7d9d1d9 100644 --- a/templates/rsyslog/22-loggly.conf.erb +++ b/templates/rsyslog/22-loggly.conf.erb @@ -4,7 +4,7 @@ ### TLS RsyslogTemplate for Loggly ########################################################## -$template LogglyFormat,"<%%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [<%= @customer_token -%>@41058 tag=\"Rsyslog TLS\"] %msg%" +$template LogglyFormat,"<%%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [<%= @customer_token -%>@41058 <% @tags.each do |value| -%>tag=\"<%=value%>\" <% end -%>] %msg%" #RsyslogGnuTLS @@ -22,7 +22,7 @@ $ActionSendStreamDriverPermittedPeer *.loggly.com ### TLS RsyslogTemplate for Loggly ########################################################## -$template LogglyFormat,"<%%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [<%= @customer_token -%>@41058] %msg%\n" +$template LogglyFormat,"<%%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [<%= @customer_token -%>@41058 <% @tags.each do |value| -%>tag=\"<%=value%>\" <% end -%>] %msg%\n" *.* @@logs-01.loggly.com:514; LogglyFormat <% end -%>