Skip to content

Commit c87d13c

Browse files
committed
Allow passing instances as hash to apache
1 parent e69e610 commit c87d13c

File tree

3 files changed

+41
-28
lines changed

3 files changed

+41
-28
lines changed

manifests/integrations/apache.pp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,29 @@
2727
# }
2828
#
2929
class datadog_agent::integrations::apache (
30-
String $url = 'http://localhost/server-status?auto',
31-
Optional[String] $username = undef,
32-
Optional[String] $password = undef,
33-
Array $tags = [],
34-
Boolean $disable_ssl_validation = false
30+
String $url = 'http://localhost/server-status?auto',
31+
Optional[String] $username = undef,
32+
Optional[String] $password = undef,
33+
Array $tags = [],
34+
Optional[Boolean] $disable_ssl_validation = undef,
35+
Optional[Hash] $init_config = undef,
36+
Optional[Array] $instances = undef,
37+
Optional[Array] $logs = undef,
3538
) inherits datadog_agent::params {
3639
include datadog_agent
3740

41+
if !$instances {
42+
$_instances = datadog_agent::clean_empty([{
43+
'apache_status_url' => $url,
44+
'apache_user' => $username,
45+
'apache_password' => $password,
46+
'tags' => $tags,
47+
'disable_ssl_validation' => $disable_ssl_validation,
48+
}])
49+
} else {
50+
$_instances = $instances
51+
}
52+
3853
$legacy_dst = "${datadog_agent::params::legacy_conf_dir}/apache.yaml"
3954
if $::datadog_agent::_agent_major_version > 5 {
4055
$dst_dir = "${datadog_agent::params::conf_dir}/apache.d"

spec/classes/datadog_agent_integrations_apache_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@
100100

101101
skip('doubly undefined behavior')
102102
end
103+
104+
context 'with instances hash' do
105+
let(:params) do
106+
{
107+
instances: [
108+
{
109+
'apache_status_url' => 'http://foobar',
110+
'apache_user' => 'userfoo',
111+
'apache_password' => 'passfoo',
112+
'tags' => ['foo', 'bar', 'baz'],
113+
},
114+
],
115+
}
116+
end
117+
118+
it { is_expected.to contain_file(conf_file).with_content(%r{apache_status_url: http://foobar}) }
119+
it { is_expected.to contain_file(conf_file).with_content(%r{apache_user: userfoo}) }
120+
it { is_expected.to contain_file(conf_file).with_content(%r{apache_password: passfoo}) }
121+
end
103122
end
104123
end
105124
end
Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
11
### MANAGED BY PUPPET
2-
3-
init_config:
4-
5-
instances:
6-
- apache_status_url: <%= @url %>
7-
<% if @disable_ssl_validation -%>
8-
disable_ssl_validation: <%= @disable_ssl_validation %>
9-
<% end -%>
10-
<% if @username -%>
11-
apache_user: <%= @username %>
12-
<% end -%>
13-
<% if @password -%>
14-
apache_password: <%= @password %>
15-
<% end -%>
16-
<% if @tags and ! @tags.empty? -%>
17-
tags:
18-
<%- Array(@tags).each do |tag| -%>
19-
<%- if tag != '' -%>
20-
- <%= tag %>
21-
<%- end -%>
22-
<%- end -%>
23-
<% end -%>
24-
2+
<% require 'yaml' -%>
3+
<%= {'init_config'=>@init_config, 'instances'=>@_instances, 'logs'=>@logs}.to_yaml %>

0 commit comments

Comments
 (0)