Skip to content

Commit 0feed8c

Browse files
Aramacktruthbk
authored andcommitted
[http_check] add support for http_check method and data (#518)
1 parent a8b313f commit 0feed8c

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

manifests/integrations/http_check.pp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
# timeout
1313
# The (optional) timeout in seconds.
1414
#
15+
# method
16+
# The (optional) HTTP method. This setting defaults to GET, though many
17+
# other HTTP methods are supported, including POST and PUT.
18+
# data
19+
# The (optional) data option. Data should be a string or an array of
20+
# key-value pairs and will be sent in the body of the request.
21+
#
1522
# username
1623
# password
1724
# If your service uses basic authentication, you can optionally
@@ -154,6 +161,8 @@
154161
$username = undef,
155162
$password = undef,
156163
$timeout = 1,
164+
$method = 'get',
165+
$data = undef,
157166
$threshold = undef,
158167
$window = undef,
159168
$content_match = undef,
@@ -182,6 +191,8 @@
182191
'username' => $username,
183192
'password' => $password,
184193
'timeout' => $timeout,
194+
'method' => $method,
195+
'data' => $data,
185196
'threshold' => $threshold,
186197
'window' => $window,
187198
'content_match' => $content_match,

spec/classes/datadog_agent_integrations_http_check_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
it { should contain_file(conf_file).without_content(%r{username: }) }
3939
it { should contain_file(conf_file).without_content(%r{password: }) }
4040
it { should contain_file(conf_file).without_content(%r{timeout: 1}) }
41+
it { should contain_file(conf_file).without_content(%r{data: }) }
4142
it { should contain_file(conf_file).without_content(%{threshold: }) }
4243
it { should contain_file(conf_file).without_content(%r{window: }) }
4344
it { should contain_file(conf_file).without_content(%r{content_match: }) }
@@ -61,6 +62,8 @@
6162
username: 'foouser',
6263
password: 'barpassword',
6364
timeout: 123,
65+
method: 'post',
66+
data: 'key=value',
6467
threshold: 456,
6568
window: 789,
6669
content_match: 'foomatch',
@@ -82,6 +85,8 @@
8285
it { should contain_file(conf_file).with_content(%r{username: foouser}) }
8386
it { should contain_file(conf_file).with_content(%r{password: barpassword}) }
8487
it { should contain_file(conf_file).with_content(%r{timeout: 123}) }
88+
it { should contain_file(conf_file).with_content(%r{method: post}) }
89+
it { should contain_file(conf_file).with_content(%r{data: key=value}) }
8590
it { should contain_file(conf_file).with_content(%r{threshold: 456}) }
8691
it { should contain_file(conf_file).with_content(%r{window: 789}) }
8792
it { should contain_file(conf_file).with_content(%r{content_match: 'foomatch'}) }
@@ -98,6 +103,19 @@
98103
it { should contain_file(conf_file).with_content(%r{ca_certs: /dev/null}) }
99104
end
100105

106+
context 'with json post data' do
107+
let(:params) {{
108+
sitename: 'foo.bar.baz',
109+
url: 'http://foo.bar.baz:4096',
110+
method: 'post',
111+
data: ['key: value'],
112+
headers: ['Content-Type: application/json'],
113+
}}
114+
it { should contain_file(conf_file).with_content(%r{method: post}) }
115+
it { should contain_file(conf_file).with_content(/data:\s+key:\s+value/) }
116+
it { should contain_file(conf_file).with_content(/headers:\s+Content-Type:\s+application\/json/) }
117+
end
118+
101119
context 'with headers parameter array' do
102120
let(:params) {{
103121
sitename: 'foo.bar.baz',

templates/agent-conf.d/http_check.yaml.erb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ instances:
99
<% if instance['timeout'] -%>
1010
timeout: <%= instance['timeout'] %>
1111
<% end -%>
12+
<% if instance['method'] -%>
13+
method: <%= instance['method'] %>
14+
<% end -%>
15+
<% if instance['data'].is_a?(String) -%>
16+
data: <%= instance['data'] %>
17+
<% elsif instance['data'].is_a?(Array) -%>
18+
data:
19+
<%- instance['data'].each do |data| -%>
20+
<%= data %>
21+
<%- end -%>
22+
<% end -%>
1223
<% if instance['username'] -%>
1324
username: <%= instance['username'] %>
1425
<% end -%>

0 commit comments

Comments
 (0)