Merge lp:~rcj/charms/precise/nrpe/trunk into lp:charms/nrpe

Proposed by Robert C Jennings
Status: Merged
Merged at revision: 35
Proposed branch: lp:~rcj/charms/precise/nrpe/trunk
Merge into: lp:charms/nrpe
Diff against target: 427 lines (+203/-80)
8 files modified
README.md (+30/-1)
hooks/config-changed (+19/-14)
hooks/local-monitors-relation-changed (+7/-3)
hooks/recursive_dictionary.py (+7/-6)
tests/00-setup (+1/-1)
tests/10-monitors (+64/-0)
tests/20-local_monitors (+75/-0)
tests/99-autogen (+0/-55)
To merge this branch: bzr merge lp:~rcj/charms/precise/nrpe/trunk
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Adam Israel (community) Approve
Robert C Jennings (community) Needs Resubmitting
Review Queue (community) automated testing Needs Fixing
Review via email: mp+235380@code.launchpad.net

Description of the change

nrpe charm pep8/pylint cleanup and additional testing

To post a comment you must log in.
Revision history for this message
Review Queue (review-queue) wrote :

This items has failed automated testing! Results available here http://reports.vapour.ws/charm-tests/charm-bundle-test-1051-results

review: Needs Fixing (automated testing)
Revision history for this message
Review Queue (review-queue) wrote :

This items has failed automated testing! Results available here http://reports.vapour.ws/charm-tests/charm-bundle-test-1197-results

review: Needs Fixing (automated testing)
Revision history for this message
Adam Israel (aisrael) wrote :

Hi Robert,

Thanks for all of your efforts getting this charm cleaned up. I had the opportunity to review the charm today, and wanted to provide some feedback.

I attempted to run the tests both manually, and how the automated testing runs (using bundletester).

Bundletester, run from the charm directory, failed:

$ bundletester -l DEBUG
...
DEBUG:runner:call ['/vagrant/precise/nrpe/tests/20-local_monitors']
DEBUG:runner:
Traceback (most recent call last):
  File "/vagrant/precise/nrpe/tests/20-local_monitors", line 25, in <module>
    with open('../test-monitors.yaml', 'r') as monitors_file:
FileNotFoundError: [Errno 2] No such file or directory: '../test-monitors.yaml'

DEBUG:runner:Exit Code: 1
    20-local_monitors

The 'test-monitors.yaml' file exists in the charm root, but with bundletester run from the charm root, I suspect it's checking for that file outside of the charm, instead of relative to the test script.

Next, I reset my environment and ran the tests by hand. I still encountered an error running 20-local_monitors, however.

$ ./20-local_monitors
2014-10-29 16:02:31 Starting deployment of local
2014-10-29 16:02:31 Deploying services...
2014-10-29 16:02:38 Adding relations...
2014-10-29 16:02:39 Adding relation nrpe:local-monitors <-> apache2:local-monitors
2014-10-29 16:03:39 Deployment complete in 69.14 seconds
Expected file on nrpe not found: /etc/nagios/nrpe.d/check_true.cfg

review: Needs Fixing
Revision history for this message
Adam Israel (aisrael) wrote :

Here are some additional details that might help:

$ juju status
environment: local
machines:
  "0":
    agent-state: started
    agent-version: 1.20.10.1
    dns-name: localhost
    instance-id: localhost
    series: trusty
    state-server-member-status: has-vote
  "1":
    agent-state: started
    agent-version: 1.20.10.1
    dns-name: 10.0.3.171
    instance-id: vagrant-local-machine-1
    series: precise
    hardware: arch=amd64
  "2":
    agent-state: started
    agent-version: 1.20.10.1
    dns-name: 10.0.3.222
    instance-id: vagrant-local-machine-2
    series: precise
    hardware: arch=amd64
