Skip to content

Commit

Permalink
add server parameter on collectd::plugin::network::server
Browse files Browse the repository at this point in the history
This feature include the possibility to add a specific title on
`collectd::plugin::network::server` for the configuration file name. The
server should be define with the `server` option.
  • Loading branch information
fe80 committed Mar 28, 2022
1 parent 12791f3 commit 4943084
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions manifests/plugin/network/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Optional[String] $interface = undef,
Optional[Boolean] $forward = undef,
Optional[Integer[1]] $resolveinterval = undef,
String[1] $server = $name,
) {
include collectd
include collectd::plugin::network
Expand Down
17 changes: 16 additions & 1 deletion spec/defines/collectd_plugin_network_server_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'collectd::plugin::network::server', type: :define do
on_supported_os(baseline_os_hash).each do |os, facts|
context "on #{os} " do
context "on #{os}" do
let :facts do
facts
end
Expand Down Expand Up @@ -41,6 +43,19 @@
is_expected.to contain_file("#{options[:plugin_conf_dir]}/network-server-node1.conf").with(ensure: 'absent')
end
end

context 'with specifique title' do
let(:title) { 'eatapples' }
let :params do
{ server: '10.0.0.1', port: 1234 }
end

it do
is_expected.to contain_file(
"#{options[:plugin_conf_dir]}/network-server-eatapples.conf"
).with_content(%r{<Server "10\.0\.0\.1" "1234">\n})
end
end
end
end
end
4 changes: 2 additions & 2 deletions templates/plugin/network/server.conf.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Plugin network>
<% if scope.lookupvar('collectd::collectd_version_real') and (scope.function_versioncmp([scope.lookupvar('collectd::collectd_version_real'), '4.7']) >= 0) -%>
<Server "<%= @name %>" "<%= @port %>">
<Server "<%= @server %>" "<%= @port %>">
<% if @securitylevel -%>
SecurityLevel "<%= @securitylevel %>"
<% end -%>
Expand All @@ -18,7 +18,7 @@
<% end %>
</Server>
<% else -%>
Server "<%= @name %>" "<%= @port %>"
Server "<%= @server %>" "<%= @port %>"
<% end -%>
<% if ! @forward.nil? -%>
Forward <%= @forward %>
Expand Down

0 comments on commit 4943084

Please sign in to comment.