1
0
mirror of https://github.com/krislamo/puppet-fluentd synced 2025-04-12 08:14:21 +00:00

Compare commits

..

No commits in common. "master" and "0.5.0" have entirely different histories.

42 changed files with 593 additions and 798 deletions

View File

@ -6,14 +6,12 @@ script: bundle exec rake validate && bundle exec rake lint && bundle exec rake s
matrix: matrix:
fast_finish: true fast_finish: true
include: include:
- rvm: 2.1.10 - rvm: 1.9.3
env: PUPPET_VERSION="~> 4.0" STRICT_VARIABLES="yes" env: PUPPET_GEM_VERSION="~> 3.0"
- rvm: 2.2.7 - rvm: 2.1.5
env: PUPPET_VERSION="~> 4.0" STRICT_VARIABLES="yes" env: PUPPET_GEM_VERSION="~> 3.0"
- rvm: 2.3.4 - rvm: 2.1.6
env: PUPPET_VERSION="~> 4.0" STRICT_VARIABLES="yes" env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes"
- rvm: 2.4.1
env: PUPPET_VERSION="~> 4.0" STRICT_VARIABLES="yes"
notifications: notifications:
slack: slack:
secure: WVBx/OJqLpX9WXyiejEdnOcAf+5ShWJ2gcyeBCX032iKzPphcdPKqH+jnlFaKjqQCZARbRqzlj/if3FZWAlhWtTrWrcY545dRHcsaGvJ/nMtdHlBUuwUNHipSn+RTXtorsYz0efhJMPye2LMl0HgAp3rEs70XUt8rZOwdedLGVgfWRwM+KixhSf8P08v9QjNRNdhWII37KFRdqv/NHryNlVKsTLH6fQOyIvok3vrTvMR8rWMRETXv6JLpCJ3FfOrxo53fW7q+GlXXuVcQ2OGlgxm3eke6q2aXZAqczeB5CSlWgUEA5T3rQ//WI3enwTayRajV/9O26HZvASjSTnDRiSSv1itYqg1Uy6kuJy5ANpBizOyWY6/QTM5Rw00AXvaY9ur0EmyNe5vLNHyTxzdr4R+rXjE07yCDvWM9RGbu+4BipP+mAoJTkuCIP54FWYn1qOJnC8DYywD/+wniCNLbp6yMgbG/aC6H5RmuSy+3xRoEbwvyXKUgA+4gL3I3aAIvidBG+yazRBFvRCn4pUJdTEc4Cpu0jhQWXWyZSE66HNPKyIOXl9JPTzul08MDo9OaqBt+K3yeMVA8EPr196mWLwerF+dExQ2PJhUu/7MAiOgFrIr4/d05iKhj4ivLYBRNN317s2NVo8qyfhPHlfv6PyzhllC/qjClQ2rLOemVhg= secure: WVBx/OJqLpX9WXyiejEdnOcAf+5ShWJ2gcyeBCX032iKzPphcdPKqH+jnlFaKjqQCZARbRqzlj/if3FZWAlhWtTrWrcY545dRHcsaGvJ/nMtdHlBUuwUNHipSn+RTXtorsYz0efhJMPye2LMl0HgAp3rEs70XUt8rZOwdedLGVgfWRwM+KixhSf8P08v9QjNRNdhWII37KFRdqv/NHryNlVKsTLH6fQOyIvok3vrTvMR8rWMRETXv6JLpCJ3FfOrxo53fW7q+GlXXuVcQ2OGlgxm3eke6q2aXZAqczeB5CSlWgUEA5T3rQ//WI3enwTayRajV/9O26HZvASjSTnDRiSSv1itYqg1Uy6kuJy5ANpBizOyWY6/QTM5Rw00AXvaY9ur0EmyNe5vLNHyTxzdr4R+rXjE07yCDvWM9RGbu+4BipP+mAoJTkuCIP54FWYn1qOJnC8DYywD/+wniCNLbp6yMgbG/aC6H5RmuSy+3xRoEbwvyXKUgA+4gL3I3aAIvidBG+yazRBFvRCn4pUJdTEc4Cpu0jhQWXWyZSE66HNPKyIOXl9JPTzul08MDo9OaqBt+K3yeMVA8EPr196mWLwerF+dExQ2PJhUu/7MAiOgFrIr4/d05iKhj4ivLYBRNN317s2NVo8qyfhPHlfv6PyzhllC/qjClQ2rLOemVhg=

View File

