1
0
mirror of https://github.com/krislamo/puppet-fluentd synced 2024-09-19 20:20:35 +00:00

allow repeating keys in match rules

extends the match template, yes, its not pretty
readable, to support array definitions for
defining multiple server or stores.
This commit is contained in:
Jan Krause 2015-12-11 10:21:27 +01:00
parent b5d8088d31
commit 88f021de43
5 changed files with 145 additions and 16 deletions

View File

@ -14,6 +14,7 @@
* [Source](#source)
* [Filter](#filter)
* [Match](#match)
* [Match Store](#match-store)
* [Plugin Installation](#plugin-installation)
* [Requirements](#requirements)
1. [Limitations - OS compatibility, etc.](#limitations)
@ -97,9 +98,9 @@ include '::fluentd'
'shared_key' => 'my_shared_key',
'self_hostname' => 'instance.test.com',
'ca_cert_path' => '/path/to/ca.cert',
'servers' => {
'host' => 'test.server.com'
}
'server' => [{
'host' => 'test.server.com',
}]
}
}
```
@ -113,9 +114,48 @@ include '::fluentd'
shared_key my_shared_key
self_hostname instance.test.com
ca_cert_path /path/to/ca.cert
<servers>
<server>
host test.server.com
</servers>
</server>
</match>
```
### Match Store
```puppet
::fluentd::match { 'test':
priority => 30,
pattern => '*.test',
config: {
'type' => 'copy',
'store' => [
{
'type' => 'elasticsearch',
'logstashformat' => true,
'hosts' => '172.20.10.17:9200',
'flush_interval' => '30s',
},
{
'type' => 'file',
'path' => '/tmp/td-agent-debug.log',
}
]
}
}
```
**creates:**
```
/etc/td-agent/conf.d/30-match-test.conf
<match *.test>
type copy
<store>
type elasticsearch
logstash_format true
hosts 172.20.10.17:9200
flush_interval 30s
</store>
<store>
type file
path /tmp/crs
</store>
</match>
```

View File

@ -9,8 +9,27 @@
'shared_key' => 'my_shared_key',
'self_hostname' => 'instance.test.com',
'ca_cert_path' => '/path/to/ca.cert',
'servers' => {
'host' => 'test.server.com'
}
'server' => [{
'host' => 'test.server.com',
}]
}
}
::fluentd::match { 'test':
priority => 30,
pattern => '*.test',
config => {
'type' => 'copy',
'store' => [{
'type' => 'elasticsearch',
'logstashformat' => true,
'hosts' => '172.20.10.17:9200',
'flush_interval' => '30s',
},
{
'type' => 'file',
'path' => '/tmp/td-agent-debug.log',
}
]
}
}

View File

@ -31,9 +31,9 @@
# 'shared_key' => 'my_shared_key',
# 'self_hostname' => 'instance.test.com',
# 'ca_cert_path' => '/path/to/ca.cert',
# 'servers' => {
# 'server' => [{
# 'host' => 'test.server.com'
# }
# }]
# }
# }
#

View File

@ -24,9 +24,11 @@ describe 'fluentd::match' do
'shared_key' => 'my_shared_key',
'self_hostname' => 'instance.test.com',
'ca_cert_path' => '/path/to/ca.cert',
'servers' => {
'host' => 'test.server.com'
}
'server' => [
{
'host' => 'test.server.com',
}
]
}
}
end
@ -40,10 +42,52 @@ describe 'fluentd::match' do
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(/<servers>/).
with_content(/<server>/).
with_content(/host test.server.com/).
with_content(/<\/servers>/).
with_content(/<\/server>/).
with_content(/<\/match>/)
end
end
end
context 'multiple store' do
let(:title) { 'test' }
let(:params) do
{
priority: '30',
pattern: '*.test',
config: {
'type' => 'copy',
'store' => [
{
'type' => 'elasticsearch',
'logstashformat' => true,
'hosts' => '172.20.10.17:9200',
'flush_interval' => '30s',
},
{
'type' => 'file',
'path' => '/tmp/td-agent-debug.log',
}
]
}
}
end
it do
is_expected.to contain_file('/etc/td-agent/conf.d/30-match-test.conf').
with_content(/<match \*.test>/).
with_content(/type copy/).
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

View File

@ -6,6 +6,32 @@
<%= key -%> <%= val %>
<%- end -%>
</<%= key %>>
<%- elsif val.is_a?( Array ) -%>
<%- val.each do |k, v| -%>
<<%= key -%>>
<%- if k.is_a?( Hash ) -%>
<%- k.each do |x, y| -%>
<%- if y.is_a?( Array ) -%>
<%- y.each do |a, b| -%>
<<%= x -%>>
<%- if a.is_a?( Hash ) -%>
<%- a.each do |c, d| -%>
<%= c -%> <%= d %>
<%- end -%>
<%- else -%>
<%= a -%> <%= b %>
<%- end -%>
</<%= x %>>
<%- end -%>
<%- else -%>
<%= x -%> <%= y %>
<%- end -%>
<%- end -%>
<%- else -%>
<%= k -%> <%= v %>
<%- end -%>
</<%= key %>>
<%- end -%>
<%- else -%>
<%= key -%> <%= val %>
<%- end -%>