Skip to content

Commit

Permalink
Allow to specify a custom network server hostname
Browse files Browse the repository at this point in the history
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,
    },
  },
}
```
  • Loading branch information
smortex committed Nov 28, 2024
1 parent d6423b9 commit 5bd8e6e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

##### <a name="-collectd--plugin--network--server--hostname"></a>`hostname`

Data type: `String[1]`

The hostname of the server to connect to

Default value: `$name`

##### <a name="-collectd--plugin--network--server--ensure"></a>`ensure`

Data type: `Enum['present', 'absent']`
Expand Down
2 changes: 2 additions & 0 deletions manifests/plugin/network/server.pp
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 2 additions & 1 deletion spec/defines/collectd_plugin_network_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
let(:title) { 'node1' }
let :params do
{
hostname: 'node1.example.com',
port: 1234,
interface: 'eth0',
securitylevel: 'Encrypt',
Expand All @@ -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: "<Plugin network>\n <Server \"node1\" \"1234\">\n SecurityLevel \"Encrypt\"\n Username \"foo\"\n Password \"bar\"\n Interface \"eth0\"\n\n </Server>\n</Plugin>\n"
content: "<Plugin network>\n <Server \"node1.example.com\" \"1234\">\n SecurityLevel \"Encrypt\"\n Username \"foo\"\n Password \"bar\"\n Interface \"eth0\"\n\n </Server>\n</Plugin>\n"
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion 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 "<%= @hostname %>" "<%= @port %>">
<% if @securitylevel -%>
SecurityLevel "<%= @securitylevel %>"
<% end -%>
Expand Down

0 comments on commit 5bd8e6e

Please sign in to comment.