Skip to content

Commit

Permalink
Merge pull request #853 from mrunge/memcached_address
Browse files Browse the repository at this point in the history
Add address field to memcached plugin
  • Loading branch information
juniorsysadmin authored Oct 20, 2018
2 parents a16f085 + 4ce93c0 commit 9624672
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
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>
<% @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

0 comments on commit 9624672

Please sign in to comment.