Update nginx integration template
And add spec test coverage
Related to
MODIFY
recipes/nginx.rb
recipes/nginx.rb
@@ -9,11 +9,14 @@ include_recipe 'datadog::dd-agent'
# node['datadog']['nginx']['instances'] = [
# {
# 'nginx_status_url' => "http://localhost:81/nginx_status/",
-# 'tags' => ["prod"]
+# 'tags' => ["prod"],
+# 'user' => "my_username",
+# 'password' => "my_password"
# },
# {
-# 'nginx_status_url' => "http://localhost:82/nginx_status/",
-# 'name' => ["test"]
+# 'nginx_status_url' => "https://localhost:82/nginx_status/",
+# 'name' => ['test'],
+# 'ssl_validation' => false
# }
# ]

ADD
spec/integrations/nginx_spec.rb
+describe 'datadog::nginx' do
+ expected_yaml = <<-EOF
+ init_config:
+
+ instances:
+ - nginx_status_url: http://localhost:80/nginx_status/
+ tags:
+ - optional_tag1
+ - optional_tag2
+ - nginx_status_url: http://localhost:81/nginx_status/
+ user: my_username
+ password: my_password
+ - nginx_status_url: https://localhost:82/nginx_status/
+ ssl_validation: false
+ EOF
+
+ cached(:chef_run) do
+ ChefSpec::SoloRunner.new(step_into: ['datadog_monitor']) do |node|
+ node.automatic['languages'] = { 'python' => { 'version' => '2.7.2' } }
+ node.set['datadog'] = {
+ api_key: 'someapikey',
+ nginx: {
+ instances: [
+ {
+ nginx_status_url: 'http://localhost:80/nginx_status/',
+ tags: ['optional_tag1', 'optional_tag2']
+ }, {
+ nginx_status_url: 'http://localhost:81/nginx_status/',
+ user: 'my_username',
+ password: 'my_password'
+ }, {
+ nginx_status_url: 'https://localhost:82/nginx_status/',
+ ssl_validation: false
+ }
+ ]
+ }
+ }
+ end.converge(described_recipe)
+ end
+
+ subject { chef_run }
+
+ it_behaves_like 'datadog-agent'
+
+ it { is_expected.to include_recipe('datadog::dd-agent') }
+
+ it { is_expected.to add_datadog_monitor('nginx') }
+
+ it 'renders expected YAML config file' do
+ expect(chef_run).to render_file('/etc/dd-agent/conf.d/nginx.yaml').with_content { |content|
+ expect(YAML.load(content).to_json).to be_json_eql(YAML.load(expected_yaml).to_json)
+ }
+ end
+end

MODIFY
templates/default/nginx.yaml.erb
templates/default/nginx.yaml.erb
instances:
<% @instances.each do |i| -%>
- nginx_status_url: <%= i['nginx_status_url'] %>
+ <% unless i['ssl_validation'].nil? -%>
+ ssl_validation: <%= i['ssl_validation'] %>
+ <% end -%>
+ <%# don't print user/password if either is nil -%>
+ <% unless i['user'].nil? || i['password'].nil? -%>
+ user: <%= i['user'] %>
+ password: <%= i['password'] %>
+ <% end -%>
<% if i.key?('tags') -%>
tags:
<% i['tags'].each do |t| -%>

Update nginx integration template (#417)

And add spec test coverage

Related to #194