Skip to content

Commit

Permalink
curl: fix handling of some parameters
Browse files Browse the repository at this point in the history
 - $verifypeer/$verifyhost/$measureresponsetime: properly handle undef vs. false
 - $matches: default value (array with empty hash) creates bad config (match
   block with missing values)
 - $matches: match blocks are optional if measureresponsetime is enabled
  • Loading branch information
bogus-py committed Dec 7, 2014
1 parent 8889605 commit 4d01659
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
6 changes: 5 additions & 1 deletion manifests/plugin/curl/page.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
$header = undef,
$post = undef,
$measureresponsetime = undef,
$matches = [{ }],
$matches = undef,
$plugininstance = $name, # You can have multiple <Page> with the same name.
) {
include collectd::params
Expand All @@ -20,6 +20,10 @@

validate_string($url)

if $matches != undef {
validate_array($matches)
}

file { "${conf_dir}/curl-${name}.conf":
ensure => $ensure,
mode => '0640',
Expand Down
27 changes: 27 additions & 0 deletions spec/classes/collectd_plugin_curl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,33 @@
end
end

context ':ensure => present, verifypeer => false, verifyhost => \'false\', measureresponsetime => true, matches empty' do
let :facts do
{:osfamily => 'Debian'}
end
let :params do
{
:ensure => 'present',
:pages => {
'selfsigned_ssl' => {
'url' => 'https://some.selfsigned.ssl.site/',
'verifypeer' => false,
'verifyhost' => 'false',
'measureresponsetime' => true,
},
}
}
end

it 'Will create /etc/collectd.d/conf.d/curl-selfsigned_ssl.conf' do
should contain_file('/etc/collectd/conf.d/curl-selfsigned_ssl.conf').with({
:ensure => 'present',
:path => '/etc/collectd/conf.d/curl-selfsigned_ssl.conf',
:content => "<Plugin curl>\n <Page \"selfsigned_ssl\">\n URL \"https://some.selfsigned.ssl.site/\"\n VerifyPeer false\n VerifyHost false\n MeasureResponseTime true\n </Page>\n</Plugin>\n",
})
end
end

context ':ensure => absent' do
let :facts do
{:osfamily => 'RedHat'}
Expand Down
12 changes: 7 additions & 5 deletions templates/plugin/curl-page.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<% if @password -%>
Password "<%= @password %>"
<% end -%>
<% if @verifypeer -%>
VerifyPeer "<%= @verifypeer %>"
<% unless @verifypeer.nil? -%>
VerifyPeer <%= @verifypeer %>
<% end -%>
<% if @verifyhost %>
VerifyHost "<%= @verifyhost %>"
<% unless @verifyhost.nil? -%>
VerifyHost <%= @verifyhost %>
<% end -%>
<% if @cacert -%>
CACert "<%= @cacert %>"
Expand All @@ -22,9 +22,11 @@
<% if @post and @collectd_version and (scope.function_versioncmp([@collectd_version, '5.3']) >= 0) -%>
Post "<%= @post %>"
<% end -%>
<% if @measureresponsetime -%>
<% unless @measureresponsetime.nil? -%>
MeasureResponseTime <%= @measureresponsetime %>
<% end -%>
<% if @matches -%>
<%= scope.function_template(["collectd/plugin/match.tpl.erb"]) %>
<% end -%>
</Page>
</Plugin>

0 comments on commit 4d01659

Please sign in to comment.