Skip to content

Commit 9472fc7

Browse files
authored
update mongo configuration template (#838)
1 parent 7f93cb4 commit 9472fc7

File tree

3 files changed

+72
-8
lines changed

3 files changed

+72
-8
lines changed

manifests/integrations/mongo.pp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@
55
# NOTE: In newer versions of the Datadog Agent, the ssl parameters will be deprecated in favor the tls variants
66
#
77
# Parameters:
8+
# $hosts
9+
# Array of hosts host (and optional port number) where the mongod instance is running
10+
# $dbm
11+
# Enable the Database Monitoring feature
12+
# $database_autodiscovery
13+
# Enable the Database Autodiscovery feature
14+
# $reported_database_hostname
15+
# Optional database hostname override the mongodb hostname detected by the Agent from mongodb admin command serverStatus
816
# $additional_metrics
917
# Optional array of additional metrics
1018
# $database
1119
# Optionally specify database to query. Defaults to 'admin'
12-
# $host:
13-
# The host mongo is running on. Defaults to '127.0.0.1'
1420
# $password
1521
# Optionally specify password for connection
16-
# $port
17-
# The port mongo is running on. Defaults to 27017
1822
# $ssl
1923
# Optionally enable SSL for connection
2024
# $ssl_ca_certs
@@ -37,6 +41,12 @@
3741
# Optional array of tags
3842
# $username
3943
# Optionally specify username for connection
44+
# $host:
45+
# Deprecated use $hosts instead
46+
# The host mongo is running on. Defaults to '127.0.0.1'
47+
# $port
48+
# Deprecated use $hosts instead
49+
# The port mongo is running on. Defaults to 27017
4050
#
4151
# Sample Usage (Older Agent Versions):
4252
#
@@ -73,19 +83,20 @@
7383
# {
7484
# 'additional_metrics' => ['top'],
7585
# 'database' => 'database_name',
76-
# 'host' => 'localhost',
86+
# 'hosts' => ['localhost:27017'],
7787
# 'password' => 'mongo_password',
78-
# 'port' => '27017',
7988
# 'tls' => true,
8089
# 'tls_ca_file' => '/path/to/ca.pem',
8190
# 'tls_allow_invalid_certificates' => false,
8291
# 'tls_certificate_key_file' => '/path/to/combined.pem',
8392
# 'tags' => ['optional_tag1', 'optional_tag2'],
8493
# 'username' => 'mongo_username',
94+
# 'dbm' => true,
95+
# 'database_autodiscovery' => {'enabled' => true},
96+
# 'reported_database_hostname' => 'mymongodbhost',
8597
# },
8698
# {
87-
# 'host' => 'localhost',
88-
# 'port' => '27018',
99+
# 'hosts' => ['localhost:27017'],
89100
# 'tags' => [],
90101
# 'additional_metrics' => [],
91102
# 'collections' => [],

spec/classes/datadog_agent_integrations_mongo_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@
2727
it { is_expected.to contain_file(conf_file).without_content(%r{tags:}) }
2828
end
2929

30+
context 'with one mongo host defined in hosts' do
31+
let(:params) do
32+
{
33+
servers: [
34+
{
35+
'hosts' => ['localhost:27017'],
36+
'username' => 'user',
37+
'password' => 'pass',
38+
'dbm' => true,
39+
'database_autodiscovery' => { 'enabled' => true },
40+
'reported_database_hostname' => 'mongohost',
41+
},
42+
],
43+
}
44+
end
45+
46+
it { is_expected.to contain_file(conf_file).with_content(%r{- hosts:\s+- localhost:27017}) }
47+
it { is_expected.to contain_file(conf_file).with_content(%r{username: user}) }
48+
it { is_expected.to contain_file(conf_file).with_content(%r{password: pass}) }
49+
it { is_expected.to contain_file(conf_file).with_content(%r{dbm: true}) }
50+
it { is_expected.to contain_file(conf_file).with_content(%r{database_autodiscovery:\s+enabled: true}) }
51+
it { is_expected.to contain_file(conf_file).with_content(%r{reported_database_hostname: mongohost}) }
52+
end
53+
3054
context 'with one mongo' do
3155
let(:params) do
3256
{

templates/agent-conf.d/mongo.yaml.erb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,24 @@ init_config:
44

55
instances:
66
<% @servers.each do |server| -%>
7+
<% if !server['hosts'].nil? && server['hosts'].any? -%>
8+
- hosts:
9+
<%- server['hosts'].each do |host| -%>
10+
- <%= host %>
11+
<%- end -%>
12+
<%- if !server['username'].nil? -%>
13+
username: <%= server['username'] %>
14+
<%- end -%>
15+
<%- if !server['password'].nil? -%>
16+
password: <%= server['password'] %>
17+
<%- end -%>
18+
<%- if !server['database'].nil? -%>
19+
database: <%= server['database'] %>
20+
<%- end -%>
21+
<%- end -%>
22+
<% if server['hosts'].nil? -%>
723
- server: mongodb://<%= server['username'] %><%= ":" unless server['password'].nil? %><%= server['password'] %><%= "@" unless server['username'].nil? %><%= server['host'] %>:<%= server['port'] %>/<%= server['database'] %>
24+
<%- end -%>
825
<%- if !server['tags'].nil? && server['tags'].any? -%>
926
tags:
1027
<%- server['tags'].each do |tag| -%>
@@ -50,4 +67,16 @@ instances:
5067
- <%= collection %>
5168
<%- end -%>
5269
<%- end -%>
70+
<%- if !server['dbm'].nil? -%>
71+
dbm: <%= server['dbm'] %>
72+
<%- end -%>
73+
<%- if !server['database_autodiscovery'].nil? -%>
74+
database_autodiscovery:
75+
<%- if !server['database_autodiscovery']['enabled'].nil? -%>
76+
enabled: <%= server['database_autodiscovery']['enabled'] %>
77+
<%- end -%>
78+
<%- end -%>
79+
<%- if !server['reported_database_hostname'].nil? -%>
80+
reported_database_hostname: <%= server['reported_database_hostname'] %>
81+
<%- end -%>
5382
<% end -%>

0 commit comments

Comments
 (0)