Skip to content

Commit

Permalink
Allow custom Properties and Meta to be defined
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrik authored and bastelfreak committed Feb 8, 2020
1 parent 4612c19 commit dc15b06
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1976,6 +1976,12 @@ class { 'collectd::plugin::write_kafka':
kafka_port => 9092,
topics => {
'mytopic' => { 'format' => 'JSON' },
},
properties => {
'myproperty' => { 'myvalue' },
},
meta => {
'mymeta' => { 'myvalue' },
}
}
```
Expand Down
2 changes: 2 additions & 0 deletions manifests/plugin/write_kafka.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
Array[String] $kafka_hosts = ['localhost:9092'],
$kafka_port = 9092,
Hash $topics = {},
Hash $properties = {},
Hash $meta = {},
) {

include collectd
Expand Down
4 changes: 3 additions & 1 deletion spec/classes/collectd_plugin_write_kafka_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
options = os_specific_options(facts)
context ':ensure => present and :kafka_host => \'myhost\'' do
let :params do
{ kafka_host: 'myhost', kafka_port: '9092', topics: { 'my-topic' => { 'format' => 'JSON' } } }
{ kafka_host: 'myhost', kafka_port: '9092', topics: { 'my-topic' => { 'format' => 'JSON' } }, properties: { 'my-property' => 'my-value' }, meta: { 'my-meta' => 'my-value' } }
end

it "Will create #{options[:plugin_conf_dir]}/10-write_kafka.conf" do
is_expected.to contain_file('write_kafka.load').with(ensure: 'present')
is_expected.to contain_file('write_kafka.load').with(path: "#{options[:plugin_conf_dir]}/10-write_kafka.conf")
is_expected.to contain_file('write_kafka.load').with(content: %r{Property "metadata.broker.list" "myhost:9092"})
is_expected.to contain_file('write_kafka.load').with(content: %r{Property "my-property" "my-value"})
is_expected.to contain_file('write_kafka.load').with(content: %r{Topic "my-topic"})
is_expected.to contain_file('write_kafka.load').with(content: %r{Format "JSON"})
is_expected.to contain_file('write_kafka.load').with(content: %r{Meta "my-meta" "my-value"})
end
end

Expand Down
6 changes: 6 additions & 0 deletions templates/plugin/write_kafka.conf.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
LoadPlugin "write_kafka"
<Plugin write_kafka>
Property "metadata.broker.list" "<%= @kafka_broker %>"
<% @properties.each do |name,value| -%>
Property "<%= name %>" "<%= value %>"
<% end -%>
<% @topics.each do |name,values| -%>
<Topic "<%= name %>">
<% if values['format'] -%>
Format "<%= values['format'] %>"
<% end -%>
</Topic>
<% end -%>
<% @meta.each do |name,value| -%>
Meta "<%= name %>" "<%= value %>"
<% end -%>
</Plugin>

0 comments on commit dc15b06

Please sign in to comment.