Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add address field to memcached plugin #853

Merged
merged 1 commit into from
Oct 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions examples/plugins/memcached.pp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
include ::collectd

class { '::collectd::plugin::memcached':
instances => {
'default' => {
'host' => '192.168.122.1',
'port' => '11211',
instances => {
'default' => {
'host' => 'localhost',
'address' => '127.0.0.1',
'port' => '11211',
},
},
}
8 changes: 7 additions & 1 deletion manifests/plugin/memcached.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# https://collectd.org/wiki/index.php/Plugin:memcached
class collectd::plugin::memcached (
$ensure = 'present',
Hash $instances = {'default' => {'host' => '127.0.0.1', 'port' => 11211 } },
Hash $instances = {
'default' => {
'host' => 'localhost',
'address' => '127.0.0.1',
'port' => 11211,
},
},
$interval = undef,
) {

Expand Down
29 changes: 23 additions & 6 deletions spec/classes/collectd_plugin_memcached_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@

options = os_specific_options(facts)

context ':ensure => present, default host and port' do
context ':ensure => present, default host, address, and port' do
it "Will create #{options[:plugin_conf_dir]}/memcached.conf" do
content = <<EOS
<Instance "default">
Host "localhost"
Address "127.0.0.1"
Port 11211
</Instance>
EOS
is_expected.to contain_file('memcached.load').with(
ensure: 'present',
path: "#{options[:plugin_conf_dir]}/10-memcached.conf",
content: %r{Host "127.0.0.1"\n.+Port 11211}
content: %r{#{content}}
)
end
end
Expand All @@ -24,12 +31,17 @@
{
'instances' => {
'sessions1' => {
'host' => '127.0.0.1',
'host' => 'localhost',
'address' => '127.0.0.1',
'port' => '11211'
},
'cache1' => {
'host' => '127.0.0.1',
'host' => 'localhost',
'port' => '11212'
},
'cache3' => {
'address' => '127.0.0.1',
'port' => '11213'
}
}
}
Expand All @@ -38,13 +50,18 @@
it "Will create #{options[:plugin_conf_dir]}/memcached.conf" do
content = <<EOS
<Instance "sessions1">
Host "127.0.0.1"
Host "localhost"
Address "127.0.0.1"
Port 11211
</Instance>
<Instance "cache1">
Host "127.0.0.1"
Host "localhost"
Port 11212
</Instance>
<Instance "cache3">
Address "127.0.0.1"
Port 11213
</Instance>
EOS
is_expected.to contain_file('memcached.load').with(
ensure: 'present',
Expand Down
9 changes: 8 additions & 1 deletion templates/plugin/memcached.conf.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<Plugin memcached>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @mrunge, are you interested in turning this into an epp template?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrunge We prefer epp for new templates going forward, but will merge this for now.

<% @instances.each do |name,values| -%>
<Instance "<%= name %>">
<% if values['host'] and values['port'] -%>
<% if values['host'] or values['address'] or values['port'] -%>
<%- if values['host'] -%>
Host "<%= values['host'] %>"
<%- end -%>
<%- if values['address'] -%>
Address "<%= values['address'] %>"
<%- end -%>
<%- if values['port'] -%>
Port <%= values['port'] %>
<%- end -%>
<% elsif values['socket'] -%>
Socket "<%= values['socket'] %>"
<% end -%>
Expand Down