~landscape/charms/trusty/rabbitmq-server-backport-lp1500204/trunk

« back to all changes in this revision

Viewing changes to tests/50_test_monitoring.py

  • Committer: Liam Young
  • Date: 2015-04-20 11:13:39 UTC
  • mfrom: (88.2.3 rabbitmq-server)
  • Revision ID: liam.young@canonical.com-20150420111339-gk9s4g4gjrh0uyhn
[thedac, r=gnuoy] This change adds support for queue monitoring by nagios.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
 
 
3
# This Amulet test performs a basic deploy and checks if rabbitmq is running.
 
4
 
 
5
import amulet
 
6
import os
 
7
import time
 
8
 
 
9
# The number of seconds to wait for the environment to setup.
 
10
seconds = 900
 
11
# Get the directory in this way to load the files from the tests directory.
 
12
path = os.path.abspath(os.path.dirname(__file__))
 
13
 
 
14
key_path = os.path.join(path, 'rabbit-server-privkey.pem')
 
15
# Read the private key file.
 
16
with open(key_path) as f:
 
17
    privateKey = f.read()
 
18
# Read the certificate file.
 
19
cert_path = os.path.join(path, 'rabbit-server-cert.pem')
 
20
with open(cert_path) as f:
 
21
    certificate = f.read()
 
22
 
 
23
# Create a dictionary for the rabbitmq configuration.
 
24
rabbitmq_configuration = {
 
25
    'stats_cron_schedule': '*/1 * * * *'
 
26
}
 
27
d = amulet.Deployment(series='trusty')
 
28
# Add the rabbitmq-server charm to the deployment.
 
29
d.add('rabbitmq-server')
 
30
# Configure options on the rabbitmq-server.
 
31
d.configure('rabbitmq-server', rabbitmq_configuration)
 
32
# Expose the server so we can connect.
 
33
d.expose('rabbitmq-server')
 
34
# XXX Remove charm= once this branch lands in the charm store
 
35
d.add('nrpe-external-master',
 
36
      charm='lp:~gnuoy/charms/trusty/nrpe/services-rewrite')
 
37
d.relate('rabbitmq-server:nrpe-external-master',
 
38
         'nrpe-external-master:nrpe-external-master')
 
39
 
 
40
try:
 
41
    # Execute the deployer with the current mapping.
 
42
    d.setup(timeout=seconds)
 
43
except amulet.helpers.TimeoutError:
 
44
    message = 'The environment did not setup in %d seconds.' % seconds
 
45
    # The SKIP status enables skip or fail the test based on configuration.
 
46
    amulet.raise_status(amulet.SKIP, msg=message)
 
47
except:
 
48
    raise
 
49
print('The rabbitmq-server has been successfully deployed and related '
 
50
      'to nrpe-external-master.')
 
51
 
 
52
###############################################################################
 
53
# # Verify nagios checks
 
54
###############################################################################
 
55
rabbitmq_sentry = d.sentry.unit['rabbitmq-server/0']
 
56
 
 
57
command = 'bash -c "$(egrep -oh /usr/local.* ' \
 
58
          '/etc/nagios/nrpe.d/check_rabbitmq.cfg)"'
 
59
print(command)
 
60
output, code = rabbitmq_sentry.run(command)
 
61
print(output)
 
62
if (code != 0):
 
63
    message = 'The ' + command + ' did not return the expected code of 0.'
 
64
    amulet.raise_status(amulet.FAIL, msg=message)
 
65
else:
 
66
    print('The rabbitmq-server check_rabbitmq is OK')
 
67
 
 
68
print('Sleeping 70 seconds to make sure the monitoring cron has run')
 
69
time.sleep(70)
 
70
 
 
71
command = 'bash -c "$(egrep -oh /usr/local.* ' \
 
72
          '/etc/nagios/nrpe.d/check_rabbitmq_queue.cfg)"'
 
73
print(command)
 
74
output, code = rabbitmq_sentry.run(command)
 
75
print(output)
 
76
if (code != 0):
 
77
    message = 'The ' + command + ' did not return the expected code of 0.'
 
78
    amulet.raise_status(amulet.FAIL, msg=message)
 
79
else:
 
80
    print('The rabbitmq-server check_rabbitmq_queue is OK')
 
81
 
 
82
# Success!
 
83
print('The rabbitmq-server passed the monitoring tests!')