/
init.pp
120 lines (113 loc) · 3.54 KB
/
init.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Class: datadog_agent
#
# This class contains the agent installation mechanism for the Datadog module
#
# Parameters:
# $dd_url:
# The host of the Datadog intake server to send agent data to.
# Defaults to https://app.datadoghq.com.
# $host:
# Your hostname to see in Datadog. Defaults with Datadog hostname detection.
# $api_key:
# Your DataDog API Key. Please replace with your key value.
# $tags
# Optional array of tags.
# $facts_to_tags
# Optional array of facts' names that you can use to define tags following
# the scheme: "fact_name:fact_value".
# $puppet_run_reports
# Will send results from your puppet agent runs back to the datadog service.
# $puppetmaster_user
# Will chown the api key used by the report processor to this user.
# $non_local_traffic
# Enable you to use the agent as a proxy. Defaults to false.
# See https://github.com/DataDog/dd-agent/wiki/Proxy-Configuration
# $log_level
# Set value of 'log_level' variable. Default is 'info' as in dd-agent.
# Valid values here are: critical, debug, error, fatal, info, warn and warning.
# $log_to_syslog
# Set value of 'log_to_syslog' variable. Default is true -> yes as in dd-agent.
# Valid values here are: true or false.
#
# Actions:
#
# Requires:
#
# Sample Usage:
#
# include datadog_agent
#
# OR
#
# class { 'datadog_agent':
# api_key => 'your key',
# tags => ['env:production', 'linux'],
# puppet_run_reports => false,
# puppetmaster_user => puppet,
# }
#
#
class datadog_agent(
$dd_url = 'https://app.datadoghq.com',
$host = '',
$api_key = 'your_API_key',
$tags = [],
$facts_to_tags = [],
$puppet_run_reports = false,
$puppetmaster_user = 'puppet',
$non_local_traffic = false,
$log_level = 'info',
$log_to_syslog = true,
$service_ensure = 'running',
$service_enable = true
) inherits datadog_agent::params {
validate_string($dd_url)
validate_string($host)
validate_string($api_key)
validate_array($tags)
validate_array($facts_to_tags)
validate_bool($puppet_run_reports)
validate_string($puppetmaster_user)
validate_bool($non_local_traffic)
validate_bool($log_to_syslog)
validate_string($log_level)
include datadog_agent::params
case upcase($log_level) {
'CRITICAL': { $_loglevel = 'CRITICAL' }
'DEBUG': { $_loglevel = 'DEBUG' }
'ERROR': { $_loglevel = 'ERROR' }
'FATAL': { $_loglevel = 'FATAL' }
'INFO': { $_loglevel = 'INFO' }
'WARN': { $_loglevel = 'WARN' }
'WARNING': { $_loglevel = 'WARNING' }
default: { $_loglevel = 'INFO' }
}
case $::operatingsystem {
'Ubuntu','Debian' : { include datadog_agent::ubuntu }
'RedHat','CentOS','Fedora','Amazon','Scientific' : { include datadog_agent::redhat }
default: { fail("Class[datadog_agent]: Unsupported operatingsystem: ${::operatingsystem}") }
}
file { '/etc/dd-agent':
ensure => present,
owner => 'root',
group => 'root',
mode => '0755',
require => Package['datadog-agent'],
}
# main agent config file
file { '/etc/dd-agent/datadog.conf':
ensure => file,
content => template('datadog_agent/datadog.conf.erb'),
owner => $datadog_agent::params::dd_user,
group => $datadog_agent::params::dd_group,
mode => '0640',
notify => Service[$datadog_agent::params::service_name],
require => File['/etc/dd-agent'],
}
if $puppet_run_reports {
class { 'datadog_agent::reports':
api_key => $api_key,
puppetmaster_user => $puppetmaster_user,
}
}
}