From 4943084ece69da4b0de1e22eefdc48ab70548769 Mon Sep 17 00:00:00 2001 From: fe80 Date: Mon, 28 Mar 2022 16:36:28 +0200 Subject: [PATCH] add server parameter on collectd::plugin::network::server 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. --- manifests/plugin/network/server.pp | 1 + .../collectd_plugin_network_server_spec.rb | 17 ++++++++++++++++- templates/plugin/network/server.conf.erb | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/manifests/plugin/network/server.pp b/manifests/plugin/network/server.pp index 8587f63fe..9d72b58ca 100644 --- a/manifests/plugin/network/server.pp +++ b/manifests/plugin/network/server.pp @@ -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 diff --git a/spec/defines/collectd_plugin_network_server_spec.rb b/spec/defines/collectd_plugin_network_server_spec.rb index 1a2fee65e..595c5095a 100644 --- a/spec/defines/collectd_plugin_network_server_spec.rb +++ b/spec/defines/collectd_plugin_network_server_spec.rb @@ -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 @@ -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{\n}) + end + end end end end diff --git a/templates/plugin/network/server.conf.erb b/templates/plugin/network/server.conf.erb index a11137a21..19489b547 100644 --- a/templates/plugin/network/server.conf.erb +++ b/templates/plugin/network/server.conf.erb @@ -1,6 +1,6 @@ <% if scope.lookupvar('collectd::collectd_version_real') and (scope.function_versioncmp([scope.lookupvar('collectd::collectd_version_real'), '4.7']) >= 0) -%> - " "<%= @port %>"> + " "<%= @port %>"> <% if @securitylevel -%> SecurityLevel "<%= @securitylevel %>" <% end -%> @@ -18,7 +18,7 @@ <% end %> <% else -%> - Server "<%= @name %>" "<%= @port %>" + Server "<%= @server %>" "<%= @port %>" <% end -%> <% if ! @forward.nil? -%> Forward <%= @forward %>