forked from DataDog/puppet-datadog-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_check.pp
More file actions
238 lines (232 loc) · 8.56 KB
/
http_check.pp
File metadata and controls
238 lines (232 loc) · 8.56 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# Class: datadog_agent::integrations::http_check
#
# This class will install the necessary config to hook the http_check in the agent
#
# Parameters:
# sitename
# (Required) The name of the instance.
#
# url
# (Required) The url to check.
#
# timeout
# The (optional) timeout in seconds.
#
# username
# password
# If your service uses basic authentication, you can optionally
# specify a username and password that will be used in the check.
#
# threshold
# window
# The (optional) window and threshold parameters allow you to trigger
# alerts only if the check fails x times within the last y attempts
# where x is the threshold and y is the window.
#
# content_match
# The (optional) content_match parameter will allow the check
# to look for a particular string within the response. The check
# will report as DOWN if the string is not found.
# content_match uses Python regular expressions which means that
# you will have to escape the following "special" characters with
# a backslash (\) if you're trying to match them in your content:
# . ^ $ * + ? { } [ ] \ | ( )
#
# include_content
# The (optional) collect_response_time parameter will instruct the
# check to create a metric 'network.http.response_time', tagged with
# the url, reporting the response time in seconds.
#
# http_response_status_code
# The (optional) http_response_status_code parameter will instruct the check
# to look for a particular HTTP response status code or a Regex identifying
# a set of possible status codes.
# The check will report as DOWN if status code returned differs.
# This defaults to 1xx, 2xx and 3xx HTTP status code: (1|2|3)\d\d.
#
# collect_response_time
# The (optional) collect_response_time parameter will instruct the
# check to create a metric 'network.http.response_time', tagged with
# the url, reporting the response time in seconds.
#
# ca_certs
# An optional string representing the path to CA certificates.
#
# disable_ssl_validation
# The setting disable_ssl_validation parameter to true will instruct
# the http client to accept self signed, expired and otherwise
# problematic SSL server certificates. To maintain backwards
# compatibility this defaults to false.
#
# 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 defaults to True because this is being deprecated.
# (See https://github.com/DataDog/dd-agent/blob/master/checks/network_checks.py#L178-L180)
#
# no_proxy
# The (optional) no_proxy parameter would bypass any proxy settings enabled
# and attempt to reach the the URL directly.
# If no proxy is defined at any level, this flag bears no effect.
# Defaults to False.
#
# check_certificate_expiration
# days_warning
# days_critical
# The (optional) check_certificate_expiration will instruct the check
# to create a service check that checks the expiration of the
# ssl certificate. Allow for a warning to occur when x days are
# left in the certificate, and alternatively raise a critical
# warning if the certificate is y days from the expiration date.
# The SSL certificate will always be validated for this additional
# service check regardless of the value of disable_ssl_validation
#
# headers
# The (optional) headers parameter allows you to send extra headers
# with the request. This is useful for explicitly specifying the host
# header or perhaps adding headers for authorisation purposes. Note
# that the http client library converts all headers to lowercase.
# This is legal according to RFC2616
# (See: http://tools.ietf.org/html/rfc2616#section-4.2)
# but may be problematic with some HTTP servers
# (See: https://code.google.com/p/httplib2/issues/detail?id=169)
#
# allow_redirects
# The (optional) allow_redirects parameter can enable redirection.
# Defaults to True.
#
# contact
# For service-specific notifications, you can optionally specify
# a list of users to notify within the service configuration.
#
# tags
# The (optional) tags to add to the check instance.
#
# Sample Usage:
#
# Add a class for each check instance:
#
# class { 'datadog_agent::integrations::http_check':
# sitename => 'google',
# url => 'http://www.google.com/',
# }
#
# class { 'datadog_agent::integrations::http_check':
# sitename => 'local',
# url => 'http://localhost/',
# headers => ['Host: stan.borbat.com', 'DNT: true'],
# tags => ['production', 'wordpress'],
# }
#
# class { 'datadog_agent::integrations::http_check':
# sitename => 'localhost-9001',
# url => 'http://localhost:9001/',
# timeout => 5,
# threshold => 1,
# window => 1,
# content_match => '^(Bread|Apples) float(s)? in water'
# include_content => true,
# collect_response_time => true,
# contact => 'pagerduty',
# tags => 'production',
# }
#
#
# Add multiple instances in one class declaration:
#
# class { 'datadog_agent::integrations::http_check':
# instances => [{
# 'sitename' => 'google',
# 'url' => 'http://www.google.com',
# },
# {
# 'sitename' => 'local',
# 'url' => 'http://localhost/',
# 'headers' => ['Host: stan.borbat.com', 'DNT: true'],
# 'tags' => ['production', 'wordpress']
# }]
# }
class datadog_agent::integrations::http_check (
$sitename = undef,
$url = undef,
$username = undef,
$password = undef,
$timeout = 1,
$threshold = undef,
$window = undef,
$content_match = undef,
$include_content = false,
$http_response_status_code = undef,
$collect_response_time = true,
$disable_ssl_validation = false,
$skip_event = true,
$no_proxy = false,
$check_certificate_expiration = true,
$days_warning = undef,
$days_critical = undef,
$headers = [],
$allow_redirects = true,
$tags = [],
$contact = [],
$instances = undef,
$ca_certs = undef,
) inherits datadog_agent::params {
include datadog_agent
if !$instances and $url {
$_instances = [{
'sitename' => $sitename,
'url' => $url,
'username' => $username,
'password' => $password,
'timeout' => $timeout,
'threshold' => $threshold,
'window' => $window,
'content_match' => $content_match,
'include_content' => $include_content,
'http_response_status_code' => $http_response_status_code,
'collect_response_time' => $collect_response_time,
'disable_ssl_validation' => $disable_ssl_validation,
'skip_event' => $skip_event,
'no_proxy' => $no_proxy,
'check_certificate_expiration' => $check_certificate_expiration,
'days_warning' => $days_warning,
'days_critical' => $days_critical,
'headers' => $headers,
'allow_redirects' => $allow_redirects,
'tags' => $tags,
'contact' => $contact,
'ca_certs' => $ca_certs,
}]
} elsif !$instances{
$_instances = []
} else {
$_instances = $instances
}
$legacy_dst = "${datadog_agent::conf_dir}/http_check.yaml"
if !$::datadog_agent::agent5_enable {
$dst_dir = "${datadog_agent::conf6_dir}/http_check.d"
file { $legacy_dst:
ensure => 'absent'
}
file { $dst_dir:
ensure => directory,
owner => $datadog_agent::params::dd_user,
group => $datadog_agent::params::dd_group,
mode => '0755',
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::params::dd_user,
group => $datadog_agent::params::dd_group,
mode => '0600',
content => template('datadog_agent/agent-conf.d/http_check.yaml.erb'),
require => Package[$datadog_agent::params::package_name],
notify => Service[$datadog_agent::params::service_name]
}
}