Skip to content

Commit 373a58f

Browse files
authored
Merge pull request #211 from DataDog/jaime/fixmetrics
[datadog-report] `m` could be nil, breaking reporting. Fix gem provider.
2 parents ab8ec1c + 7ac92d8 commit 373a58f

5 files changed

Lines changed: 93 additions & 42 deletions

File tree

README.md

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,40 +70,55 @@ Reporting
7070
---------
7171
To enable reporting of changes to the Datadog timeline, enable the report
7272
processor on your Puppet master, and enable reporting for your clients.
73-
The clients will send a run report after each check-in back to the master,
74-
and the master will process the reports and send them to the Datadog API.
73+
The clients will send a run report after each check-in back to the master.
7574

75+
Please specify what clients/hosts you'd like to submit puppet run reports
76+
for by setting the puppet_run_reports option to true in the node configuration
77+
manifest.
7678

77-
In your Puppet master `/etc/puppet/puppet.conf`, add these configuration options:
78-
79-
[main]
80-
# No need to modify this section
79+
```ruby
80+
class { "datadog-agent":
81+
api_key => "<your_api_key>",
82+
puppet_run_reports => true
8183
# ...
84+
}
85+
```
8286

83-
[master]
84-
# Enable reporting to datadog
85-
reports=datadog_reports
86-
# If you use other reports already, just add datadog_reports at the end
87-
# reports=store,log,datadog_reports
88-
# ...
87+
In your Puppet master `/etc/puppet/puppet.conf`, add these configuration options:
8988

90-
[agent]
91-
# ...
92-
pluginsync=true
93-
report=true
89+
```ini
90+
[main]
91+
# No need to modify this section
92+
# ...
93+
94+
[master]
95+
# Enable reporting to datadog
96+
reports=datadog_reports
97+
# If you use other reports already, just add datadog_reports at the end
98+
# reports=store,log,datadog_reports
99+
# ...
100+
101+
[agent]
102+
# ...
103+
pluginsync=true
104+
report=true
105+
```
94106

95107
And on all of your Puppet client nodes add:
96108

97-
[agent]
98-
# ...
99-
report=true
100-
109+
```ini
110+
[agent]
111+
# ...
112+
report=true
113+
```
101114

102115
If you get
103116

104-
err: Could not send report:
105-
Error 400 on SERVER: Could not autoload datadog_reports:
106-
Class Datadog_reports is already defined in Puppet::Reports
117+
```
118+
err: Could not send report:
119+
Error 400 on SERVER: Could not autoload datadog_reports:
120+
Class Datadog_reports is already defined in Puppet::Reports
121+
```
107122

108123
Make sure `reports=datadog_reports` is defined in **[master]**, not **[main]**.
109124

lib/puppet/reports/datadog_reports.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def process
4848
@msg_host = self.host
4949
unless HOSTNAME_EXTRACTION_REGEX.nil?
5050
m = @msg_host.match(HOSTNAME_EXTRACTION_REGEX)
51-
unless m[:hostname].nil?
51+
if !m.nil? && !m[:hostname].nil?
5252
@msg_host = m[:hostname]
5353
end
5454
end

manifests/init.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@
341341
class { 'datadog_agent::reports':
342342
api_key => $api_key,
343343
puppetmaster_user => $puppetmaster_user,
344+
dogapi_version => $datadog_agent::params::dogapi_version,
344345
hostname_extraction_regex => $hostname_extraction_regex,
345346
}
346347
}

manifests/reports.pp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,13 @@
1616
class datadog_agent::reports(
1717
$api_key,
1818
$puppetmaster_user,
19+
$dogapi_version,
1920
$hostname_extraction_regex = nil
2021
) {
2122

2223
include datadog_agent::params
2324
$rubydev_package = $datadog_agent::params::rubydev_package
24-
$gemprovider = 'puppetserver_gem'
25-
26-
# set the right provider
27-
if (!defined('$::serverversion') or versioncmp($::serverversion, '3.7.0') < 0) {
28-
$_gemprovider = 'gem'
29-
} else {
30-
$_gemprovider = $gemprovider
31-
}
25+
$gemprovider = 'gem'
3226

3327
# check to make sure that you're not installing rubydev somewhere else
3428
if ! defined(Package[$rubydev_package]) {
@@ -55,8 +49,8 @@
5549
}
5650

5751
package{'dogapi':
58-
ensure => $datadog_agent::params::dogapi_version,
59-
provider => $_gemprovider,
52+
ensure => $dogapi_version,
53+
provider => $gemprovider,
6054
}
6155

6256
}

spec/classes/datadog_agent_reports_spec.rb

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
require 'spec_helper'
22

33
describe 'datadog_agent::reports' do
4-
let(:params) do
5-
{
6-
api_key: 'notanapikey',
7-
hostname_extraction_regex: nil,
8-
puppetmaster_user: 'puppet'
9-
}
10-
end
11-
124
context 'all supported operating systems' do
5+
let(:params) do
6+
{
7+
api_key: 'notanapikey',
8+
hostname_extraction_regex: nil,
9+
puppetmaster_user: 'puppet',
10+
dogapi_version: 'installed'
11+
}
12+
end
1313
ALL_OS.each do |operatingsystem|
1414
describe "datadog_agent class common actions on #{operatingsystem}" do
1515
let(:facts) do
@@ -53,4 +53,45 @@
5353
end
5454
end
5555
end
56+
context 'specific dogapi version' do
57+
let(:params) do
58+
{
59+
api_key: 'notanapikey',
60+
hostname_extraction_regex: nil,
61+
puppetmaster_user: 'puppet',
62+
dogapi_version: '1.2.2'
63+
}
64+
end
65+
describe "datadog_agent class dogapi version override" do
66+
let(:facts) do
67+
{
68+
operatingsystem: 'Debian',
69+
osfamily: 'debian'
70+
}
71+
end
72+
73+
it { should contain_class('ruby').with_rubygems_update(false) }
74+
it { should contain_class('ruby::params') }
75+
it { should contain_package('ruby').with_ensure('installed') }
76+
it { should contain_package('rubygems').with_ensure('installed') }
77+
78+
it do
79+
should contain_package('ruby-dev')\
80+
.with_ensure('installed')\
81+
.that_comes_before('Package[dogapi]')
82+
end
83+
84+
it do
85+
should contain_package('dogapi')\
86+
.with_ensure('1.2.2')
87+
.with_provider('gem')
88+
end
89+
90+
it do
91+
should contain_file('/etc/dd-agent/datadog.yaml')\
92+
.with_owner('puppet')\
93+
.with_group('root')
94+
end
95+
end
96+
end
5697
end

0 commit comments

Comments
 (0)