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

Update report processor to add tag function based on Puppet facts. #641

Merged
merged 3 commits into from
Jul 28, 2020
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
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ Once the `datadog_agent` module is installed on your `puppetserver`/`puppetmaste
- To support reporting, your Puppet master needs the [dogapi][3] gem installed by running the Puppet Agent on your master with this configuration or installing it manually with `gem`. You may need to restart your `puppetserver` service after installing the `dogapi` gem.
- `puppetserver_gem` is defined as a module dependency. It is installed automatically when the module is installed.

4. (Optional) Include integrations to use with the Agent, for example:
4. (Optional) Enable tagging of reports with facts
You can add tags to reports that are sent to Datadog as events. These tags can be sourced from Puppet facts for the given node the report is regarding. These should be 1:1 and not involve structured facts (hashes, arrays, etc.) to ensure readability. To enable tagging, set the parameter `datadog_agent::reports::report_fact_tags` to the array value of facts—for example `["virtual","trusted.extensions.pp_role","operatingsystem"]` results in three separate tags per report event.

NOTE: Changing these settings requires a restart of pe-puppetserver (or puppetserver) to re-read the report processor. Ensure the changes are deployed prior to restarting the service(s).

Tips:
- Use dot index to specify a target fact; otherwise, the entire fact data set becomes the value as a string (not very useful)
- Do not duplicate common data from monitoring like hostname, uptime, memory, etc.
- Coordinate core facts like role, owner, template, datacenter, etc., that help you build meaningful correlations to the same tags from metrics


5. (Optional) Include integrations to use with the Agent, for example:

```conf
include 'datadog_agent::integrations::mongo'
Expand Down
8 changes: 7 additions & 1 deletion lib/puppet/reports/datadog_reports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
config = YAML.load_file(configfile)
API_KEY = config[:datadog_api_key]
API_URL = config[:api_url]
REPORT_FACT_TAGS = config[:report_fact_tags] || []

if ENV['DD_PROXY_HTTP'].nil?
ENV['DD_PROXY_HTTP'] = config[:proxy_http]
Expand Down Expand Up @@ -128,13 +129,18 @@ def process
end
end

facts = Puppet::Node::Facts.indirection.find(host).values
dog_tags = REPORT_FACT_TAGS.map { |name| "#{name}:#{facts.dig(*name.split('.'))}" }

Puppet.debug "Sending events for #{@msg_host} to Datadog"
@dog.emit_event(Dogapi::Event.new(event_data,
msg_title: event_title,
event_type: 'config_management.run',
event_object: @msg_host,
alert_type: alert_type,
priority: event_priority,
source_type_name: 'puppet'), host: @msg_host)
source_type_name: 'puppet',
tags: dog_tags),
host: @msg_host)
end
end
3 changes: 3 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
# Valid values here are: true or false.
# $dogstatsd_port
# Set value of the 'dogstatsd_port' variable. Defaultis 8125.
# $report_fact_tags
# Sets tags for report events sent to Datadog from specified facts
# $statsd_forward_host
# Set the value of the statsd_forward_host varable. Used to forward all
# statsd metrics to another host.
Expand Down Expand Up @@ -776,6 +778,7 @@
hostname_extraction_regex => $hostname_extraction_regex,
proxy_http => $proxy_http,
proxy_https => $proxy_https,
report_fact_tags => $report_fact_tags,
}
}

Expand Down
1 change: 1 addition & 0 deletions manifests/reports.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
$hostname_extraction_regex = undef,
$proxy_http = undef,
$proxy_https = undef,
$report_fact_tags = [],
$datadog_site = 'datadoghq.com',
$puppet_gem_provider = $datadog_agent::params::gem_provider,
) inherits datadog_agent::params {
Expand Down
6 changes: 6 additions & 0 deletions templates/datadog-reports.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@
<% if @proxy_https -%>
:proxy_https: <%= @proxy_https %>
<% end -%>
<% if @report_fact_tags -%>
:report_fact_tags:
<%- @report_fact_tags.each do |tag| -%>
- <%= tag %>
<%- end -%>
<% end -%>