Skip to content

Commit 352a9c7

Browse files
authored
Update report processor to add tag function based on Puppet facts. (DataDog#641)
Modify report class to manage report tags from facts through datadog config yaml file.
1 parent e117b35 commit 352a9c7

5 files changed

Lines changed: 29 additions & 2 deletions

File tree

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,18 @@ Once the `datadog_agent` module is installed on your `puppetserver`/`puppetmaste
6565
- 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.
6666
- `puppetserver_gem` is defined as a module dependency. It is installed automatically when the module is installed.
6767

68-
4. (Optional) Include integrations to use with the Agent, for example:
68+
4. (Optional) Enable tagging of reports with facts
69+
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.
70+
71+
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).
72+
73+
Tips:
74+
- Use dot index to specify a target fact; otherwise, the entire fact data set becomes the value as a string (not very useful)
75+
- Do not duplicate common data from monitoring like hostname, uptime, memory, etc.
76+
- Coordinate core facts like role, owner, template, datacenter, etc., that help you build meaningful correlations to the same tags from metrics
77+
78+
79+
5. (Optional) Include integrations to use with the Agent, for example:
6980

7081
```conf
7182
include 'datadog_agent::integrations::mongo'

lib/puppet/reports/datadog_reports.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
config = YAML.load_file(configfile)
1414
API_KEY = config[:datadog_api_key]
1515
API_URL = config[:api_url]
16+
REPORT_FACT_TAGS = config[:report_fact_tags] || []
1617

1718
if ENV['DD_PROXY_HTTP'].nil?
1819
ENV['DD_PROXY_HTTP'] = config[:proxy_http]
@@ -133,13 +134,18 @@ def process
133134
end
134135
end
135136

137+
facts = Puppet::Node::Facts.indirection.find(host).values
138+
dog_tags = REPORT_FACT_TAGS.map { |name| "#{name}:#{facts.dig(*name.split('.'))}" }
139+
136140
Puppet.debug "Sending events for #{@msg_host} to Datadog"
137141
@dog.emit_event(Dogapi::Event.new(event_data,
138142
msg_title: event_title,
139143
event_type: 'config_management.run',
140144
event_object: @msg_host,
141145
alert_type: alert_type,
142146
priority: event_priority,
143-
source_type_name: 'puppet'), host: @msg_host)
147+
source_type_name: 'puppet',
148+
tags: dog_tags),
149+
host: @msg_host)
144150
end
145151
end

manifests/init.pp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
# Valid values here are: true or false.
6363
# $dogstatsd_port
6464
# Set value of the 'dogstatsd_port' variable. Defaultis 8125.
65+
# $report_fact_tags
66+
# Sets tags for report events sent to Datadog from specified facts
6567
# $statsd_forward_host
6668
# Set the value of the statsd_forward_host varable. Used to forward all
6769
# statsd metrics to another host.
@@ -776,6 +778,7 @@
776778
hostname_extraction_regex => $hostname_extraction_regex,
777779
proxy_http => $proxy_http,
778780
proxy_https => $proxy_https,
781+
report_fact_tags => $report_fact_tags,
779782
}
780783
}
781784

manifests/reports.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
$hostname_extraction_regex = undef,
2222
$proxy_http = undef,
2323
$proxy_https = undef,
24+
$report_fact_tags = [],
2425
$datadog_site = 'datadoghq.com',
2526
$puppet_gem_provider = $datadog_agent::params::gem_provider,
2627
) inherits datadog_agent::params {

templates/datadog-reports.yaml.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@
1212
<% if @proxy_https -%>
1313
:proxy_https: <%= @proxy_https %>
1414
<% end -%>
15+
<% if @report_fact_tags -%>
16+
:report_fact_tags:
17+
<%- @report_fact_tags.each do |tag| -%>
18+
- <%= tag %>
19+
<%- end -%>
20+
<% end -%>

0 commit comments

Comments
 (0)