~brad-marshall/charms/trusty/nagios/add-livestatus

« back to all changes in this revision

Viewing changes to hooks/upgrade-charm

  • Committer: Brad Marshall
  • Date: 2015-04-10 03:58:29 UTC
  • Revision ID: brad.marshall@canonical.com-20150410035829-njl3097igadm0xh1
[bradm] Add livestatus support

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
import base64
6
6
from jinja2 import Template
7
7
import os
 
8
import pwd
 
9
import grp
8
10
import shutil
9
11
import subprocess
10
12
from charmhelpers.contrib import ssl
11
13
from charmhelpers.core import hookenv, host
 
14
from charmhelpers.fetch import apt_install
12
15
 
13
16
from common import update_localhost
14
17
 
15
18
# Gather facts
16
19
legacy_relations = hookenv.config('legacy')
17
20
extra_config = hookenv.config('extraconfig')
 
21
enable_livestatus = hookenv.config('enable_livestatus')
 
22
livestatus_path = hookenv.config('livestatus_path')
18
23
ssl_config = hookenv.config('ssl')
19
24
charm_dir = os.environ['CHARM_DIR']
20
25
cert_domain = hookenv.unit_get('public-address')
43
48
    if extra_config is not None:
44
49
        host.write_file('/etc/nagios3/conf.d/extra.cfg', extra_config)
45
50
 
 
51
def livestatus_config():
 
52
    livestatus_str = "broker_module=/usr/lib/check_mk/livestatus.o /var/lib/nagios3/livestatus/socket"
 
53
    if enable_livestatus:
 
54
        uid = pwd.getpwnam("nagios").pw_uid
 
55
        gid = grp.getgrnam("nagios").gr_gid
 
56
        livestatus_dir = os.path.dirname(livestatus_path)
 
57
        if not os.path.exists(livestatus_dir):
 
58
            os.makedirs(livestatus_dir)
 
59
            os.chown(livestatus_dir, uid, gid)
 
60
        # THIS CONFIG MUST BE IN THE nagios.cfg FILE, NOT AN EXTERNAL ONE
 
61
        # FIX THIS BEFORE TRYING AGAIN
 
62
        host.write_file('/etc/nagios3/conf.d/livestatus.cfg', livestatus_str)
 
63
        apt_install('check-mk-livestatus')
 
64
 
46
65
 
47
66
def ssl_configured():
48
67
    allowed_options = ["on", "only"]
143
162
 
144
163
warn_legacy_relations()
145
164
write_extra_config()
 
165
livestatus_config()
146
166
if ssl_configured():
147
167
    enable_ssl()
148
168
update_apache()