Skip to content

Commit 4ffbe79

Browse files
committed
Add parameter for extra options to Telegraf inputs
This commit adds a new parameter for passing additional hash elements to the options parameter of the Telegraf inputs used in this module.
1 parent b95cd9f commit 4ffbe79

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

manifests/telegraf/agent.pp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
'sslcert' => '/etc/telegraf/puppet_cert.pem',
147147
'sslrootcert' => '/etc/telegraf/puppet_ca.pem',
148148
},
149+
Optional[Hash] $extra_input_options = undef,
149150
Enum['yaml','toml'] $template_format = $puppet_operational_dashboards::template_format,
150151
) {
151152
unless [$puppetserver_hosts, $puppetdb_hosts, $postgres_hosts, $profiles, $local_services].any |$service| { $service } {
@@ -350,6 +351,7 @@
350351
http_timeout_seconds => $http_timeout_seconds,
351352
template_format => $template_format,
352353
include_pe_metrics => $include_pe_metrics,
354+
extra_input_options => $extra_input_options,
353355
}
354356
}
355357
@@ -360,6 +362,7 @@
360362
http_timeout_seconds => $http_timeout_seconds,
361363
template_format => $template_format,
362364
include_pe_metrics => $include_pe_metrics,
365+
extra_input_options => $extra_input_options,
363366
}
364367
}
365368
@@ -370,6 +373,7 @@
370373
http_timeout_seconds => $http_timeout_seconds,
371374
template_format => $template_format,
372375
include_pe_metrics => $include_pe_metrics,
376+
extra_input_options => $extra_input_options,
373377
}
374378
}
375379
@@ -417,6 +421,7 @@
417421
http_timeout_seconds => $http_timeout_seconds,
418422
template_format => $template_format,
419423
include_pe_metrics => $include_pe_metrics,
424+
extra_input_options => $extra_input_options,
420425
}
421426
}
422427
}
@@ -434,6 +439,7 @@
434439
http_timeout_seconds => $http_timeout_seconds,
435440
template_format => $template_format,
436441
include_pe_metrics => $include_pe_metrics,
442+
extra_input_options => $extra_input_options,
437443
}
438444
}
439445
@@ -444,6 +450,7 @@
444450
http_timeout_seconds => $http_timeout_seconds,
445451
template_format => $template_format,
446452
include_pe_metrics => $include_pe_metrics,
453+
extra_input_options => $extra_input_options,
447454
}
448455
if $include_pe_metrics {
449456
puppet_operational_dashboards::telegraf::config { 'pcp':
@@ -452,6 +459,7 @@
452459
http_timeout_seconds => $http_timeout_seconds,
453460
template_format => $template_format,
454461
include_pe_metrics => $include_pe_metrics,
462+
extra_input_options => $extra_input_options,
455463
}
456464
}
457465
}
@@ -463,6 +471,7 @@
463471
http_timeout_seconds => $http_timeout_seconds,
464472
template_format => $template_format,
465473
include_pe_metrics => $include_pe_metrics,
474+
extra_input_options => $extra_input_options,
466475
}
467476
}
468477

manifests/telegraf/config.pp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
Enum['present', 'absent'] $ensure = 'present',
2222
Enum['yaml','toml'] $template_format = 'toml',
2323
Boolean $include_pe_metrics,
24+
Optional[Hash] $extra_input_options = undef,
2425
) {
2526
unless $service in ['puppetserver', 'puppetdb', 'puppetdb_jvm', 'orchestrator', 'pcp'] {
2627
fail("Unknown service type ${service}")
@@ -56,7 +57,12 @@
5657

5758
telegraf::input { "${service}_metrics":
5859
plugin_type => 'http',
59-
options => [$_inputs],
60+
options => if $extra_input_options {
61+
[$_inputs + $extra_input_options]
62+
}
63+
else {
64+
[$_inputs]
65+
},
6066
}
6167

6268
# Create processors.strings.rename entries to rename full url to hostname

spec/defines/puppet_operational_dashboards_telegraf_config_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'spec_helper'
22
require 'json'
3+
require 'pry'
34

45
describe 'puppet_operational_dashboards::telegraf::config' do
56
let(:facts) { { os: { family: 'RedHat' } } }
@@ -169,4 +170,36 @@
169170
)
170171
}
171172
end
173+
174+
context 'when passing extra input options' do
175+
let(:title) { 'puppetserver' }
176+
let(:puppetserver_epp) do
177+
JSON.parse(File.read('./spec/fixtures/defines/puppetserver_metrics.json'))
178+
end
179+
let(:params) do
180+
{
181+
ensure: 'present',
182+
protocol: 'https',
183+
http_timeout_seconds: 5,
184+
hosts: ['localhost.foo.com'],
185+
include_pe_metrics: true,
186+
extra_input_options: {
187+
tags: {
188+
'foo' => 'bar',
189+
}
190+
}
191+
}
192+
193+
end
194+
195+
it {
196+
is_expected.to compile
197+
198+
# Testing that the Telegraf input contains identical Ruby objects was turning out to be difficult
199+
# It was returning an error but saying the diffs were identical, so instead we just check the file
200+
is_expected.to contain_file('/etc/telegraf/telegraf.d/puppetserver_metrics.conf').with_content(
201+
%r{\[inputs\.http\.tags]\nfoo = \"bar\"}
202+
)
203+
}
204+
end
172205
end

0 commit comments

Comments
 (0)