3
#TODO - Discover what service mymonitors was designed for - as the charm store has nothing listed for this interface.
13
d = amulet.Deployment()
20
#TODO - configure nagios with SSL options in branch
21
# lp:~lazypower/charms/precise/nagios/ssl-everywhere
23
d.configure('nagios', {'extraconfig': '#amulet'})
24
d.configure('haproxy', {})
25
d.configure('mysql', {})
27
d.relate('nagios:website', 'haproxy:reverseproxy')
28
d.relate('nagios:monitors', 'mysql:monitors')
29
d.relate('nrpe:general-info', 'haproxy:juju-info')
30
d.relate('nrpe:monitors', 'nagios:monitors')
36
d.setup(timeout=seconds)
38
except amulet.helpers.TimeoutError:
39
amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
45
# Set relationship aliases
47
mysql_unit = d.sentry.unit['mysql/0']
48
nagios_unit = d.sentry.unit['nagios/0']
49
haproxy_unit = d.sentry.unit['haproxy/0']
51
# Fetch nagios private address through the relation data
52
sql_paddr = d.sentry.unit['nagios/0'].relation('monitors', 'mysql:monitors')['private-address']
55
# Mysql has a nice built in monitoring relationship with nagios
56
# Validate that we get the proper tables setup
57
def test_mysql_monitoring_connection():
58
validation_sql = "select * from information_schema.user_privileges where grantee like \\\"'monitors'%\\\";"
59
validation_command = "mysql -u root -p`cat /var/lib/mysql/mysql.passwd` -e \"%s\"" % validation_sql
60
output, code = mysql_unit.run(validation_command)
61
#We know that we need a GRANT USAGE permission for this to work properly
62
if output.find("USAGE") == -1:
63
amulet.raise_status(amulet.FAIL, msg="Missing GRANT on MySQL unit")
66
# We have an issue here. We cannot assign a sentry unit to a
67
# subordinate. This poses an interesting problem.
68
# validate that haproxy has an nrpe config, and *assume* its ok for now - needs
69
# some love otherwise.
70
def test_nrpe_monitor():
71
#On join the NRPE unit generates an allowed hosts config
72
ahosts = haproxy_unit.file_stat('/etc/nagios/nrpe.d/allowed.hosts.cfg')
74
amulet.raise_status(amulet.FAIL, msg="Missing nrpe config")
75
running, code = haproxy_unit.run('service nagios-nrpe-server status')
76
if running.find('running') == -1:
77
amulet.raise_status(amulet.FAIL, msg="Failed to find running nrpe daemon")
80
#Validate that the web interface has htpasswd authentication
81
def test_web_interface_is_protected():
82
r = requests.get("http://%s/nagios3/" % nagios_unit.info['public-address'])
83
if r.status_code != 401:
84
amulet.raise_status(amulet.FAIL, msg="Web Interface open to the world")
85
#validate that our configured admin is valid
86
nagpwd = nagios_unit.file_contents('/var/lib/juju/nagios.passwd').strip()
87
r = requests.get("http://%s/nagios3/" % nagios_unit.info['public-address'],
88
auth=('nagiosadmin', nagpwd))
89
if r.status_code != 200:
90
amulet.raise_status(amulet.FAIL, msg="Web Admin login failed")
93
def text_extra_config_is_written():
94
extracfg = nagios_unit.file_stat('/etc/nagios3/conf.d/extra.cfg')
96
amulet.raise_status(amulet.FAIL, msg="Extra Config missing")
97
extracont = nagios_unit.file_contents('/etc/nagios3/conf.d/extra.cfg')
98
if extracont.find('#amulet') == -1:
99
amulet.raise_status(amulet.FAIL, msg="Missing extra config contents")
101
#TODO validate SQLite database entries for units
104
test_mysql_monitoring_connection()
106
test_web_interface_is_protected()