services:
  apache2:
    charm: cs:precise/apache2-25
    exposed: false
    relations:
      juju-info:
      - nrpe
      local-monitors:
      - nrpe
    units:
      apache2/0:
        agent-state: started
        agent-version: 1.20.10.1
        machine: "1"
        public-address: 10.0.3.171
        subordinates:
          nrpe/0:
            upgrading-from: cs:precise/nrpe-7
            agent-state: started
            agent-version: 1.20.10.1
            public-address: 10.0.3.171
  nagios:
    charm: cs:precise/nagios-10
    exposed: false
    relations:
      monitors:
      - nrpe
    units:
      nagios/0:
        agent-state: started
        agent-version: 1.20.10.1
        machine: "2"
        open-ports:
        - 80/tcp
        public-address: 10.0.3.222
  nrpe:
    charm: cs:precise/nrpe-7
    exposed: false
    relations:
      general-info:
      - apache2
      local-monitors:
      - apache2
      monitors:
      - nagios
    subordinate-to:
    - apache2

ubuntu@vagrant-local-machine-1:/etc/nagios/nrpe.d$ ls -la
total 16
drwxr-xr-x 1 root root 114 Oct 29 16:00 .
drwxr-xr-x 1 root root 56 Oct 29 16:00 ..
-rwxr----- 1 root root 25 Oct 29 16:00 allowed.hosts.cfg
-rw-r--r-- 1 root root 144 Oct 29 16:00 base-monitors.cfg
-rw-r--r-- 1 root root 96 Oct 29 16:02 check_mem.cfg
-rw-r--r-- 1 root root 67 Oct 29 16:02 disk__.cfg

Revision history for this message
Review Queue (review-queue) wrote :

This items has failed automated testing! Results available here http://reports.vapour.ws/charm-tests/charm-bundle-test-10371-results

review: Needs Fixing (automated testing)
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

I'm moving this back in to "work in progress" When you're ready for another review please move this merge to "needs review"

review: Needs Information
Revision history for this message
Robert C Jennings (rcj) wrote :

I have corrected the file path issue and rebased against the current tree.

Revision history for this message
Robert C Jennings (rcj) wrote :

Please review with latest changes and retest. Thank you.

review: Needs Resubmitting
Revision history for this message
Adam Israel (aisrael) wrote :

Hi Robert,

I took a look at this late last week. I'm happy to report that it merges cleanly and all tests are passing, against local and amazon providers. Thanks again for all of your efforts on this!

+1

review: Approve
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

