46
46
def load_tls_certs(path):
48
48
for filepath in glob.glob("{}/*.pem".format(os.path.abspath(path))):
49
# There might be some dead symlinks in there, so let's make sure it's real.
50
if os.path.exists(filepath):
49
# There might be some dead symlinks in there,
50
# so let's make sure it's real.
51
if os.path.isfile(filepath):
51
52
data = open(filepath).read()
52
53
x509 = load_certificate(FILETYPE_PEM, data)
53
54
# Now, de-duplicate in case the same cert has multiple names.
103
104
raise ValueError("timed out")
105
raise ValueError("timed out connecting to %s" % ip)
106
raise ValueError("timed out connecting to {}".format(ip))
108
109
def make_tcp_check(host, port, timeout=None, **kwargs):
109
110
"""Return a check for TCP connectivity."""
110
111
return make_check("tcp:{}:{}".format(host, port),
111
112
lambda: do_tcp_check(host, port, timeout=timeout),
112
info="%s:%s" % (host, port))
113
info="{}:{}".format(host, port))
115
116
def make_tls_check(host, port, disable_tls_verification=False, timeout=None,
117
118
"""Return a check for TLS setup."""
118
return make_check("tls:{}:{}".format(host, port),
119
lambda: do_tcp_check(host, port, tls=True,
120
tls_verify=(not disable_tls_verification),
122
info="%s:%s" % (host, port))
120
verify = not disable_tls_verification
121
check = make_check("tls:{}:{}".format(host, port),
122
lambda: do_tcp_check(host, port, tls=True,
125
info="{}:{}".format(host, port))
125
130
class UDPCheckProtocol(DatagramProtocol):
176
181
raise ValueError("timed out")
178
raise ValueError("timed out waiting for %s" % ip)
183
raise ValueError("timed out waiting for {}".format(ip))
181
186
def make_udp_check(host, port, send, expect, timeout=None,
183
188
"""Return a check for UDP connectivity."""
184
189
return make_check("udp:{}:{}".format(host, port),
185
lambda: do_udp_check(host, port, send, expect, timeout),
186
info="%s:%s" % (host, port))
190
lambda: do_udp_check(host, port, send, expect, timeout),
191
info="{}:{}".format(host, port))
189
194
def extract_host_port(url):
219
224
def do_request():
222
proxies['http'] = proxies['https']= proxy_url
227
proxies['http'] = proxies['https'] = proxy_url
224
proxies['http'] = proxies['https']= '{}:{}'.format(
225
proxy_host, proxy_port)
229
proxies['http'] = proxies['https'] = '{}:{}'.format(
230
proxy_host, proxy_port)
227
232
headers = kwargs.get('headers')
228
233
body = kwargs.get('body')
266
271
if response.status_code != expected_code:
267
272
raise RuntimeError(
268
273
"Unexpected response code: {}".format(
269
response.status_code))
274
response.status_code))
271
276
subchecks.append(make_check('', do_request,
272
277
info='{} {}'.format(method, url)))
273
279
return add_check_prefix('http:{}'.format(url),
274
280
sequential_check(subchecks))
299
305
yield client.authenticate(username, password)
301
307
subchecks.append(make_check("amqp:{}:{}".format(host, port),
302
do_auth, info="user %s" % (username,),))
308
do_auth, info="user {}".format(username),))
303
309
return sequential_check(subchecks)
331
337
subchecks.append(make_check("postgres:{}:{}".format(host, port),
332
check_auth, info="user %s" % (username,),
338
check_auth, info="user {}".format(username),
334
341
return sequential_check(subchecks)
359
366
raise RuntimeError("failed to auth to redis")
361
connect_info = "connect with auth" if password is not None else "connect"
368
if password is not None:
369
connect_info = "connect with auth"
371
connect_info = "connect"
362
372
subchecks.append(make_check(connect_info, do_connect))
363
374
return add_check_prefix('redis:{}:{}'.format(host, port),
364
375
sequential_check(subchecks))
380
391
version = yield client.version()
393
raise RuntimeError('Failed retrieve memcached server version')
382
395
subchecks.append(make_check('connect', do_connect))
383
397
return add_check_prefix('memcache:{}:{}'.format(host, port),
384
398
sequential_check(subchecks))
412
426
mongo = yield conn
413
427
names = yield mongo[database].collection_names()
429
raise RuntimeError('Failed to retrieve collection names')
415
431
def timeout_handler():
416
"""Manual timeout handler as txmongo timeout args above don't work in
432
"""Manual timeout handler as txmongo timeout args don't always work."""
418
433
if 'deferred' in do_connect.func_dict:
419
434
err = ValueError("timeout connecting to mongodb")
420
435
do_connect.func_dict['deferred'].errback(err)
422
connect_info = "connect with auth" if any((username, password)) else "connect"
437
if any((username, password)):
438
connect_info = "connect with auth"
440
connect_info = "connect"
423
441
subchecks.append(make_check(connect_info, do_connect))
424
443
return add_check_prefix('mongodb:{}:{}'.format(host, port),
425
444
sequential_check(subchecks))