Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 26 additions & 1 deletion manifests/integrations/http_check.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
# This class will install the necessary config to hook the http_check in the agent
#
# Parameters:
# sitename
# (Required) The name of the instance.
#
# url
# (Required) The url to check.
#
# timeout
# The (optional) timeout in seconds.
#
# username
# password
Expand Down Expand Up @@ -57,9 +63,12 @@
# a list of users to notify within the service configuration.
#
# tags
# The (optional) tags to add to the check instance.
#
# Sample Usage:
#
# Add a class for each check instance:
#
# class { 'datadog_agent::integrations::http_check':
# sitename => 'google',
# url => 'http://www.google.com/',
Expand All @@ -86,6 +95,22 @@
# }
#
#
# Add multiple instances in one class declaration:
#
# class { 'datadog_agent::integrations::http_check':
# instances => [{
# 'sitename' => 'google',
# 'url' => 'http://www.google.com',
# },
# {
# 'sitename' => 'local',
# 'url' => 'http://localhost/',
# 'headers' => ['Host: stan.borbat.com', 'DNT: true'],
# 'tags' => ['production', 'wordpress']
# }]
# }


class datadog_agent::integrations::http_check (
$sitename = undef,
$url = undef,
Expand Down Expand Up @@ -117,7 +142,7 @@
'content_match' => $content_match,
'include_content' => $include_content,
'collect_response_time' => $collect_response_time,
'disable_ssl_validation' => $disable_ssl_validation,
'disable_ssl_validation' => $disable_ssl_validation,
'headers' => $headers,
'tags' => $tags,
'contact' => $contact,
Expand Down
4 changes: 4 additions & 0 deletions templates/agent-conf.d/http_check.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ instances:
<% if instance['collect_response_time'] -%>
collect_response_time: <%= instance['collect_response_time'] %>
<% end -%>
<% if instance['disable_ssl_validation'] -%>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will fail if the key doesn't exist... can you try with has_key(instance, 'disable_ssl_validation') instead?

Copy link
Copy Markdown
Contributor Author

@sjenriquez sjenriquez Nov 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested successfully with this config in the manifest:

node 'ip-0-0-0-0.ec2.internal' {
    class { "datadog_agent":
        api_key => "key"
    }

    class { 'datadog_agent::integrations::http_check':
      instances => [{
        'sitename'  => 'google',
        'url'       => 'http://www.google.com',
        'tags'      => 'site:google'
      },
      {
        'sitename'  => 'datadog',
        'url'       => 'http://www.datadoghq.com',
        'tags'      => 'site:dog'
      }]
    }
}

We only add parameters when they are found. Another alternative would be to use:
if instance.has_key?("disable_ssl_validation") although I used the above for consistency. What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nil evaluates as false:

irb(main):001:0> instance = {"sitename"=>"google", "url"=>"http://www.google.com", "tags"=>"site:google"}
=> {"sitename"=>"google", "url"=>"http://www.google.com", "tags"=>"site:google"}
irb(main):002:0> instance['disable_ssl_validation']
=> nil
irb(main):003:0> if instance['disable_ssl_validation']; puts 'TRUE' ; else puts 'FALSE' ; end
FALSE
=> nil

disable_ssl_validation: <%= instance['disable_ssl_validation'] %>
<% else %>
disable_ssl_validation: false
Copy link
Copy Markdown
Member

@truthbk truthbk Nov 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just remove this.... the if here in line 31 should be enough - just check if 'disable_ssl_validation' key is defined in the hash and then drop in the value.

<% end -%>
<% if instance['headers'] and ! instance['headers'].empty? -%>
headers:
<%- Array(instance['headers']).each do |header| -%>
Expand Down