@ -1,38 +1,5 @@
# Changelog # Changelog
## 1.0.0
**Breaking changes:** This version drops puppet 3 support!
* Fix hard coded user/group names in config manifest (#23)
* migrate from stdlib validation to puppet datatypes (#24)
## 0.6.0
* Updated README
* fixed broken links, due to github organisation rename
* fixed indentation for config files (filter, match, source)
* use rspec-puppet-facts for unit testing
## 0.5.6
* Fixed `conf_dir_manage` parameter call
## 0.5.5
* Added `conf_dir_manage` parameter (Default: false)
* Exclusively handle config files into fluentd::conf_dir. Other files not created by puppet, will be deleted
## 0.5.4
* fixed templates/filter.erb
* fixed removing of old GPG key for yum repos
## 0.5.3
* update treasure data repo gpg key
## 0.5.2
* Correct the docs related to the service_enable parameter
## 0.5.1
* Allow to install specific version of fluent gem plugins
## 0.5.0 ## 0.5.0
* Added support for Debian 6, 7, 8 * Added support for Debian 6, 7, 8
* Added support for CentOS 6, 7 * Added support for CentOS 6, 7

16
Gemfile
View File

@ -1,22 +1,10 @@
source 'https://rubygems.org' source 'https://rubygems.org'
ENV['PUPPET_VERSION'].nil? ? puppetversion = '~> 4.6' : puppetversion = ENV['PUPPET_VERSION'].to_s puppetversion = ENV.key?('PUPPET_VERSION') ? "#{ENV['PUPPET_VERSION']}" : ['>= 3.3']
gem 'puppet', puppetversion gem 'puppet', puppetversion
gem 'puppetlabs_spec_helper', '>= 0.8.2' gem 'puppetlabs_spec_helper', '>= 0.8.2'
gem 'puppet-lint', '>= 1.0.0' gem 'puppet-lint', '>= 1.0.0'
gem 'facter', '>= 1.7.0' gem 'facter', '>= 1.7.0'
gem 'beaker-rspec'
gem 'beaker-puppet_install_helper' gem 'beaker-puppet_install_helper'
gem 'metadata-json-lint' gem 'metadata-json-lint'
gem 'rspec-puppet-facts', '~> 1.7'
beakerrspec = '> 0'
platforms [:ruby_19, :ruby_21] do
beakerrspec = '<= 5.6.0'
end
gem 'beaker-rspec', beakerrspec
platforms :ruby_19 do
gem 'public_suffix', '< 1.5.0', :platforms => :ruby_19
gem 'nokogiri', '~> 1.8.1', :platforms => :ruby_19
gem 'mime-types', '< 3.0', :platforms => :ruby_19
end

View File

@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier same "printed page" as the copyright notice for easier
identification within third-party archives. identification within third-party archives.
Copyright 2017 ATVAG GmbH Copyright 2015 wywy GmbH
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

138
README.md
View File

@ -1,7 +1,7 @@
# pilchkinstein-gtv/fluentd Puppet Module # wywygmbh/fluentd Puppet Module
[![GitHub version](https://badge.fury.io/gh/wywy%2Fpuppet-fluentd.svg)](https://github.com/pilchkinstein-gtv/puppet-fluentd) [![GitHub version](https://badge.fury.io/gh/wywygmbh%2Fpuppet-fluentd.svg)](https://github.com/wywygmbh/puppet-fluentd)
[![Build Status](https://travis-ci.org/wywy/puppet-fluentd.svg?branch=master)](https://travis-ci.org/wywy/puppet-fluentd) [![Build Status](https://travis-ci.org/wywygmbh/puppet-fluentd.svg?branch=master)](https://travis-ci.org/wywygmbh/puppet-fluentd)
@ -15,7 +15,6 @@
* [Source](#source) * [Source](#source)
* [Filter](#filter) * [Filter](#filter)
* [Match](#match) * [Match](#match)
* [Match with buffer and chunk_keys](#match-with-buffer-and-chunk_keys)
* [Match Store](#match-store) * [Match Store](#match-store)
* [Plugin Installation](#plugin-installation) * [Plugin Installation](#plugin-installation)
* [Requirements](#requirements) * [Requirements](#requirements)
@ -49,62 +48,42 @@ include '::fluentd'
Include repository to install recent fluentd (td-agent) from. Include repository to install recent fluentd (td-agent) from.
**Default:** 'true' **Default:** 'true'
`package_ensure` `package_ensure`
Package ensure. Package ensure.
**Default:** 'installed' **Default:** 'installed'
`package_name` `package_name`
Package name. Package name.
**Default:** 'td-agent' **Default:** 'td-agent'
`package_install_options` `package_install_options`
Package install options. Package install options.
**Default:** '[]' **Default:** '[]'
`service_manage` `service_manage`
Defines if the service should be managed by puppet. Defines if the service should be managed by puppet.
**Default:** 'true' **Default:** 'true'
`service_name` `service_name`
Name of the service. Name of the service.
**Default:** 'td-agent' **Default:** 'td-agent'
`service_ensure` `service_ensure`
Service ensure. Service ensure.
**Default:** 'running' **Default:** 'running'
`service_enable` `service_enabled`
Defines if the service should be enabled. Defines if the service should be enabled.
**Default:** 'true' **Default:** 'true'
`config_path`
Path to configuration files
**Default:** '/etc/td-agent'
`config_dir`
Configuration directory name
**Default:** '${config_path}/conf.d'
`config_file`
Default configuration file name
**Default:** '${config_path}/td-agent.conf'
`conf_dir_manage`
Exclusively handle config files into fluentd::conf_dir. Other files not created by puppet, will be deleted
**Default:** 'false'
`user_manage` `user_manage`
Defines if the user should be manage, which will add the user Defines if the user should be manage, which will add the user
@ -115,11 +94,11 @@ include '::fluentd'
`user_name` `user_name`
**Default:** 'td-agent' **Default:** 'td-agent'
`user_group` `user_group`
**Default:** 'td-agent' **Default:** 'td-agent'
`user_groups` `user_groups`
**Default:** '["adm"]' **Default:** '["adm"]'
@ -132,18 +111,7 @@ include '::fluentd'
'type' => 'tail', 'type' => 'tail',
'format' => 'json', 'format' => 'json',
'path' => '/var/log/test-application/*.json', 'path' => '/var/log/test-application/*.json',
'parse' => { 'tag' => 'application.test'
'type' => 'regexp',
'expression' => '^(?<name>[^ ]*) (?<user>[^ ]*) (?<age>\d*)$'
},
'storage'=> {
'type' => 'local',
'path' => 'test.pos'
},
'tag' => 'application.test',
'parse' => {
'message_format' => 'auto'
}
} }
} }
``` ```
@ -154,18 +122,7 @@ include '::fluentd'
type tail type tail
format json format json
path /var/log/test-application/*.json path /var/log/test-application/*.json
<parse>
type regexp
expression ^(?<name>[^ ]*) (?<user>[^ ]*) (?<age>\d*)$
</parse>
<storage>
type local
path test.pos
</storage>
tag application.test tag application.test
<parse>
message_format auto
</parse>
</source> </source>
``` ```
#### Filter #### Filter
@ -224,41 +181,7 @@ include '::fluentd'
</server> </server>
</match> </match>
``` ```
#### Match with buffer and chunk_keys ### Match Store
buffer_chunk_keys will not be included in the template. They will be filtered and only be used as a "pattern" for the buffer section.
```
::fluentd::match { 'test':
priority => 98,
pattern => 'test.**',
config => {
type => 'file',
path => '/var/log/td-agent/test/${host}',
append => true,
buffer_chunk_keys => 'host',
buffer => {
type => file,
path => /var/log/td-agent/test/buffer/,
flush_mode => immediate,
},
},
}
```
**creates:**
```
<match test.**>
type file
path /var/log/td-agent/test/${host}
append true
<buffer host>
type file
path /var/log/td-agent/test/buffer/
flush_mode immediate
</buffer>
</match>
```
#### Match Store
```puppet ```puppet
::fluentd::match { 'test': ::fluentd::match { 'test':
priority => 30, priority => 30,
@ -274,13 +197,7 @@ buffer_chunk_keys will not be included in the template. They will be filtered an
}, },
{ {
'type' => 'file', 'type' => 'file',
'path' => '/tmp/td-agent-debug-${host}.log', 'path' => '/tmp/td-agent-debug.log',
'buffer_chunk_keys' => 'host',
'buffer' => [{
'@type' => 'file',
path => '/var/log/td-agent/buffer/',
flush_mode => 'immediate',
}]
} }
] ]
} }
@ -299,11 +216,7 @@ buffer_chunk_keys will not be included in the template. They will be filtered an
</store> </store>
<store> <store>
type file type file
path /tmp/td-agent-debug-${host}.log path /tmp/crs
<buffer host>
@type file
path /var/log/td-agent/buffer/
flush_mode immediate
</store> </store>
</match> </match>
``` ```
@ -315,8 +228,7 @@ This module gives you the possibility to install plugins as gem or files.
**gem installation** **gem installation**
```puppet ```puppet
::fluentd::plugin { 'fluent-plugin-elasticsearch': ::fluentd::plugin { 'fluent-plugin-elasticsearch':
type => 'gem', type => 'gem'
ensure => '0.1.3'
} }
``` ```
**file installation** **file installation**
@ -330,14 +242,14 @@ This module gives you the possibility to install plugins as gem or files.
### Requirements ### Requirements
Modules: Modules:
* puppetlabs/apt >= 4.0.0 * puppetlabs/apt >= 1.8.0 < 3.0.0
## Limitations ## Limitations
This module has been built on and tested against Puppet 4.6 and higher. This module has been built on and tested against Puppet 3.7.5 and higher.
The module has been tested on: The module has been tested on:
* Ubuntu 16.04 * Ubuntu 12.04
Testing on other platforms has been light and cannot be guaranteed. Testing on other platforms has been light and cannot be guaranteed.
@ -352,8 +264,8 @@ To run the tests install the ruby dependencies with `bundler` and execute
bundle install --path vendor/bundle bundle install --path vendor/bundle
bundle exec rake spec bundle exec rake spec
bundle exec rake lint bundle exec rake lint
bundle exec rake beaker BEAKER_set=ubuntu-server-1204-x64
bundle exec rake beaker BEAKER_set=ubuntu-server-1404-x64 bundle exec rake beaker BEAKER_set=ubuntu-server-1404-x64
bundle exec rake beaker BEAKER_set=ubuntu-server-1604-x64
bundle exec rake beaker BEAKER_set=debian-60-x64 bundle exec rake beaker BEAKER_set=debian-60-x64
bundle exec rake beaker BEAKER_set=debian-78-x64 bundle exec rake beaker BEAKER_set=debian-78-x64
bundle exec rake beaker BEAKER_set=debian-82-x64 bundle exec rake beaker BEAKER_set=debian-82-x64
@ -363,7 +275,7 @@ bundle exec rake beaker BEAKER_set=centos-70-x64
## License ## License
Copyright 2017 ATVAG GmbH Copyright 2015 wywy GmbH
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -377,4 +289,4 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
This Puppet module is being actively maintained by some fellow puppeteers at [wywy](http://wywy.com/). This Puppet module is being actively maintained by some fellow puppeteers at [wywy GmbH](http://wywy.com/).

View File

@ -1,23 +1,7 @@
require 'puppetlabs_spec_helper/rake_tasks' require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint' require 'puppet-lint/tasks/puppet-lint'
PuppetLint.configuration.log_format = '%{path}:%{line}:%{check}:%{KIND}:%{message}'
PuppetLint.configuration.fail_on_warnings = true
PuppetLint.configuration.send('relative')
PuppetLint.configuration.send('disable_80chars') PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.send('disable_class_inherits_from_params_class') PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]
PuppetLint.configuration.send('disable_class_parameter_defaults')
PuppetLint.configuration.send('disable_documentation')
PuppetLint.configuration.send('disable_single_quote_string_with_variables')
exclude_paths = %w(
pkg/**/*
vendor/**/*
.vendor/**/*
spec/**/*
)
PuppetLint.configuration.ignore_paths = exclude_paths
PuppetSyntax.exclude_paths = exclude_paths
desc "Validate manifests, templates, and ruby files" desc "Validate manifests, templates, and ruby files"
task :validate do task :validate do

View File

@ -5,5 +5,5 @@
# file installation # file installation
::fluentd::plugin { 'fluent-plugin-elasticsearch': ::fluentd::plugin { 'fluent-plugin-elasticsearch':
type => 'file', type => 'file',
source => 'puppet:///modules/path/to/plugin' source => 'puppet:///path/to/plugin'
} }

View File

@ -2,17 +2,9 @@
::fluentd::source { 'test': ::fluentd::source { 'test':
priority => 10, priority => 10,
config => { config => {
'type' => 'tail', 'type' => 'tail',
'format' => 'json', 'format' => 'json',
'path' => '/var/log/test-application/*.json', 'path' => '/var/log/test-application/*.json',
'parse' => { 'tag' => 'application.test'
'type' => 'regexp',
'expression' => '^(?<name>[^ ]*) (?<user>[^ ]*) (?<age>\d*)$'
},
'storage' => {
'type' => 'local',
'path' => 'test.pos'
},
'tag' => 'application.test'
} }
} }

View File

@ -1,30 +0,0 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----
Comment: Encryption subkey has been removed due to apt-key parsing bug
mQINBFhiI8wBEADThWLNd8IKPRw7Ygu3DHS4Sb/Yc6vSZSaMGJ6Wkj245jScvI+C
nG4C4rtO/8ObUj5cUpb4CyfYZX8W4tp9x+W68c4paXevG4s+X4EE3uUsgdwTnFXi
GMa57QDzR4p/JvjUjfGJ2UAr4Bfj8Q2S54LmIu6UAe82ce2B4tEHCeYSxkmVUDAZ
utfmgKoVTbnceTemU0m5ANS6IC1/53KEhgB1sKm5G/FjRJGslHWb3mf+bLrhmlkP
pA4BOKF2w3eFYH3LhWskxMS0SPM7J6aq+6LyNNqtlKL6lUS7qVjRQ6PlgFcmtG4J
tijsZI62bDn1f44DmeLY+LMS/nM0xyIx94lYumGH5EYmjUECagqMool98/+Wx79A
Thtg/1pYNzo8Z76qr0i3xLSRtsQ2Om2Rfal7VGadOrx4sqlkSaUaGI+hBc1r4tNy
tERvBEMGSf78bWDbdzxSNEW4LUDUpniNQb0DrURfWkqRa3q4WcTJr8lpQM/NmAru
owayAXQwKob+OIZ09/O69EaqVJ9MqsM3keQouSHShKvzNrppuo3D3z+Dpy05FsYw
MAiIN7auXxy+XQwCVsKF083YaDHcC0I22GReEgt43yZXQ/b/J9QNrm5nJ+3Cpso3
jJnMzubuniSOOdd3mXQ6MwgZvWgtH/nPF8oUX9VSGwqNohiKWcxQDxW7qQARAQAB
tFRUcmVhc3VyZSBEYXRhLCBJbmMgKFRyZWFzdXJlIEFnZW50IE9mZmljaWFsIFNp
Z25pbmcga2V5KSA8c3VwcG9ydEB0cmVhc3VyZS1kYXRhLmNvbT6JAjcEEwEIACEF
AlhiI8wCGwMFCwkIBwMFFQoJCAsFFgIDAQACHgECF4AACgkQkB+Rd6uXrL5GrhAA
nh82+caSu9Qu/LW256gN5UjPUFhph66ElT1OVyAR2FoOmz2pJH3t8YYD5cUV2W6/
xqJDmjl+vnL2HBgxjHKRCo2K3hrq6z4LoU7SpWDI1cZ03lkjh1yNx13S+9JvZNlp
jit0WRIspke0n0vWSpNo4nh19Yg3EA1c+vGeHnmlYo6xwRHu6XOhhCwywtFRGC3a
iMJzAV4N69ZU6P5VZZkC6LjYYQtF4aI10COLZ4AcObH2htGAZTj2KlZfdJHmr+Oa
wY57giUYz7OF45LLCuqe+VwpGp2d3UK/MtCnXRLi5InMVJKDvyt18MzRDFuyA27e
WSt+JumVqhEjawh3hmdzIS1cHKmv19gdeE8On2i2Lf8lyek8fsB/YPgADAmp2oSe
cjLu0ocGbgxRjuCR29+6IG+DiUDFCkqFZNdLiGVqzjpjpYHaPhVe77ciwA8TCPru
3dh5t/qv2HglSd7lj95IApZBtny5AK8NS4qtaOeZbBbbDRuOPL0c7fU3bqyIPy57
zvdYi3KdjWZVCawcAmk3ILP83eFSivCRPRoyCqO+HX8U647BBWvlFuEbPa+Y1sgE
12MEF/Y6VVJh3Ptw+h/qKRbra4LdA+5Y30q/9l6WGgbO/4h3NKmGeVCrAFvS3h92
fS0ABYD1nAP7fSNS9RfYIqfBXtJem+tJ14YKJwWiAYU=
=TPyg
-----END PGP PUBLIC KEY BLOCK-----

View File

@ -8,20 +8,11 @@ Puppet::Type.type(:package).provide :fluentd_gem, :parent => :gem do
not a valid URL, it will be interpreted as the path to a local gem file. If not a valid URL, it will be interpreted as the path to a local gem file. If
source is not present at all, the gem will be installed from the default gem source is not present at all, the gem will be installed from the default gem
repositories." repositories."
confine :exists => "/opt/td-agent/bin/gem" confine :exists => "/opt/td-agent/embedded/bin/gem"
has_feature :versionable, :install_options has_feature :versionable, :install_options
commands :gemcmd => "/opt/td-agent/bin/gem" commands :gemcmd => "/opt/td-agent/embedded/bin/gem"
def install(useversion = true)
command = [command(:gemcmd), "install"]
command << "--no-document" << resource[:name]
output = execute(command)
# Apparently some stupid gem versions don't exit non-0 on failure
self.fail "Could not install: #{output.chomp}" if output.include?("ERROR")
end
def uninstall def uninstall
command = [command(:gemcmd), "uninstall"] command = [command(:gemcmd), "uninstall"]

View File

@ -11,11 +11,9 @@ class fluentd::config inherits fluentd {
} }
file { $::fluentd::conf_dir: file { $::fluentd::conf_dir:
ensure => 'directory', ensure => 'directory',
recurse => $::fluentd::conf_dir_manage, owner => $::fluentd::user_name,
purge => $::fluentd::conf_dir_manage, group => $::fluentd::user_group,
owner => $::fluentd::user_name, mode => '0750',
group => $::fluentd::user_group,
mode => '0750',
} }
} }

View File

@ -28,8 +28,8 @@ define fluentd::config::file (
file { $config_path: file { $config_path:
ensure => $ensure, ensure => $ensure,
content => $content, content => $content,
owner => $::fluentd::user_name, owner => 'td-agent',
group => $::fluentd::user_group, group => 'td-agent',
mode => '0644', mode => '0644',
notify => Class['Fluentd::Service'], notify => Class['Fluentd::Service'],
} }

View File

@ -35,19 +35,26 @@
# Copyright # Copyright
# --------- # ---------
# #
# Copyright 2015 wywy, unless otherwise noted. # Copyright 2015 wywy GmbH, unless otherwise noted.
# #
define fluentd::filter ( define fluentd::filter (
Enum['present', 'absent'] $ensure = present, $ensure = present,
Integer $priority = 20, $priority = 20,
String $pattern = '**', $pattern = '**',
Hash $config = {}, $config = {},
) { ) {
# parameter validation
if ! ($ensure in [ 'present', 'absent' ]) {
fail('ensure parameter must be present or absent')
}
validate_integer($priority)
validate_string($pattern)
validate_hash($config)
fluentd::config::file { "filter-${title}": fluentd::config::file { "filter-${title}":
ensure => $ensure, ensure => $ensure,
priority => $priority, priority => $priority,
content => template( 'fluentd/filter.erb'), content => template( 'fluentd/filter.erb'),
} }
} }

View File

@ -8,9 +8,6 @@
# [*repo_manage*] # [*repo_manage*]
# Include repository to install recent fluentd (td-agent) from # Include repository to install recent fluentd (td-agent) from
# Default: 'true' # Default: 'true'
# [*repo_version*]
# The major version of td-agent to install
# Default: 3
# [*package_ensure*] # [*package_ensure*]
# Package ensure # Package ensure
# Default: 'installed' # Default: 'installed'
@ -29,21 +26,9 @@
# [*service_ensure*] # [*service_ensure*]
# Service ensure # Service ensure
# Default: 'running' # Default: 'running'
# [*service_enable*] # [*service_enabled*]
# Defines if the service should be enabled # Defines if the service should be enabled
# Default: 'true' # Default: 'true'
# [*config_path*]
# Path to configuration files
# Default: '/etc/td-agent'
# [*config_dir*]
# Configuration directory name
# Default: '${config_path}/conf.d'
# [*config_file*]
# Default configuration file name
# Default: '${config_path}/td-agent.conf'
# [*conf_dir_manage*]
# Exclusively handle config files into fluentd::conf_dir. Other files not created by puppet, will be deleted
# Default: 'false'
# [*user_manage*] # [*user_manage*]
# Defines if the user should be manage, which will add the user # Defines if the user should be manage, which will add the user
# to groups defined in $user_groups. # to groups defined in $user_groups.
@ -65,28 +50,39 @@
# Copyright # Copyright
# --------- # ---------
# #
# Copyright 2015 wywy, unless otherwise noted. # Copyright 2015 wywy GmbH, unless otherwise noted.
# #
class fluentd ( class fluentd (
Boolean $repo_manage = $::fluentd::params::repo_manage, $repo_manage = $::fluentd::params::repo_manage,
Integer $repo_version = $::fluentd::params::repo_version, $package_ensure = $::fluentd::params::package_ensure,
String $package_ensure = $::fluentd::params::package_ensure, $package_name = $::fluentd::params::package_name,
String $package_name = $::fluentd::params::package_name, $package_install_options = $::fluentd::params::package_install_options,
Array $package_install_options = $::fluentd::params::package_install_options, $service_manage = $::fluentd::params::service_manage,
Boolean $service_manage = $::fluentd::params::service_manage, $service_name = $::fluentd::params::service_name,
String $service_name = $::fluentd::params::service_name, $service_ensure = $::fluentd::params::service_ensure,
Enum['running', 'stopped'] $service_ensure = $::fluentd::params::service_ensure, $service_enable = $::fluentd::params::service_enable,
Boolean $service_enable = $::fluentd::params::service_enable, $config_path = $::fluentd::params::config_path,
String $config_path = $::fluentd::params::config_path, $conf_dir = $::fluentd::params::conf_dir,
String $conf_dir = $::fluentd::params::conf_dir, $config_file = $::fluentd::params::config_file,
String $config_file = $::fluentd::params::config_file, $user_manage = $::fluentd::params::user_manage,
Boolean $conf_dir_manage = $::fluentd::params::conf_dir_manage, $user_name = $::fluentd::params::user_name,
Boolean $user_manage = $::fluentd::params::user_manage, $user_group = $::fluentd::params::user_group,
String $user_name = $::fluentd::params::user_name, $user_groups = $::fluentd::params::user_groups,
String $user_group = $::fluentd::params::user_group,
Array $user_groups = $::fluentd::params::user_groups,
) inherits fluentd::params { ) inherits fluentd::params {
# parameter validation
validate_bool($repo_manage)
validate_string($package_ensure)
validate_string($package_name)
validate_array($package_install_options)
validate_bool($service_manage)
validate_string($service_name)
validate_bool($service_enable)
if ! ($service_ensure in [ 'running', 'stopped' ]) {
fail('service_ensure parameter must be running or stopped')
}
# class calls # class calls
include '::fluentd::repo' include '::fluentd::repo'
include '::fluentd::install' include '::fluentd::install'
@ -94,16 +90,10 @@ class fluentd (
include '::fluentd::config' include '::fluentd::config'
include '::fluentd::service' include '::fluentd::service'
# Realize any virtual configurations
Fluentd::Plugin <| |>
Fluentd::Source <| |>
Fluentd::Filter <| |>
Fluentd::Match <| |>
# dependencies # dependencies
Class['::Fluentd::Repo'] Class['::Fluentd::Repo'] ->
-> Class['::Fluentd::Install'] Class['::Fluentd::Install'] ->
-> Class['::Fluentd::User'] Class['::Fluentd::User'] ->
-> Class['::Fluentd::Config'] Class['::Fluentd::Config'] ->
-> Class['::Fluentd::Service'] Class['::Fluentd::Service']
} }

View File

@ -40,19 +40,26 @@
# Copyright # Copyright
# --------- # ---------
# #
# Copyright 2015 wywy, unless otherwise noted. # Copyright 2015 wywy GmbH, unless otherwise noted.
# #
define fluentd::match ( define fluentd::match (
Enum['present', 'absent'] $ensure = present, $ensure = present,
Integer $priority = 30, $priority = 30,
String $pattern = '**', $pattern = '**',
Hash $config = {}, $config = {},
) { ) {
# parameter validation
if ! ($ensure in [ 'present', 'absent' ]) {
fail('ensure parameter must be present or absent')
}
validate_integer($priority)
validate_string($pattern)
validate_hash($config)
fluentd::config::file { "match-${title}": fluentd::config::file { "match-${title}":
ensure => $ensure, ensure => $ensure,
priority => $priority, priority => $priority,
content => template( 'fluentd/match.erb'), content => template( 'fluentd/match.erb'),
} }
} }

View File

@ -11,15 +11,12 @@ class fluentd::params {
# config params # config params
$config_path = '/etc/td-agent' $config_path = '/etc/td-agent'
$conf_dir = "${config_path}/conf.d" $conf_dir = "${config_path}/conf.d"
$conf_dir_manage = false
$config_file = "${config_path}/td-agent.conf" $config_file = "${config_path}/td-agent.conf"
# user params # user params
$user_manage = true $user_manage = true
$user_name = 'td-agent' $user_name = 'td-agent'
$user_group = 'td-agent' $user_group = 'td-agent'
$user_groups = ['adm'] $user_groups = ['adm']
# repo params
$repo_version = 4
case $::osfamily { case $::osfamily {
'Debian': { 'Debian': {

View File

@ -23,14 +23,19 @@
# Copyright # Copyright
# --------- # ---------
# #
# Copyright 2015 wywy, unless otherwise noted. # Copyright 2015 wywy GmbH, unless otherwise noted.
# #
define fluentd::plugin ( define fluentd::plugin (
String $ensure = present, $ensure = present,
String $type = 'gem', $type = 'gem',
Optional[String] $source = undef, $source = undef,
) { ) {
# parameter validation
if ! ($ensure in [ 'present', 'absent' ]) {
fail('ensure parameter must be present or absent')
}
case $type { case $type {
'gem': { 'gem': {
fluentd::plugin::gem { $name: fluentd::plugin::gem { $name:
@ -39,10 +44,7 @@ define fluentd::plugin (
} }
} }
'file': { 'file': {
# parameter validation validate_string($source)
if ! ($ensure in [ 'present', 'absent' ]) {
fail('ensure parameter must be present or absent')
}
fluentd::plugin::file { $name: fluentd::plugin::file { $name:
ensure => $ensure, ensure => $ensure,

View File

@ -4,7 +4,7 @@ class fluentd::repo inherits fluentd {
if $::fluentd::repo_manage { if $::fluentd::repo_manage {
case $::osfamily { case $::osfamily {
'Debian': { 'Debian': {
contain ::fluentd::repo::apt include ::fluentd::repo::apt
} }
'RedHat': { 'RedHat': {
include ::fluentd::repo::yum include ::fluentd::repo::yum

View File

@ -2,13 +2,13 @@
# #
class fluentd::repo::apt ( class fluentd::repo::apt (
$ensure = 'present', $ensure = 'present',
$location = downcase("http://packages.treasuredata.com/${::fluentd::repo_version}/${::lsbdistid}/${::lsbdistcodename}"), $location = downcase("http://packages.treasuredata.com/2/${::lsbdistid}/${::lsbdistcodename}"),
$release = $::lsbdistcodename, $release = $::lsbdistcodename,
$repos = 'contrib', $repos = 'contrib',
$architecture = $::architecture, $architecture = $::architecture,
$key = { $key = {
'id' => 'BEE682289B2217F45AF4CC3F901F9177AB97ACBE', 'id' => 'C901622B5EC4AF820C38AB861093DB45A12E206F',
'content' => file('fluentd/GPG-KEY-td-agent'), 'source' => 'http://packages.treasuredata.com/GPG-KEY-td-agent'
}, },
$include = { $include = {
'src' => false, 'src' => false,
@ -27,6 +27,4 @@ class fluentd::repo::apt (
key => $key, key => $key,
include => $include, include => $include,
} }
Class['apt::update'] -> Package['fluentd']
} }

View File

@ -3,7 +3,7 @@
class fluentd::repo::yum ( class fluentd::repo::yum (
$ensure = 'present', $ensure = 'present',
$descr = 'TreasureData', $descr = 'TreasureData',
$baseurl = "https://packages.treasuredata.com/${::fluentd::repo_version}/redhat/\$releasever/\$basearch", $baseurl = 'https://packages.treasuredata.com/2/redhat/$releasever/$basearch',
$enabled = '1', $enabled = '1',
$gpgcheck = '1', $gpgcheck = '1',
$gpgkey = 'https://packages.treasuredata.com/GPG-KEY-td-agent', $gpgkey = 'https://packages.treasuredata.com/GPG-KEY-td-agent',
@ -23,12 +23,4 @@ class fluentd::repo::yum (
path => '/bin:/usr/bin/', path => '/bin:/usr/bin/',
refreshonly => true, refreshonly => true,
} }
exec { 'remove old GPG key':
command => 'rpm -e --allmatches gpg-pubkey-a12e206f-*',
path => '/bin:/usr/bin/',
onlyif => 'rpm -qi gpg-pubkey-a12e206f-*',
notify => Exec['add GPG key'],
}
} }

View File

@ -31,18 +31,20 @@
# Copyright # Copyright
# --------- # ---------
# #
# Copyright 2015 wywy, unless otherwise noted. # Copyright 2015 wywy GmbH, unless otherwise noted.
# #
define fluentd::source ( define fluentd::source (
String $ensure = present, $ensure = present,
Integer $priority = 10, $priority = 10,
Hash $config = {}, $config = {},
) { ) {
# parameter validation # parameter validation
if ! ($ensure in [ 'present', 'absent' ]) { if ! ($ensure in [ 'present', 'absent' ]) {
fail('ensure parameter must be present or absent') fail('ensure parameter must be present or absent')
} }
validate_integer($priority)
validate_hash($config)
fluentd::config::file { "source-${title}": fluentd::config::file { "source-${title}":
ensure => $ensure, ensure => $ensure,

View File

@ -1,17 +1,17 @@
{ {
"name": "pilchkinstein-fluentd", "name": "wywygmbh-fluentd",
"version": "1.0.0", "version": "0.5.0",
"author": "pilchkinstein-gtv", "author": "wywy GmbH",
"summary": "Generic module for fluentd (td-agent).", "summary": "Generic module for fluentd (td-agent).",
"license": "Apache-2.0", "license": "Apache-2.0",
"source": "https://github.com/pilchkinstein-gtv/puppet-fluentd", "source": "https://github.com/wywygmbh/puppet-fluentd",
"project_page": "https://github.com/pilchkinstein-gtv/puppet-fluentd", "project_page": "https://github.com/wywygmbh/puppet-fluentd",
"issues_url": "https://github.com/pilchkinstein-gtv/puppet-fluentd/issues", "issues_url": "https://github.com/wywygmbh/puppet-fluentd/issues",
"tags": ["fluentd", "td-agent"], "tags": ["fluentd", "td-agent"],
"operatingsystem_support": [ "operatingsystem_support": [
{ {
"operatingsystem": "Ubuntu", "operatingsystem": "Ubuntu",
"operatingsystemrelease": [ "16.04", "14.04" ] "operatingsystemrelease": [ "14.04", "12.04" ]
}, },
{ {
"operatingsystem": "Debian", "operatingsystem": "Debian",
@ -24,7 +24,7 @@
], ],
"dependencies": [ "dependencies": [
{ "name": "puppetlabs/stdlib", "version_requirement": ">= 4.6.0 < 5.0.0" }, { "name": "puppetlabs/stdlib", "version_requirement": ">= 4.6.0 < 5.0.0" },
{ "name": "puppetlabs/apt", "version_requirement": ">= 4.0.0" } { "name": "puppetlabs/apt", "version_requirement": ">= 2.0.0 < 3.0.0" }
], ],
"data_provider": null "data_provider": null
} }

View File

@ -1,31 +1,45 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::config', :type => :class do describe 'fluentd::config', :type => :class do
on_supported_os.each do |os, facts| shared_examples 'when called with no parameters' do
context "on #{os}" do it {
let :facts do should contain_file('/etc/td-agent/td-agent.conf').with({
facts 'ensure' => 'file',
end 'owner' => 'root',
'group' => 'root',
'source' => 'puppet:///modules/fluentd/td-agent.conf',
'notify' => 'Class[Fluentd::Service]'
})
describe 'when called with no parameters' do should contain_file('/etc/td-agent/conf.d').with({
'ensure' => 'directory',
'owner' => 'td-agent',
'group' => 'td-agent',
'mode' => '0750'
})
}
end
it { context 'when osfamily is Debian' do
should contain_file('/etc/td-agent/td-agent.conf').with({ let(:facts) {
'ensure' => 'file', {
'owner' => 'root', :osfamily => 'Debian',
'group' => 'root', :lsbdistid => 'Ubuntu',
'source' => 'puppet:///modules/fluentd/td-agent.conf', :operatingsystem => 'Ubuntu',
'notify' => 'Class[Fluentd::Service]' :lsbdistcodename => 'precise',
}) }
}
should contain_file('/etc/td-agent/conf.d').with({ include_examples 'when called with no parameters'
'ensure' => 'directory', end
'owner' => 'td-agent',
'group' => 'td-agent', context 'when osfamily is RedHat' do
'mode' => '0750' let(:facts) {
}) {
} :osfamily => 'RedHat',
end }
end }
include_examples 'when called with no parameters'
end end
end end

View File

@ -1,21 +1,37 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::install', :type => :class do describe 'fluentd::install', :type => :class do
on_supported_os.each do |os, facts|
context "on #{os}" do
let :facts do
facts
end
describe 'when called with no parameters' do shared_examples 'when called with no parameters' do
it { it {
should contain_package('fluentd').with({ should contain_package('fluentd').with({
'ensure' => 'installed', 'ensure' => 'installed',
'name' => 'td-agent', 'name' => 'td-agent',
'install_options' => [] 'install_options' => []
}) })
} }
end
end
end end
context 'when osfamily is Debian' do
let(:facts) {
{
:osfamily => 'Debian',
:lsbdistid => 'Ubuntu',
:operatingsystem => 'Ubuntu',
:lsbdistcodename => 'precise',
}
}
include_examples 'when called with no parameters'
end
context 'when osfamily is RedHat' do
let(:facts) {
{
:osfamily => 'RedHat',
}
}
include_examples 'when called with no parameters'
end
end end

View File

@ -1,81 +1,34 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::repo::apt', :type => :class do describe 'fluentd::repo::apt', :type => :class do
on_supported_os.each do |os, facts| let(:facts) {
context "on #{os}" do {
let :facts do :osfamily => 'Debian',
facts :lsbdistid => 'Ubuntu',
end :operatingsystem => 'Ubuntu',
:lsbdistcodename => 'precise',
:architecture => 'amd64',
}
}
case facts[:osfamily] describe 'when called with no parameters on Ubuntu' do
when 'Debian' it {
it { should contain_class('apt')
should contain_class('apt') should contain_apt__source('treasure-data').with({
should contain_apt__source('treasure-data').with({ 'ensure' => 'present',
'ensure' => 'present', 'location' => 'http://packages.treasuredata.com/2/ubuntu/precise',
'repos' => 'contrib', 'release' => 'precise',
'architecture' => 'amd64', 'repos' => 'contrib',
'key' => { 'architecture' => 'amd64',
'id' => 'BEE682289B2217F45AF4CC3F901F9177AB97ACBE', 'key' => {
'source' => 'http://packages.treasuredata.com/GPG-KEY-td-agent' 'id' => 'C901622B5EC4AF820C38AB861093DB45A12E206F',
}, 'source' => 'http://packages.treasuredata.com/GPG-KEY-td-agent'
'include' => { },
'src' => false, 'include' => {
'deb' => true 'src' => false,
} 'deb' => true
})
} }
case facts[:operatingsystem] })
when 'Ubuntu' }
case facts[:lsbdistcodename]
when 'precise'
it {
should contain_apt__source('treasure-data').with({
'location' => 'http://packages.treasuredata.com/2/ubuntu/precise',
'release' => 'precise'
})
}
when 'trusty'
it {
should contain_apt__source('treasure-data').with({
'location' => 'http://packages.treasuredata.com/2/ubuntu/trusty',
'release' => 'trusty'
})
}
when 'xenial'
it {
should contain_apt__source('treasure-data').with({
'location' => 'http://packages.treasuredata.com/2/ubuntu/xenial',
'release' => 'xenial'
})
}
end
when 'Debian'
case facts[:lsbdistcodename]
when 'jessie'
it {
should contain_apt__source('treasure-data').with({
'location' => 'http://packages.treasuredata.com/2/debian/jessie',
'release' => 'jessie'
})
}
when 'squeeze'
it {
should contain_apt__source('treasure-data').with({
'location' => 'http://packages.treasuredata.com/2/debian/squeeze',
'release' => 'squeeze'
})
}
when 'wheezy'
it {
should contain_apt__source('treasure-data').with({
'location' => 'http://packages.treasuredata.com/2/debian/wheezy',
'release' => 'wheezy'
})
}
end
end
end
end
end end
end end

View File

@ -1,21 +1,29 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::repo', :type => :class do describe 'fluentd::repo', :type => :class do
on_supported_os.each do |os, facts|
context "on #{os}" do
let :facts do
facts
end
describe 'when called with no parameters' do context 'when called with no parameters on osfamily Debian' do
case facts[:osfamily] let(:facts) {
when 'Debian' {
it { is_expected.to contain_class('fluentd::repo::apt') } :osfamily => 'Debian',
when 'RedHat' :lsbdistid => 'Ubuntu',
it { is_expected.to contain_class('fluentd::repo::yum') } :operatingsystem => 'Ubuntu',
end :lsbdistcodename => 'precise',
end }
end }
it {
should contain_class('fluentd::repo::apt')
}
end
context 'when called with no parameters on osfamily RedHat' do
let(:facts) {
{
:osfamily => 'RedHat',
}
}
it {
should contain_class('fluentd::repo::yum')
}
end end
end end

View File

@ -1,32 +1,27 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::repo::yum', :type => :class do describe 'fluentd::repo::yum', :type => :class do
on_supported_os.each do |os, facts| let(:facts) {
context "on #{os}" do {
let :facts do :osfamily => 'RedHat',
facts }
end }
describe 'when called with no parameters' do describe 'when called with no parameters on RedHat' do
case facts[:osfamily] it {
when 'RedHat' should contain_yumrepo('treasure-data').with({
it { 'ensure' => 'present',
should contain_yumrepo('treasure-data').with({ 'baseurl' => 'https://packages.treasuredata.com/2/redhat/$releasever/$basearch',
'ensure' => 'present', 'descr' => 'TreasureData',
'baseurl' => 'https://packages.treasuredata.com/2/redhat/$releasever/$basearch', 'enabled' => '1',
'descr' => 'TreasureData', 'gpgcheck' => '1'
'enabled' => '1', }).that_notifies('Exec[add GPG key]')
'gpgcheck' => '1'
}).that_notifies('Exec[add GPG key]')
should contain_exec('add GPG key').with({ should contain_exec('add GPG key').with({
'command' => 'rpm --import https://packages.treasuredata.com/GPG-KEY-td-agent', 'command' => 'rpm --import https://packages.treasuredata.com/GPG-KEY-td-agent',
'path' => '/bin:/usr/bin/', 'path' => '/bin:/usr/bin/',
'refreshonly' => 'true' 'refreshonly' => 'true'
}) })
} }
end
end
end
end end
end end

View File

@ -1,23 +1,38 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::config', :type => :class do describe 'fluentd::config', :type => :class do
on_supported_os.each do |os, facts| shared_examples 'when called with no parameters' do
context "on #{os}" do it {
let :facts do should contain_service('fluentd').with({
facts 'name' => 'td-agent',
end 'ensure' => 'running',
'enable' => 'true',
'hasstatus' => 'true',
'hasrestart' => 'true'
})
}
end
describe 'when called with no parameters' do context 'when osfamily is Debian' do
it { let(:facts) {
should contain_service('fluentd').with({ {
'name' => 'td-agent', :osfamily => 'Debian',
'ensure' => 'running', :lsbdistid => 'Ubuntu',
'enable' => 'true', :operatingsystem => 'Ubuntu',
'hasstatus' => 'true', :lsbdistcodename => 'precise',
'hasrestart' => 'true' }
}) }
}
end include_examples 'when called with no parameters'
end end
context 'when osfamily is RedHat' do
let(:facts) {
{
:osfamily => 'RedHat',
}
}
include_examples 'when called with no parameters'
end end
end end

View File

@ -1,20 +1,36 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd', :type => :class do describe 'fluentd', :type => :class do
on_supported_os.each do |os, facts| shared_examples 'when called with no parameters' do
context "on #{os}" do it {
let :facts do should contain_class('fluentd::repo')
facts should contain_class('fluentd::install')
end should contain_class('fluentd::config')
should contain_class('fluentd::service')
describe 'when called with no parameters' do }
it {
should contain_class('fluentd::repo')
should contain_class('fluentd::install')
should contain_class('fluentd::config')
should contain_class('fluentd::service')
}
end
end
end end
context 'when osfamily is Debian' do
let(:facts) {
{
:osfamily => 'Debian',
:lsbdistid => 'Ubuntu',
:operatingsystem => 'Ubuntu',
:lsbdistcodename => 'precise',
}
}
include_examples 'when called with no parameters'
end
context 'when osfamily is RedHat' do
let(:facts) {
{
:osfamily => 'RedHat',
}
}
include_examples 'when called with no parameters'
end
end end

View File

@ -1,21 +1,36 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::user', :type => :class do describe 'fluentd::user', :type => :class do
on_supported_os.each do |os, facts| shared_examples 'when called with no parameters' do
context "on #{os}" do it {
let :facts do should contain_user('fluentd').with({
facts 'name' => 'td-agent',
end 'gid' => 'td-agent',
'groups' => ['adm']
})
}
end
describe 'when called with no parameters' do context 'when osfamily is Debian' do
it { let(:facts) {
should contain_user('fluentd').with({ {
'name' => 'td-agent', :osfamily => 'Debian',
'gid' => 'td-agent', :lsbdistid => 'Ubuntu',
'groups' => ['adm'] :operatingsystem => 'Ubuntu',
}) :lsbdistcodename => 'precise',
} }
end }
end
include_examples 'when called with no parameters'
end
context 'when osfamily is RedHat' do
let(:facts) {
{
:osfamily => 'RedHat',
}
}
include_examples 'when called with no parameters'
end end
end end

View File

@ -1,34 +1,39 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::filter' do describe 'fluentd::filter' do
on_supported_os.each do |os, facts| let(:facts) {
context "on #{os}" do {
let :facts do :osfamily => 'Debian',
facts :lsbdistid => 'Ubuntu',
end :operatingsystem => 'Ubuntu',
:lsbdistcodename => 'precise',
}
}
let(:pre_condition) { 'include fluentd' }
let(:pre_condition) { 'include fluentd' } context 'basic filter' do
let(:title) { 'test' }
describe 'basic filter' do let(:params) do
let(:title) { 'test' } {
let(:params) do priority: '20',
{ pattern: '*.test',
priority: 20, config: {
pattern: '*.test',
config: {
'type' => 'record_transformer', 'type' => 'record_transformer',
'record' => { 'record' => {
'hostname' => '${hostname}' 'hostname' => '${hostname}'
} }
}
} }
end }
end
it do it do
is_expected.to contain_file('/etc/td-agent/conf.d/20-filter-test.conf'). is_expected.to contain_file('/etc/td-agent/conf.d/20-filter-test.conf').
with_content(IO.read(File.join(File.dirname(__FILE__), '../fixtures/files/filter_record_transformer.conf'))) with_content(/<filter \*.test>/).
end with_content(/type record_transformer/).
end with_content(/<record>/).
with_content(/hostname \$\{hostname\}/).
with_content(/<\/record>/).
with_content(/<\/filter>/)
end end
end end
end end

View File

@ -1,71 +1,93 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::match' do describe 'fluentd::match' do
on_supported_os.each do |os, facts| let(:facts) {
context "on #{os}" do {
let :facts do :osfamily => 'Debian',
facts :lsbdistid => 'Ubuntu',
end :operatingsystem => 'Ubuntu',
:lsbdistcodename => 'precise',
}
}
let(:pre_condition) { 'include fluentd' }
let(:pre_condition) { 'include fluentd' } context 'basic match' do
let(:title) { 'test' }
describe 'basic match' do let(:params) do
let(:title) { 'test' } {
let(:params) do priority: '30',
{ pattern: '*.test',
priority: 30, config: {
pattern: '*.test', 'flush_interval' => '30s',
config: { 'type' => 'secure_forward',
'flush_interval' => '30s', 'secure' => 'yes',
'type' => 'secure_forward', 'shared_key' => 'my_shared_key',
'secure' => 'yes', 'self_hostname' => 'instance.test.com',
'shared_key' => 'my_shared_key', 'ca_cert_path' => '/path/to/ca.cert',
'self_hostname' => 'instance.test.com', 'server' => [
'ca_cert_path' => '/path/to/ca.cert', {
'server' => [ 'host' => 'test.server.com',
{ }
'host' => 'test.server.com', ]
}
]
}
} }
end }
end
it do it do
is_expected.to contain_file('/etc/td-agent/conf.d/30-match-test.conf'). is_expected.to contain_file('/etc/td-agent/conf.d/30-match-test.conf').
with_content(IO.read(File.join(File.dirname(__FILE__), '../fixtures/files/match_secure_forward.conf'))) with_content(/<match \*.test>/).
end with_content(/flush_interval 30s/).
end with_content(/type secure_forward/).
with_content(/secure yes/).
with_content(/shared_key my_shared_key/).
with_content(/self_hostname instance.test.com/).
with_content(/ca_cert_path \/path\/to\/ca.cert/).
with_content(/<server>/).
with_content(/host test.server.com/).
with_content(/<\/server>/).
with_content(/<\/match>/)
end
end
describe 'multiple store' do context 'multiple store' do
let(:title) { 'test' } let(:title) { 'test' }
let(:params) do let(:params) do
{ {
priority: 30, priority: '30',
pattern: '*.test', pattern: '*.test',
config: { config: {
'type' => 'copy', 'type' => 'copy',
'store' => [ 'store' => [
{ {
'type' => 'elasticsearch', 'type' => 'elasticsearch',
'logstashformat' => true, 'logstashformat' => true,
'hosts' => '172.20.10.17:9200', 'hosts' => '172.20.10.17:9200',
'flush_interval' => '30s', 'flush_interval' => '30s',
}, },
{ {
'type' => 'file', 'type' => 'file',
'path' => '/tmp/td-agent-debug.log', 'path' => '/tmp/td-agent-debug.log',
} }
] ]
}
} }
end }
end
it do it do
is_expected.to contain_file('/etc/td-agent/conf.d/30-match-test.conf'). is_expected.to contain_file('/etc/td-agent/conf.d/30-match-test.conf').
with_content(IO.read(File.join(File.dirname(__FILE__), '../fixtures/files/match_copy.conf'))) with_content(/<match \*.test>/).
end with_content(/type copy/).
end with_content(/<store>/).
with_content(/type elasticsearch/).
with_content(/logstashformat true/).
with_content(/hosts 172.20.10.17:9200/).
with_content(/flush_interval 30s/).
with_content(/<\/store>/).
with_content(/<store>/).
with_content(/type file/).
with_content(/path \/tmp\/td-agent-debug.log/).
with_content(/<\/store>/).
with_content(/<\/match>/)
end end
end end
end end

View File

@ -1,51 +1,51 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::plugin' do describe 'fluentd::plugin' do
on_supported_os.each do |os, facts| let(:facts) {
context "on #{os}" do {
let :facts do :osfamily => 'Debian',
facts :lsbdistid => 'Ubuntu',
end :operatingsystem => 'Ubuntu',
:lsbdistcodename => 'precise',
}
}
let(:pre_condition) { 'include fluentd' }
let(:pre_condition) { 'include fluentd' } context 'gem plugin' do
let(:title) { 'fluent-plugin-elasticsearch' }
let(:params) do
{
type: 'gem'
}
end
describe 'gem plugin' do it do
let(:title) { 'fluent-plugin-elasticsearch' } should contain_package('fluent-plugin-elasticsearch').with({
let(:params) do 'ensure' => 'present',
{ 'provider' => 'fluentd_gem',
type: 'gem' 'notify' => 'Class[Fluentd::Service]'
} })
end
it do
should contain_package('fluent-plugin-elasticsearch').with({
'ensure' => 'present',
'provider' => 'fluentd_gem',
'notify' => 'Class[Fluentd::Service]'
})
end
end
describe 'file plugin' do
let(:title) { 'fluent-plugin-test' }
let(:params) do
{
type: 'file',
source: 'puppet:///path/to/source'
}
end
it do
should contain_file('/etc/td-agent/plugin/fluent-plugin-test').with({
'ensure' => 'present',
'owner' => 'td-agent',
'group' => 'td-agent',
'mode' => '0640',
'source' => 'puppet:///path/to/source',
'notify' => 'Class[Fluentd::Service]'
})
end
end
end end
end end
end
context 'file plugin' do
let(:title) { 'fluent-plugin-test' }
let(:params) do
{
type: 'file',
source: 'puppet:///path/to/source'
}
end
it do
should contain_file('/etc/td-agent/plugin/fluent-plugin-test').with({
'ensure' => 'present',
'owner' => 'td-agent',
'group' => 'td-agent',
'mode' => '0640',
'source' => 'puppet:///path/to/source',
'notify' => 'Class[Fluentd::Service]'
})
end
end
end

View File

@ -1,41 +1,38 @@
require 'spec_helper' require 'spec_helper'
describe 'fluentd::source' do describe 'fluentd::source' do
on_supported_os.each do |os, facts| let(:facts) {
context "on #{os}" do {
let :facts do :osfamily => 'Debian',
facts :lsbdistid => 'Ubuntu',
end :operatingsystem => 'Ubuntu',
:lsbdistcodename => 'precise',
}
}
let(:pre_condition) { 'include fluentd' }
let(:pre_condition) { 'include fluentd' } context 'basic source' do
let(:title) { 'test' }
describe 'basic source' do let(:params) do
let(:title) { 'test' } {
let(:params) do priority: '10',
{ config: {
priority: 10, 'type' => 'tail',
config: { 'format' => 'json',
'type' => 'tail', 'path' => '/var/log/test-application/*.json',
'format' => 'json', 'tag' => 'application.test'
'path' => '/var/log/test-application/*.json',
'parse' => {
'type' => 'regexp',
'expression' => '^(?<name>[^ ]*) (?<user>[^ ]*) (?<age>\d*)$'
},
'storage'=> {
'type' => 'local',
'path' => 'test.pos'
},
'tag' => 'application.test'
}
} }
end }
end
it do it do
is_expected.to contain_file('/etc/td-agent/conf.d/10-source-test.conf'). is_expected.to contain_file('/etc/td-agent/conf.d/10-source-test.conf').
with_content(IO.read(File.join(File.dirname(__FILE__), '../fixtures/files/source_tail.conf'))) with_content(/<source>/).
end with_content(/type tail/).
end with_content(/format json/).
with_content(/path \/var\/log\/test-application\/\*.json/).
with_content(/tag application.test/).
with_content(/<\/source>/)
end end
end end
end end

View File

@ -1,6 +0,0 @@
<filter *.test>
type record_transformer
<record>
hostname ${hostname}
</record>
</filter>

View File

@ -1,13 +0,0 @@
<match *.test>
type copy
<store>
type elasticsearch
logstashformat true
hosts 172.20.10.17:9200
flush_interval 30s
</store>
<store>
type file
path /tmp/td-agent-debug.log
</store>
</match>

View File

@ -1,11 +0,0 @@
<match *.test>
flush_interval 30s
type secure_forward
secure yes
shared_key my_shared_key
self_hostname instance.test.com
ca_cert_path /path/to/ca.cert
<server>
host test.server.com
</server>
</match>

View File

@ -1,14 +0,0 @@
<source>
type tail
format json
path /var/log/test-application/*.json
<parse>
type regexp
expression ^(?<name>[^ ]*) (?<user>[^ ]*) (?<age>\d*)$
</parse>
<storage>
type local
path test.pos
</storage>
tag application.test
</source>

View File

@ -1,3 +1 @@
require 'puppetlabs_spec_helper/module_spec_helper' require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts'
include RspecPuppetFacts

View File

@ -1,13 +1,13 @@
<filter <%= @pattern %>> <filter <%= @pattern %>>
<% @config.each do |key, val| -%> <% @config.each do |key, val| -%>
<%- if val.is_a?( Hash ) -%> <%- if val.is_a?( Hash ) -%>
<<%= key -%>> <<%= key -%>>
<%- val.each do |key2, val2| -%> <%- val.each do |key, val| -%>
<%= key2 -%> <%= val2 %> <%= key -%> <%= val %>
<%- end -%> <%- end -%>
</<%= key %>> </<%= key %>>
<%- else -%> <%- else -%>
<%= key -%> <%= val %> <%= key -%> <%= val %>
<%- end -%> <%- end -%>
<% end -%> <% end -%>
</filter> </filter>

View File

@ -1,41 +1,39 @@
<match <%= @pattern %>> <match <%= @pattern %>>
<% @config.each do |key, val| -%> <% @config.each do |key, val| -%>
<%- if key == 'buffer_chunk_keys'; next; end-%> <%- if val.is_a?( Hash ) -%>
<%- if val.is_a?( Hash ) -%> <<%= key -%>>
<<%= key -%><%- if key == 'buffer' && !@config['buffer_chunk_keys'].nil? -%> <%= @config['buffer_chunk_keys'] -%><%- end -%>> <%- val.each do |key, val| -%>
<%- val.each do |key, val| -%> <%= key -%> <%= val %>
<%= key -%> <%= val %> <%- end -%>
<%- end -%> </<%= key %>>
</<%= key %>> <%- elsif val.is_a?( Array ) -%>
<%- elsif val.is_a?( Array ) -%> <%- val.each do |k, v| -%>
<%- val.each do |k, v| -%> <<%= key -%>>
<<%= key -%>> <%- if k.is_a?( Hash ) -%>
<%- if k.is_a?( Hash ) -%> <%- k.each do |x, y| -%>
<%- k.each do |x, y| -%> <%- if y.is_a?( Array ) -%>
<%- if y.is_a?( Array ) -%> <%- y.each do |a, b| -%>
<%- y.each do |a, b| -%> <<%= x -%>>
<<%= x -%><%- if x == 'buffer' && !k['buffer_chunk_keys'].nil? -%> <%= k['buffer_chunk_keys'] -%><%- end -%>> <%- if a.is_a?( Hash ) -%>
<%- if a.is_a?( Hash ) -%> <%- a.each do |c, d| -%>
<%- a.each do |c, d| -%> <%= c -%> <%= d %>
<%= c -%> <%= d %> <%- end -%>
<%- end -%> <%- else -%>
<%- else -%> <%= a -%> <%= b %>
<%= a -%> <%= b %> <%- end -%>
<%- end -%> </<%= x %>>
</<%= x %>> <%- end -%>
<%- end -%> <%- else -%>
<%= x -%> <%= y %>
<%- end -%>
<%- end -%>
<%- else -%>
<%= k -%> <%= v %>
<%- end -%>
</<%= key %>>
<%- end -%>
<%- else -%> <%- else -%>
<%- if x == 'buffer_chunk_keys'; next; end -%> <%= key -%> <%= val %>
<%= x -%> <%= y %>
<%- end -%> <%- end -%>
<%- end -%>
<%- else -%>
<%= k -%> <%= v %>
<%- end -%>
</<%= key %>>
<%- end -%>
<%- else -%>
<%= key -%> <%= val %>
<%- end -%>
<% end -%> <% end -%>
</match> </match>

View File

@ -1,13 +1,5 @@
<source> <source>
<% @config.each do |key, val| -%> <% @config.each do |key, val| -%>
<%- if val.is_a?( Hash ) -%>
<<%= key -%>>
<%- val.each do |key, val| -%>
<%= key -%> <%= val %> <%= key -%> <%= val %>
<%- end -%>
</<%= key %>>
<%- else -%>
<%= key -%> <%= val %>
<%- end -%>
<% end -%> <% end -%>
</source> </source>