~stub/charms/xenial/nrpe/py3

« back to all changes in this revision

Viewing changes to tests/11-monitors-configurations

  • Committer: Marco Ceppi
  • Date: 2015-03-24 18:13:50 UTC
  • mfrom: (34.1.2 all-tests)
  • Revision ID: marco@ceppi.net-20150324181350-jos78bmi2xe7vf0l
[nicopace] Integrated all tests for nrpe in one branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
 
 
3
import amulet
 
4
import requests
 
5
 
 
6
seconds = 20000
 
7
 
 
8
d = amulet.Deployment(series='trusty')
 
9
 
 
10
d.add('nagios')
 
11
d.add('mysql')
 
12
d.add('nrpe')
 
13
 
 
14
d.relate('nagios:monitors', 'mysql:monitors')
 
15
d.relate('nrpe:monitors', 'nagios:monitors')
 
16
d.relate('nrpe:local-monitors', 'mysql:local-monitors')
 
17
 
 
18
d.expose('nagios')
 
19
 
 
20
try:
 
21
    d.setup(timeout=seconds)
 
22
except amulet.helpers.TimeoutError:
 
23
    amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
 
24
except:
 
25
    raise
 
26
 
 
27
 
 
28
##
 
29
# Set relationship aliases
 
30
##
 
31
mysql_unit = d.sentry.unit['mysql/0']
 
32
nagios_unit = d.sentry.unit['nagios/0']
 
33
 
 
34
 
 
35
def test_nrpe_monitors_config():
 
36
    # look for procrunning in nrpe config
 
37
    try:
 
38
        mysql_unit.file_contents('/etc/nagios/nrpe.d/procrunning_mysqld.cfg')
 
39
    except IOError as e:
 
40
        amulet.raise_status(amulet.ERROR,
 
41
                            msg="procrunning config not found. Error:" +
 
42
                            e.args[1])
 
43
 
 
44
 
 
45
def test_nagios_monitors_response():
 
46
    # look for mysql_database requests
 
47
    nagpwd = nagios_unit.file_contents('/var/lib/juju/nagios.passwd').strip()
 
48
    host_url = ("http://%s/cgi-bin/nagios3/status.cgi?"
 
49
                "host=mysql-0")
 
50
    r = requests.get(host_url % nagios_unit.info['public-address'],
 
51
                     auth=('nagiosadmin', nagpwd))
 
52
    if not r.text.find('mysql-0-basic'):
 
53
        amulet.raise_status(amulet.ERROR,
 
54
                            msg='Nagios is not monitoring the' +
 
55
                            ' hosts it supposed to.')
 
56
 
 
57
test_nrpe_monitors_config()
 
58
test_nagios_monitors_response()