From 5bd8e6e3330fa7f11455cd4ae66d1ae0422b5b28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Wed, 27 Nov 2024 18:12:54 -1000 Subject: [PATCH] Allow to specify a custom network server hostname When sending metrics to multiple services on distinct ports on the same node, in order to avoid conflicts we need to allow overriding the server hostname on a per resource basis. Example use case: ```puppet class { 'collectd::plugin::network': servers => { 'collectd' => { hostname => 'remote.example.com', port => 25826, }, 'influxdb' => { hostname => 'remote.example.com', port => 25827, }, }, } ``` --- REFERENCE.md | 9 +++++++++ manifests/plugin/network/server.pp | 2 ++ spec/defines/collectd_plugin_network_server_spec.rb | 3 ++- templates/plugin/network/server.conf.erb | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index 6f1127127..b31bce376 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -8812,6 +8812,7 @@ The collectd::plugin::network::server class. The following parameters are available in the `collectd::plugin::network::server` defined type: +* [`hostname`](#-collectd--plugin--network--server--hostname) * [`ensure`](#-collectd--plugin--network--server--ensure) * [`username`](#-collectd--plugin--network--server--username) * [`password`](#-collectd--plugin--network--server--password) @@ -8821,6 +8822,14 @@ The following parameters are available in the `collectd::plugin::network::server * [`forward`](#-collectd--plugin--network--server--forward) * [`resolveinterval`](#-collectd--plugin--network--server--resolveinterval) +##### `hostname` + +Data type: `String[1]` + +The hostname of the server to connect to + +Default value: `$name` + ##### `ensure` Data type: `Enum['present', 'absent']` diff --git a/manifests/plugin/network/server.pp b/manifests/plugin/network/server.pp index 8587f63fe..9c9903632 100644 --- a/manifests/plugin/network/server.pp +++ b/manifests/plugin/network/server.pp @@ -1,6 +1,8 @@ # +# @param hostname The hostname of the server to connect to define collectd::plugin::network::server ( Enum['present', 'absent'] $ensure = 'present', + String[1] $hostname = $name, Optional[String] $username = undef, Optional[String] $password = undef, Optional[Stdlib::Port] $port = undef, diff --git a/spec/defines/collectd_plugin_network_server_spec.rb b/spec/defines/collectd_plugin_network_server_spec.rb index 0c330ebf9..c6e814e0e 100644 --- a/spec/defines/collectd_plugin_network_server_spec.rb +++ b/spec/defines/collectd_plugin_network_server_spec.rb @@ -14,6 +14,7 @@ let(:title) { 'node1' } let :params do { + hostname: 'node1.example.com', port: 1234, interface: 'eth0', securitylevel: 'Encrypt', @@ -26,7 +27,7 @@ is_expected.to contain_file("#{options[:plugin_conf_dir]}/network-server-node1.conf").with( ensure: 'present', path: "#{options[:plugin_conf_dir]}/network-server-node1.conf", - content: "\n \n SecurityLevel \"Encrypt\"\n Username \"foo\"\n Password \"bar\"\n Interface \"eth0\"\n\n \n\n" + content: "\n \n SecurityLevel \"Encrypt\"\n Username \"foo\"\n Password \"bar\"\n Interface \"eth0\"\n\n \n\n" ) end end diff --git a/templates/plugin/network/server.conf.erb b/templates/plugin/network/server.conf.erb index a11137a21..70bd05b16 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 -%>