Merged

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== renamed file 'README' => 'README.md'
--- README 2012-07-26 23:39:54 +0000
+++ README.md 2015-04-02 19:42:00 +0000
@@ -1,10 +1,39 @@
1# Overview
2
1This charm provides an nrpe subordinate to integrate with nagios logging.3This charm provides an nrpe subordinate to integrate with nagios logging.
24
3Adding the charm as a subordinate to a service will run an nrpe server5Adding the charm as a subordinate to a service will run an nrpe server
4on the unit and allow for nagios to query the service using that server.6on the unit and allow for nagios to query the service using that server.
57
8# Usage
9
10Deploy the charm as a subordinate of an existing service. In this example
11we will deploy a Trusty version of the Apache2 charm and add nrpe to it.
12The relationship, `general-monitors`, provides basic monitoring data.
13
14 juju deploy nagios
15 juju deploy cs:precise/apache2
16 juju deploy cs:precise/nrpe
17 juju add-relation nrpe:general-monitors apache2:juju-info
18 juju add-relation nrpe:monitors nagios:monitors
19
20In this second example we will use the `local-monitors` relationship with
21Apache2. The Apache2 charm provides a `local-monitors` relationship that
22will add additional monitoring checks.
23
24 juju deploy nagios
25 juju deploy cs:precise/apache2
26 juju deploy cs:precise/nrpe
27 juju add-relation nrpe:local-monitors apache2: local-monitors
28 juju add-relation nrpe:monitors nagios:monitors
29
30Note that a series for nagios is not specified as nrpe can communicate
31with nagios charms of different series.
32
33# Charm relationship data
34
6The service provides a 'local-monitors' container scoped interface35The service provides a 'local-monitors' container scoped interface
7to define the plugins that the nrpe server can use. The charm should36to define the plug-ins that the nrpe server can use. The charm should
8'relation-set monitors=monitors' with a monitors.yaml in the same37'relation-set monitors=monitors' with a monitors.yaml in the same
9format as the 'monitors' relation seen in the nagios charm. This will38format as the 'monitors' relation seen in the nagios charm. This will
10be merged with the base monitors and any monitors configured via the39be merged with the base monitors and any monitors configured via the
1140
=== modified file 'hooks/config-changed'
--- hooks/config-changed 2012-07-26 23:37:43 +0000
+++ hooks/config-changed 2015-04-02 19:42:00 +0000
@@ -11,13 +11,16 @@
1111
12PLUGIN_PATH = '/usr/lib/nagios/plugins'12PLUGIN_PATH = '/usr/lib/nagios/plugins'
1313
14base_yaml = RecursiveDictionary(yaml.safe_load(open('base-monitors.yaml','r')))14with open('base-monitors.yaml', 'r') as base_monitors:
15 base_yaml = RecursiveDictionary(yaml.safe_load(base_monitors))
15yamls = []16yamls = []
16if len(sys.argv) > 1:17if len(sys.argv) > 1:
17 for f in sys.argv[1:]:18 for f in sys.argv[1:]:
18 yamls.append(yaml.safe_load(open(f)))19 yamls.append(yaml.safe_load(open(f)))
19else:20else:
20 cmon = json.loads(subprocess.check_output(['config-get','monitors','--format=json']))21 cmon = json.loads(subprocess.check_output(['config-get',
22 'monitors',
23 '--format=json']))
21 if cmon is not None and type(cmon) != dict:24 if cmon is not None and type(cmon) != dict:
22 cmon = yaml.safe_load(cmon)25 cmon = yaml.safe_load(cmon)
23 if cmon is not None:26 if cmon is not None:
@@ -32,25 +35,27 @@
3235
33base_yaml = dict(base_yaml)36base_yaml = dict(base_yaml)
3437
38
35def make_command(mclass, mon):39def make_command(mclass, mon):
36 cmd_name = 'check_true'40 cmd_name = 'check_true'
37 cmd_line = ['/usr/bin/true']41 cmd_line = ['/usr/bin/true']
3842
39 if mclass == 'procrunning' or mclass == 'processcount':43 if mclass == 'procrunning' or mclass == 'processcount':
40 executable = mon.get('executable','')44 executable = mon.get('executable', '')
41 cmd_name = '%s_%s' % (mclass, executable.replace('/','_'))45 cmd_name = '%s_%s' % (mclass, executable.replace('/', '_'))
42 range_arg = '%s:%s' % (mon.get('min',''), mon.get('max',''))46 range_arg = '%s:%s' % (mon.get('min', ''), mon.get('max', ''))
43 cmd = os.path.join(PLUGIN_PATH, 'check_procs')47 cmd = os.path.join(PLUGIN_PATH, 'check_procs')
44 cmd_line = [cmd,'-w',range_arg,'-c',range_arg]48 cmd_line = [cmd, '-w', range_arg, '-c', range_arg]
45 if executable:49 if executable:
46 cmd_line.extend(('-C',executable))50 cmd_line.extend(('-C', executable))
47 elif mclass == 'mem':51 elif mclass == 'mem':
48 cmd_name = 'check_mem'52 cmd_name = 'check_mem'
49 cmd = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),53 cmd = os.path.abspath(os.path.join(
50 '..', 'plugins', 'check_mem.pl'))54 os.path.dirname(os.path.abspath(__file__)),
55 '..', 'plugins', 'check_mem.pl'))
51 cmd_line = [cmd, '-C', '-u', '-w', '85', '-c', '90']56 cmd_line = [cmd, '-C', '-u', '-w', '85', '-c', '90']
52 elif mclass == 'disk':57 elif mclass == 'disk':
53 path = mon.get('path','/')58 path = mon.get('path', '/')
54 cmd_name = 'disk_%s' % (path.replace('/', '_'))59 cmd_name = 'disk_%s' % (path.replace('/', '_'))
55 cmd = os.path.join(PLUGIN_PATH, 'check_disk')60 cmd = os.path.join(PLUGIN_PATH, 'check_disk')
56 cmd_line = [cmd, '-w', '20', '-c', '10', '-p', path]61 cmd_line = [cmd, '-w', '20', '-c', '10', '-p', path]
@@ -65,8 +70,8 @@
65 return cmd_name70 return cmd_name
6671
67# Now transform local's into remote nrpe's72# Now transform local's into remote nrpe's
68local = base_yaml['monitors'].get('local',{})73local = base_yaml['monitors'].get('local', {})
69out_remotes = base_yaml['monitors'].get('remote',{})74out_remotes = base_yaml['monitors'].get('remote', {})
70for mclass, mons in local.iteritems():75for mclass, mons in local.iteritems():
71 if 'nrpe' not in out_remotes:76 if 'nrpe' not in out_remotes:
72 out_remotes['nrpe'] = {}77 out_remotes['nrpe'] = {}
@@ -93,7 +98,7 @@
93 print yaml.safe_dump(base_yaml)98 print yaml.safe_dump(base_yaml)
94 sys.exit(0)99 sys.exit(0)
95100
96with open('monitors.yaml','w') as end_yaml:101with open('monitors.yaml', 'w') as end_yaml:
97 yaml.safe_dump(base_yaml, end_yaml)102 yaml.safe_dump(base_yaml, end_yaml)
98103
99subprocess.call(['service','nagios-nrpe-server','restart'])104subprocess.call(['service', 'nagios-nrpe-server', 'restart'])
100105
=== modified file 'hooks/local-monitors-relation-changed'
--- hooks/local-monitors-relation-changed 2012-07-27 00:18:58 +0000
+++ hooks/local-monitors-relation-changed 2015-04-02 19:42:00 +0000
@@ -9,13 +9,17 @@
9 print 'Need JUJU_REMOTE_UNIT to run'9 print 'Need JUJU_REMOTE_UNIT to run'
10 sys.exit(0)10 sys.exit(0)
1111
12primary_id=os.environ['JUJU_REMOTE_UNIT'].replace('/','-')12primary_id = os.environ['JUJU_REMOTE_UNIT'].replace('/', '-')
13
13if not os.path.exists('data'):14if not os.path.exists('data'):
14 os.mkdir('data')15 os.mkdir('data')
15with open('data/primary_id','w') as primid:16with open('data/primary_id', 'w') as primid:
16 primid.write(primary_id)17 primid.write(primary_id)
1718
18monitors = json.loads(subprocess.check_output(['relation-get','--format=json','monitors']))19monitors = json.loads(subprocess.check_output(['relation-get',
20 '--format=json',
21 'monitors']))
22
19if monitors is None or len(monitors) == 0:23if monitors is None or len(monitors) == 0:
20 sys.exit(0)24 sys.exit(0)
2125
2226
=== modified file 'hooks/recursive_dictionary.py'
--- hooks/recursive_dictionary.py 2012-07-04 19:04:20 +0000
+++ hooks/recursive_dictionary.py 2015-04-02 19:42:00 +0000
@@ -6,17 +6,17 @@
6# which makes it easier to deal with yaml dump/load6# which makes it easier to deal with yaml dump/load
7#7#
8# Copyright (c) 2009 Jannis Andrija Schnitzer8# Copyright (c) 2009 Jannis Andrija Schnitzer
9# 9#
10# Permission is hereby granted, free of charge, to any person obtaining a copy10# Permission is hereby granted, free of charge, to any person obtaining a copy
11# of this software and associated documentation files (the "Software"), to deal11# of this software and associated documentation files (the "Software"), to deal
12# in the Software without restriction, including without limitation the rights12# in the Software without restriction, including without limitation the rights
13# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell13# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14# copies of the Software, and to permit persons to whom the Software is14# copies of the Software, and to permit persons to whom the Software is
15# furnished to do so, subject to the following conditions:15# furnished to do so, subject to the following conditions:
16# 16#
17# The above copyright notice and this permission notice shall be included in17# The above copyright notice and this permission notice shall be included in
18# all copies or substantial portions of the Software.18# all copies or substantial portions of the Software.
19# 19#
20# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR20# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,21# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE22# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -27,6 +27,7 @@
2727
28__author__ = 'jannis@itisme.org (Jannis Andrija Schnitzer)'28__author__ = 'jannis@itisme.org (Jannis Andrija Schnitzer)'
2929
30
30class RecursiveDictionary(dict):31class RecursiveDictionary(dict):
31 """RecursiveDictionary provides the methods rec_update and iter_rec_update32 """RecursiveDictionary provides the methods rec_update and iter_rec_update
32 that can be used to update member dictionaries rather than overwriting33 that can be used to update member dictionaries rather than overwriting
@@ -34,7 +35,7 @@
34 def rec_update(self, other, **third):35 def rec_update(self, other, **third):
35 """Recursively update the dictionary with the contents of other and36 """Recursively update the dictionary with the contents of other and
36 third like dict.update() does - but don't overwrite sub-dictionaries.37 third like dict.update() does - but don't overwrite sub-dictionaries.
37 38
38 Example:39 Example:
39 >>> d = RecursiveDictionary({'foo': {'bar': 42}})40 >>> d = RecursiveDictionary({'foo': {'bar': 42}})
40 >>> d.rec_update({'foo': {'baz': 36}})41 >>> d.rec_update({'foo': {'baz': 36}})
@@ -47,7 +48,7 @@
47 iterator = other48 iterator = other
48 self.iter_rec_update(iterator)49 self.iter_rec_update(iterator)
49 self.iter_rec_update(third.iteritems())50 self.iter_rec_update(third.iteritems())
50 51
51 def iter_rec_update(self, iterator):52 def iter_rec_update(self, iterator):
52 for (key, value) in iterator:53 for (key, value) in iterator:
53 if key in self and \54 if key in self and \
@@ -58,6 +59,6 @@
58 self[key] = dict(self[key])59 self[key] = dict(self[key])
59 else:60 else:
60 self[key] = value61 self[key] = value
61 62
62 def __repr__(self):63 def __repr__(self):
63 return super(self.__class__, self).__repr__()64 return super(self.__class__, self).__repr__()
6465
=== modified file 'tests/00-setup'
--- tests/00-setup 2014-11-06 21:21:58 +0000
+++ tests/00-setup 2015-04-02 19:42:00 +0000
@@ -2,4 +2,4 @@
22
3sudo add-apt-repository ppa:juju/stable -y3sudo add-apt-repository ppa:juju/stable -y
4sudo apt-get update4sudo apt-get update
5sudo apt-get install amulet python3-requests -y5sudo apt-get install amulet -y
66
=== added file 'tests/10-monitors'
--- tests/10-monitors 1970-01-01 00:00:00 +0000
+++ tests/10-monitors 2015-04-02 19:42:00 +0000
@@ -0,0 +1,64 @@
1#!/usr/bin/python3
2
3import amulet
4import subprocess
5
6
7def file_exists(unit, unit_name, filename):
8 try:
9 unit.file(filename)
10 except:
11 amulet.raise_status(amulet.FAIL,
12 'Expected file on {} not found: {}'.format(unit_name,
13 filename))
14
15
16d = amulet.Deployment(series='precise')
17
18# Use known charms for the deploy.
19d.add('nagios', charm='cs:precise/nagios-10')
20d.add('apache2', charm='cs:precise/apache2-25')
21
22# The nrpe charm will be subordinate to apache2.
23d.add('nrpe')
24
25# NRPE monitors apache2 and answers to Nagios
26d.relate('nrpe:monitors', 'nagios:monitors')
27d.relate('nrpe:general-info', 'apache2:juju-info')
28
29try:
30 d.setup(timeout=1200)
31 d.sentry.wait(timeout=1200)
32except amulet.helpers.TimeoutError:
33 amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
34except:
35 raise
36
37nrpe = d.sentry.unit['apache2/0']
38nagios = d.sentry.unit['nagios/0']
39
40# Check for nrpe configration files
41file_exists(nrpe, 'nrpe', '/etc/nagios/nrpe.d/base-monitors.cfg')
42file_exists(nrpe, 'nrpe', '/etc/nagios/nrpe.d/check_mem.cfg')
43file_exists(nrpe, 'nrpe', '/etc/nagios/nrpe.d/disk__.cfg')
44file_exists(nrpe, 'nrpe', '/etc/nagios/nrpe.d/allowed.hosts.cfg')
45
46# Check for nagios configration files from nrpe
47base_nagios = '/etc/nagios3/conf.d/commands'
48file_exists(nagios, 'nagios',
49 '/'.join((base_nagios, 'check_nrpe_H_HOSTADDRESS__ccheck_mem.cfg')))
50file_exists(nagios, 'nagios',
51 '/'.join((base_nagios, 'check_nrpe_H_HOSTADDRESS__cdisk__.cfg')))
52
53# Check that nagios knows the IP of of the unit with nrpe
54apache_private_address = subprocess.check_output(['juju', 'run',
55 '-e', d.juju_env,
56 '--unit', 'apache2/0',
57 'unit-get private-address'])
58nagios_charm_cfg = nagios.file_contents('/etc/nagios3/conf.d/charm.cfg')
59apache_private_address = apache_private_address.decode('utf-8')
60if nagios_charm_cfg.find(apache_private_address) == -1:
61 amulet.raise_status(amulet.FAIL,
62 msg='IP for nrpe host not in nagios config')
63
64amulet.raise_status(amulet.PASS, msg='monitors<->juju-info relationship pass')
065
=== added file 'tests/20-local_monitors'
--- tests/20-local_monitors 1970-01-01 00:00:00 +0000
+++ tests/20-local_monitors 2015-04-02 19:42:00 +0000
@@ -0,0 +1,75 @@
1#!/usr/bin/python3
2
3import amulet
4import subprocess
5
6
7def file_exists(unit, unit_name, filename):
8 try:
9 unit.file(filename)
10 except:
11 amulet.raise_status(amulet.FAIL,
12 'Expected file on {} not found: {}'.format(unit_name,
13 filename))
14
15
16d = amulet.Deployment(series='precise')
17
18# Use known charms for the deploy.
19d.add('nagios', charm='cs:precise/nagios-10')
20d.add('apache2', charm='cs:precise/apache2-25')
21
22# The nrpe charm will be subordinate to apache2.
23d.add('nrpe')
24
25with open('test-monitors.yaml', 'r') as monitors_file:
26 monitors_cfg = monitors_file.read()
27# Configure nrpe with some test monitors
28d.configure('nrpe', options={'monitors': monitors_cfg})
29
30# NRPE monitors apache2 and answers to Nagios
31d.relate('nrpe:monitors', 'nagios:monitors')
32d.relate('nrpe:local-monitors', 'apache2:local-monitors')
33
34try:
35 d.setup(timeout=1200)
36 d.sentry.wait(timeout=1200)
37except amulet.helpers.TimeoutError:
38 amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
39except:
40 raise
41
42nrpe = d.sentry.unit['apache2/0']
43nagios = d.sentry.unit['nagios/0']
44
45# Check for nrpe configration files
46file_exists(nrpe, 'nrpe', '/etc/nagios/nrpe.d/allowed.hosts.cfg')
47file_exists(nrpe, 'nrpe', '/etc/nagios/nrpe.d/base-monitors.cfg')
48file_exists(nrpe, 'nrpe', '/etc/nagios/nrpe.d/check_mem.cfg')
49file_exists(nrpe, 'nrpe', '/etc/nagios/nrpe.d/check_true.cfg')
50file_exists(nrpe, 'nrpe', '/etc/nagios/nrpe.d/disk__.cfg')
51file_exists(nrpe, 'nrpe', '/etc/nagios/nrpe.d/processcount_.cfg')
52
53# Check for nagios configration files from nrpe
54base_nagios = '/etc/nagios3/conf.d/commands'
55file_exists(nagios, 'nagios',
56 '/'.join((base_nagios, 'check_nrpe_H_HOSTADDRESS__ccheck_mem.cfg')))
57file_exists(nagios, 'nagios',
58 '/'.join((base_nagios, 'check_nrpe_H_HOSTADDRESS__ccheck_true.cfg')))
59file_exists(nagios, 'nagios',
60 '/'.join((base_nagios, 'check_nrpe_H_HOSTADDRESS__cdisk__.cfg')))
61file_exists(nagios, 'nagios',
62 '/'.join((base_nagios, 'check_nrpe_H_HOSTADDRESS__cprocesscount_.cfg')))
63
64# Check that nagios knows the IP of of the unit with nrpe
65apache_private_address = subprocess.check_output(['juju', 'run',
66 '-e', d.juju_env,
67 '--unit', 'apache2/0',
68 'unit-get private-address'])
69apache_private_address = apache_private_address.decode('utf-8')
70nagios_charm_cfg = nagios.file_contents('/etc/nagios3/conf.d/charm.cfg')
71if nagios_charm_cfg.find(apache_private_address) == -1:
72 amulet.raise_status(amulet.FAIL,
73 msg='IP for nrpe host not in nagios config')
74
75amulet.raise_status(amulet.PASS, msg='local-monitors relationship pass')
076
=== removed file 'tests/99-autogen'
--- tests/99-autogen 2014-11-20 19:45:39 +0000
+++ tests/99-autogen 1970-01-01 00:00:00 +0000
@@ -1,55 +0,0 @@
1#!/usr/bin/env python3
2
3import amulet
4import requests
5import unittest
6
7
8class TestDeployment(unittest.TestCase):
9 @classmethod
10 def setUpClass(cls):
11 cls.deployment = amulet.Deployment(series='precise')
12
13 cls.deployment.add('nrpe')
14 cls.deployment.add('nagios')
15 cls.deployment.add('mysql')
16 cls.deployment.add('ubuntu')
17 cls.deployment.relate('nrpe:monitors', 'nagios:monitors')
18 cls.deployment.relate('nrpe:local-monitors', 'mysql:local-monitors')
19 cls.deployment.relate('nrpe:general-info', 'ubuntu:juju-info')
20
21 try:
22 cls.deployment.setup(timeout=900)
23 cls.deployment.sentry.wait()
24 except amulet.helpers.TimeoutError:
25 amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
26 except:
27 raise
28
29 def test_case(self):
30 # Now you can use self.deployment.sentry.unit[UNIT] to address each of
31 # the units and perform more in-depth steps. You can also reference
32 # the first unit as self.unit.
33 # There are three test statuses that can be triggered with
34 # amulet.raise_status():
35 # - amulet.PASS
36 # - amulet.FAIL
37 # - amulet.SKIP
38 # Each unit has the following methods:
39 # - .info - An array of the information of that unit from Juju
40 # - .file(PATH) - Get the details of a file on that unit
41 # - .file_contents(PATH) - Get plain text output of PATH file from that unit
42 # - .directory(PATH) - Get details of directory
43 # - .directory_contents(PATH) - List files and folders in PATH on that unit
44 # - .relation(relation, service:rel) - Get relation data from return service
45 # add tests here to confirm service is up and working properly
46 # For example, to confirm that it has a functioning HTTP server:
47 # page = requests.get('http://{}'.format(self.unit.info['public-address']))
48 # page.raise_for_status()
49 # More information on writing Amulet tests can be found at:
50 # https://juju.ubuntu.com/docs/tools-amulet.html
51 pass
52
53
54if __name__ == '__main__':
55 unittest.main()

Subscribers

People subscribed via source and target branches