Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

curl_json: support parameters: host, digest, post, timeout #649

Merged
merged 1 commit into from
Apr 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,20 @@ class { 'collectd::plugin::curl':
```puppet
collectd::plugin::curl_json {
'rabbitmq_overview':
url => 'http://localhost:55672/api/overview',
instance => 'rabbitmq_overview',
interval => '300',
keys => {
url => 'http://localhost:55672/api/overview',
host => 'rabbitmq.example.net',
instance => 'rabbitmq_overview',
interval => '300',
user => 'user',
password => 'password',
digest => 'false',
verifypeer => 'false',
verifyhost => 'false',
cacert => '/path/to/ca.crt',
header => 'Accept: application/json',
post => '{secret: \"mysecret\"}',
timeout => '1000',
keys => {
'message_stats/publish' => {
'type' => 'gauge',
'instance' => 'overview',
Expand Down
4 changes: 4 additions & 0 deletions manifests/plugin/curl_json.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
$instance,
$keys,
$ensure = 'present',
$host = undef,
$interval = undef,
$user = undef,
$password = undef,
$digest = undef,
$verifypeer = undef,
$verifyhost = undef,
$cacert = undef,
$header = undef,
$post = undef,
$timeout = undef,
$order = '10',
$manage_package = undef,
) {
Expand Down
177 changes: 177 additions & 0 deletions spec/defines/collectd_plugin_curl_json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,30 @@
let(:my_params) do
{
url: 'http://localhost:55672/api/overview',
host: 'rabbitmq.example.net',
instance: 'rabbitmq_overview',
interval: 10,
user: 'user',
password: 'password',
digest: 'false',
verifypeer: 'false',
verifyhost: 'false',
cacert: '/path/to/ca.crt',
header: 'Accept: application/json',
post: '{secret: \"mysecret\"}',
timeout: 1000,
keys: {
'message_stats/publish' => {
'type' => 'gauge',
'instance' => 'overview'
}
}
}
end
let(:sock_params) do
{
url: '/run/sock',
instance: 'rabbitmq_overview',
keys: {
'message_stats/publish' => {
'type' => 'gauge',
Expand Down Expand Up @@ -46,10 +65,168 @@
it { is_expected.to contain_file(filename).that_notifies('Service[collectd]') }
it { is_expected.to contain_file(filename).with_content(%r{LoadPlugin "curl_json"}) }
it { is_expected.to contain_file(filename).with_content(%r{URL "http://localhost:55672/api/overview">}) }
it { is_expected.to contain_file(filename).without_content(%r{\bHost}) }
it { is_expected.to contain_file(filename).without_content(%r{Interval}) }
it { is_expected.to contain_file(filename).with_content(%r{User "user"}) }
it { is_expected.to contain_file(filename).with_content(%r{Password "password"}) }
it { is_expected.to contain_file(filename).without_content(%r{Digest}) }
it { is_expected.to contain_file(filename).with_content(%r{VerifyPeer false}) }
it { is_expected.to contain_file(filename).with_content(%r{VerifyHost false}) }
it { is_expected.to contain_file(filename).with_content(%r{CACert "/path/to/ca.crt"}) }
it { is_expected.to contain_file(filename).without_content(%r{Header}) }
it { is_expected.to contain_file(filename).without_content(%r{Post}) }
it { is_expected.to contain_file(filename).without_content(%r{Timeout}) }
it { is_expected.to contain_file(filename).with_content(%r{Key "message_stats/publish">}) }
it { is_expected.to contain_file(filename).with_content(%r{Type "gauge"}) }
it { is_expected.to contain_file(filename).with_content(%r{Instance "overview"}) }
end

context 'default params 5.3' do
let(:params) { my_params }

let :facts do
{
osfamily: 'Debian',
collectd_version: '5.3.0',
operatingsystemmajrelease: '7',
python_dir: '/usr/local/lib/python2.7/dist-packages'
}
end

it do
is_expected.to contain_file(filename).with(
path: '/etc/collectd/conf.d/10-rabbitmq_overview.conf'
)
end

it { is_expected.to contain_file(filename).that_notifies('Service[collectd]') }
it { is_expected.to contain_file(filename).with_content(%r{LoadPlugin "curl_json"}) }
it { is_expected.to contain_file(filename).with_content(%r{URL "http://localhost:55672/api/overview">}) }
it { is_expected.to contain_file(filename).without_content(%r{\bHost}) }
it { is_expected.to contain_file(filename).with_content(%r{Instance "rabbitmq_overview"}) }
it { is_expected.to contain_file(filename).without_content(%r{Interval}) }
it { is_expected.to contain_file(filename).with_content(%r{User "user"}) }
it { is_expected.to contain_file(filename).with_content(%r{Password "password"}) }
it { is_expected.to contain_file(filename).without_content(%r{Digest}) }
it { is_expected.to contain_file(filename).with_content(%r{VerifyPeer false}) }
it { is_expected.to contain_file(filename).with_content(%r{VerifyHost false}) }
it { is_expected.to contain_file(filename).with_content(%r{CACert "/path/to/ca.crt"}) }
it { is_expected.to contain_file(filename).with_content(%r{Header "Accept: application/json"}) }
it { is_expected.to contain_file(filename).with_content(%r|Post "{secret: \\"mysecret\\"}"|) }
it { is_expected.to contain_file(filename).without_content(%r{Timeout}) }
it { is_expected.to contain_file(filename).with_content(%r{Key "message_stats/publish">}) }
it { is_expected.to contain_file(filename).with_content(%r{Type "gauge"}) }
it { is_expected.to contain_file(filename).with_content(%r{Instance "overview"}) }
end

context 'default params 5.5' do
let(:params) { my_params }

let :facts do
{
osfamily: 'Debian',
collectd_version: '5.5.0',
operatingsystemmajrelease: '7',
python_dir: '/usr/local/lib/python2.7/dist-packages'
}
end

it do
is_expected.to contain_file(filename).with(
path: '/etc/collectd/conf.d/10-rabbitmq_overview.conf'
)
end

it { is_expected.to contain_file(filename).that_notifies('Service[collectd]') }
it { is_expected.to contain_file(filename).with_content(%r{LoadPlugin "curl_json"}) }
it { is_expected.to contain_file(filename).with_content(%r{URL "http://localhost:55672/api/overview">}) }
it { is_expected.to contain_file(filename).without_content(%r{\bHost}) }
it { is_expected.to contain_file(filename).with_content(%r{Instance "rabbitmq_overview"}) }
it { is_expected.to contain_file(filename).with_content(%r{Interval 10}) }
it { is_expected.to contain_file(filename).with_content(%r{User "user"}) }
it { is_expected.to contain_file(filename).with_content(%r{Password "password"}) }
it { is_expected.to contain_file(filename).with_content(%r{Digest false}) }
it { is_expected.to contain_file(filename).with_content(%r{VerifyPeer false}) }
it { is_expected.to contain_file(filename).with_content(%r{VerifyHost false}) }
it { is_expected.to contain_file(filename).with_content(%r{CACert "/path/to/ca.crt"}) }
it { is_expected.to contain_file(filename).with_content(%r{Header "Accept: application/json"}) }
it { is_expected.to contain_file(filename).with_content(%r|Post "{secret: \\"mysecret\\"}"|) }
it { is_expected.to contain_file(filename).with_content(%r{Timeout 1000}) }
it { is_expected.to contain_file(filename).with_content(%r{Key "message_stats/publish">}) }
it { is_expected.to contain_file(filename).with_content(%r{Type "gauge"}) }
it { is_expected.to contain_file(filename).with_content(%r{Instance "overview"}) }
end

context 'default params 5.6' do
let(:params) { my_params }

let :facts do
{
osfamily: 'Debian',
collectd_version: '5.6.0',
operatingsystemmajrelease: '7',
python_dir: '/usr/local/lib/python2.7/dist-packages'
}
end

it do
is_expected.to contain_file(filename).with(
path: '/etc/collectd/conf.d/10-rabbitmq_overview.conf'
)
end

it { is_expected.to contain_file(filename).that_notifies('Service[collectd]') }
it { is_expected.to contain_file(filename).with_content(%r{LoadPlugin "curl_json"}) }
it { is_expected.to contain_file(filename).with_content(%r{URL "http://localhost:55672/api/overview">}) }
it { is_expected.to contain_file(filename).with_content(%r{Host "rabbitmq\.example\.net"}) }
it { is_expected.to contain_file(filename).with_content(%r{Instance "rabbitmq_overview"}) }
it { is_expected.to contain_file(filename).with_content(%r{Interval 10}) }
it { is_expected.to contain_file(filename).with_content(%r{User "user"}) }
it { is_expected.to contain_file(filename).with_content(%r{Password "password"}) }
it { is_expected.to contain_file(filename).with_content(%r{Digest false}) }
it { is_expected.to contain_file(filename).with_content(%r{VerifyPeer false}) }
it { is_expected.to contain_file(filename).with_content(%r{VerifyHost false}) }
it { is_expected.to contain_file(filename).with_content(%r{CACert "/path/to/ca.crt"}) }
it { is_expected.to contain_file(filename).with_content(%r{Header "Accept: application/json"}) }
it { is_expected.to contain_file(filename).with_content(%r|Post "{secret: \\"mysecret\\"}"|) }
it { is_expected.to contain_file(filename).with_content(%r{Timeout 1000}) }
it { is_expected.to contain_file(filename).with_content(%r{Key "message_stats/publish">}) }
it { is_expected.to contain_file(filename).with_content(%r{Type "gauge"}) }
it { is_expected.to contain_file(filename).with_content(%r{Instance "overview"}) }
end

context 'sock params' do
let(:params) { sock_params }

let :facts do
{
osfamily: 'Debian',
collectd_version: '5.6.0',
operatingsystemmajrelease: '7',
python_dir: '/usr/local/lib/python2.7/dist-packages'
}
end

it do
is_expected.to contain_file(filename).with(
path: '/etc/collectd/conf.d/10-rabbitmq_overview.conf'
)
end

it { is_expected.to contain_file(filename).that_notifies('Service[collectd]') }
it { is_expected.to contain_file(filename).with_content(%r{LoadPlugin "curl_json"}) }
it { is_expected.to contain_file(filename).with_content(%r{Sock "/run/sock">}) }
it { is_expected.to contain_file(filename).without_content(%r{Host}) }
it { is_expected.to contain_file(filename).without_content(%r{Interval}) }
it { is_expected.to contain_file(filename).without_content(%r{User}) }
it { is_expected.to contain_file(filename).without_content(%r{Password}) }
it { is_expected.to contain_file(filename).without_content(%r{Digest}) }
it { is_expected.to contain_file(filename).without_content(%r{VerifyPeer}) }
it { is_expected.to contain_file(filename).without_content(%r{VerifyHost}) }
it { is_expected.to contain_file(filename).without_content(%r{CACert}) }
it { is_expected.to contain_file(filename).without_content(%r{Header}) }
it { is_expected.to contain_file(filename).without_content(%r{Post}) }
it { is_expected.to contain_file(filename).without_content(%r{Timeout}) }
it { is_expected.to contain_file(filename).with_content(%r{Key "message_stats/publish">}) }
it { is_expected.to contain_file(filename).with_content(%r{Type "gauge"}) }
it { is_expected.to contain_file(filename).with_content(%r{Instance "overview"}) }
Expand Down
22 changes: 22 additions & 0 deletions templates/curl_json.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,27 @@ LoadPlugin "curl_json"
<Sock "<%= @url %>">
<%- else -%>
<URL "<%= @url %>">
<%- end -%>
<% if scope.lookupvar('collectd::collectd_version_real') and (scope.function_versioncmp([scope.lookupvar('collectd::collectd_version_real'), '5.6']) >= 0) -%>
<%- if @host -%>
Host "<%= @host %>">
<%- end -%>
<%- end -%>
Instance "<%= @instance %>"
<% if scope.lookupvar('collectd::collectd_version_real') and (scope.function_versioncmp([scope.lookupvar('collectd::collectd_version_real'), '5.5']) >= 0) -%>
<% if @interval -%>
Interval <%= @interval %>
<% end -%>
<% end -%>
<% if @user -%>
User "<%= @user %>"
Password "<%= @password %>"
<% end -%>
<% if scope.lookupvar('collectd::collectd_version_real') and (scope.function_versioncmp([scope.lookupvar('collectd::collectd_version_real'), '5.5']) >= 0) -%>
<% unless @digest.nil? -%>
Digest <%= @digest %>
<% end -%>
<% end -%>
<% unless @verifypeer.nil? -%>
VerifyPeer <%= @verifypeer %>
<% end -%>
Expand All @@ -24,9 +36,19 @@ LoadPlugin "curl_json"
<% if @cacert -%>
CACert "<%= @cacert %>"
<% end -%>
<% if scope.lookupvar('collectd::collectd_version_real') and (scope.function_versioncmp([scope.lookupvar('collectd::collectd_version_real'), '5.3']) >= 0) -%>
<% if @header -%>
Header "<%= @header %>"
<% end -%>
<% unless @post.nil? -%>
Post "<%= @post %>"
<% end -%>
<% end -%>
<% if scope.lookupvar('collectd::collectd_version_real') and (scope.function_versioncmp([scope.lookupvar('collectd::collectd_version_real'), '5.5']) >= 0) -%>
<% unless @timeout.nil? -%>
Timeout <%= @timeout %>
<% end -%>
<% end -%>
<% @keys.sort.each do |key,keydata| -%>
<Key "<%= key %>">
Type "<%= keydata['type'] %>"
Expand Down