forked from DataDog/puppet-datadog-agent
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtcp_check.pp
147 lines (143 loc) · 4.64 KB
/
tcp_check.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Class: datadog_agent::integrations::tcp_check
#
# This class will install the necessary config to hook the tcp_check in the agent
#
# Parameters:
# check_name
# (Required) - Name of the service.
# This will be included as a tag: instance:<check_name>.
#
# host
# (Required) - Host to be checked.
# This will be included as a tag: url:<host>:<port>.
#
# port
# (Required) - Port to be checked.
# This will be included as a tag: url:<host>:<port>.
#
# timeout
# (Optional) - Timeout for the check. Defaults to 10 seconds.
#
# threshold
# (Optional) - Used in conjunction with window. An alert will
# trigger if the check fails <threshold> times in <window> attempts.
#
# window
# (Optional) - Refer to threshold.
#
# collect_response_time
# (Optional) - Defaults to false. If this is not set to true, no
# response time metric will be collected. If it is set to true, the
# metric returned is network.tcp.response_time.
#
# skip_event
# The (optional) skip_event parameter will instruct the check to not
# create any event to avoid duplicates with a server side service check.
# This default to False.
#
# tags
# The (optional) tags to add to the check instance.
#
# Sample Usage:
#
# Add a class for each check instance:
#
# class { 'datadog_agent::integrations::tcp_check':
# check_name => 'localhost-ftp',
# host => 'ftp.example.com',
# port => '21',
# }
#
# class { 'datadog_agent::integrations::tcp_check':
# check_name => 'localhost-ssh',
# host => '127.0.0.1',
# port => '22',
# threshold => 1,
# window => 1,
# tags => ['production', 'ssh access'],
# }
#
# class { 'datadog_agent::integrations::tcp_check':
# name => 'localhost-web-response',
# host => '127.0.0.1',
# port => '80',
# timeout => '8',
# threshold => 1,
# window => 1,
# collect_response_time => 1,
# skip_event => 1,
# tags => ['production', 'webserver response time'],
# }
#
# Add multiple instances in one class declaration:
#
# class { 'datadog_agent::integrations::tcp_check':
# instances => [{
# 'check_name' => 'www.example.com-http',
# 'host' => 'www.example.com',
# 'port' => '80',
# },
# {
# 'check_name' => 'www.example.com-https',
# 'host' => 'www.example.com',
# 'port' => '443',
# }]
# }
class datadog_agent::integrations::tcp_check (
String $check_name,
String $host,
Optional[String] $port = undef,
Integer $timeout = 10,
Optional[Integer] $threshold = undef,
Optional[Integer] $window = undef,
Optional[Integer] $collect_response_time = undef,
Optional[Integer] $skip_event = undef,
Array $tags = [],
Optional[Array] $instances = undef,
) inherits datadog_agent::params {
require datadog_agent
if !$instances and $host {
$_instances = [{
'check_name' => $check_name,
'host' => $host,
'port' => $port,
'timeout' => $timeout,
'threshold' => $threshold,
'window' => $window,
'collect_response_time' => $collect_response_time,
'skip_event' => $skip_event,
'tags' => $tags,
}]
} elsif !$instances {
$_instances = []
} else {
$_instances = $instances
}
$legacy_dst = "${datadog_agent::params::legacy_conf_dir}/tcp_check.yaml"
if $datadog_agent::_agent_major_version > 5 {
$dst_dir = "${datadog_agent::params::conf_dir}/tcp_check.d"
file { $legacy_dst:
ensure => 'absent',
}
file { $dst_dir:
ensure => directory,
owner => $datadog_agent::dd_user,
group => $datadog_agent::params::dd_group,
mode => $datadog_agent::params::permissions_directory,
require => Package[$datadog_agent::params::package_name],
notify => Service[$datadog_agent::params::service_name],
}
$dst = "${dst_dir}/conf.yaml"
} else {
$dst = $legacy_dst
}
file { $dst:
ensure => file,
owner => $datadog_agent::dd_user,
group => $datadog_agent::params::dd_group,
mode => $datadog_agent::params::permissions_protected_file,
content => template('datadog_agent/agent-conf.d/tcp_check.yaml.erb'),
require => Package[$datadog_agent::params::package_name],
notify => Service[$datadog_agent::params::service_name],
}
}