diff --git a/manifests/plugin/curl/page.pp b/manifests/plugin/curl/page.pp index 64c5bb90e..d91c06d73 100644 --- a/manifests/plugin/curl/page.pp +++ b/manifests/plugin/curl/page.pp @@ -10,7 +10,7 @@ $header = undef, $post = undef, $measureresponsetime = undef, - $matches = [{ }], + $matches = undef, $plugininstance = $name, # You can have multiple with the same name. ) { include collectd::params @@ -20,6 +20,10 @@ validate_string($url) + if $matches != undef { + validate_array($matches) + } + file { "${conf_dir}/curl-${name}.conf": ensure => $ensure, mode => '0640', diff --git a/spec/classes/collectd_plugin_curl_spec.rb b/spec/classes/collectd_plugin_curl_spec.rb index 7b76eabc6..964452aae 100644 --- a/spec/classes/collectd_plugin_curl_spec.rb +++ b/spec/classes/collectd_plugin_curl_spec.rb @@ -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 => "\n \n URL \"https://some.selfsigned.ssl.site/\"\n VerifyPeer false\n VerifyHost false\n MeasureResponseTime true\n \n\n", + }) + end + end + context ':ensure => absent' do let :facts do {:osfamily => 'RedHat'} diff --git a/templates/plugin/curl-page.conf.erb b/templates/plugin/curl-page.conf.erb index 8ecccef34..3caf4b011 100644 --- a/templates/plugin/curl-page.conf.erb +++ b/templates/plugin/curl-page.conf.erb @@ -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 %>" @@ -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 -%>