~roadmr/capomastro/charm-force-python-django-version-again

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash

set -xev

. inc/common

if [ -x "/usr/local/lib/nagios/plugins/capomastro_status.sh" ]; then
	juju-log "Updating the NRPE setup..."

	# we know it's a lot to ask below but we tried to create
	# a very opinionated charm by providing hardcoded values
	# that possibly no one would need to change, hence we'll
	# have a less cluttered config.yaml file
	export t_nagios_context="$(config-get nagios_context)"
	export t_nagios_servicegroup="$t_nagios_context"
	export t_nagios_hostname="${t_nagios_context}-${unit_name//\//-}"

	# Clean slate
	rm -f /var/lib/nagios/export/service_*

	# check for the actual web page being available or not
	export t_nagios_service_description="Capomastro build server"
	export t_nagios_command_name="check_${t_nagios_context}_capomastro_app"
	export t_nagios_command="/usr/lib/nagios/plugins/check_http -I ${private_address} -p ${port} -H ${sitename} -u / -e '302 FOUND' -u / -d 'http://${sitename}/accounts/login/'"
	
	cheetah fill --env -p templates/nrpe_command_file.tmpl > /etc/nagios/nrpe.d/${t_nagios_command_name}.cfg
	cheetah fill --env -p templates/nrpe_service_file.tmpl > /var/lib/nagios/export/service_${t_nagios_hostname}_${t_nagios_command_name}.cfg

	# check the status of the celery workers
	export t_nagios_service_description="Capomastro celery workers"
	export t_nagios_command_name="check_${t_nagios_context}_capomastro_celery"
	export t_nagios_command="/usr/local/lib/nagios/plugins/check_status_file.sh /var/log/capomastro/capomastro-celery-status"

	cheetah fill --env -p templates/nrpe_command_file.tmpl > /etc/nagios/nrpe.d/${t_nagios_command_name}.cfg
	cheetah fill --env -p templates/nrpe_service_file.tmpl > /var/lib/nagios/export/service_${t_nagios_hostname}_${t_nagios_command_name}.cfg

	# make it run with some frequency so nagios can check it
	cheetah fill --env -p templates/nrpe_status_cron.tmpl > /etc/cron.d/capomastro-status

	# so we have a first status file for the mojo spec, no need for cron to wait 5min
	/usr/local/lib/nagios/plugins/capomastro_status.sh

	service nagios-nrpe-server reload
else
	juju-log "Skipping NPRE config, plugins directory not found"
fi