~verterok/charms/trusty/mongodb/fix-data_directory-migration

« back to all changes in this revision

Viewing changes to hooks/hooks.py

  • Committer: Marco Ceppi
  • Date: 2015-03-24 19:55:48 UTC
  • mfrom: (66.1.3 mongodb)
  • Revision ID: marco@ceppi.net-20150324195548-qms64mwxd1w70vhe
[brad-marshall] Adds nrpe-external-master interface and adds basic nrpe checks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    relations_of_type,
46
46
    relation_id,
47
47
    relation_ids,
 
48
    local_unit,
48
49
    Hooks,
49
50
    DEBUG,
50
51
    WARNING,
73
74
    apt_install("python-lockfile", fatal=True)
74
75
    from lockfile import FileLock
75
76
 
 
77
from charmhelpers.contrib.charmsupport.nrpe import NRPE
 
78
 
76
79
hooks = Hooks()
77
80
 
78
81
###############################################################################
1059
1062
    else:
1060
1063
        open_port(config_data['mongos_port'])
1061
1064
 
 
1065
    update_nrpe_config()
 
1066
 
1062
1067
    print "About to leave config_changed"
1063
1068
    return(True)
1064
1069
 
1366
1371
    update_file(default_mongos_list, '\n'.join(config_servers))
1367
1372
 
1368
1373
 
 
1374
@hooks.hook('nrpe-external-master-relation-joined',
 
1375
            'nrpe-external-master-relation-changed')
 
1376
def update_nrpe_config():
 
1377
    # Find out if nrpe set nagios_hostname
 
1378
    hostname = None
 
1379
    host_context = None
 
1380
    for rel in relations_of_type('nrpe-external-master'):
 
1381
        if 'nagios_hostname' in rel:
 
1382
            hostname = rel['nagios_hostname']
 
1383
            host_context = rel['nagios_host_context']
 
1384
            break
 
1385
    nrpe = NRPE(hostname=hostname)
 
1386
    apt_install('python-dbus')
 
1387
 
 
1388
    if host_context:
 
1389
        current_unit = "%s:%s" % (host_context, local_unit())
 
1390
    else:
 
1391
        current_unit = local_unit()
 
1392
 
 
1393
    nrpe.add_check(
 
1394
        shortname='mongodb',
 
1395
        description='process check {%s}' % current_unit,
 
1396
        check_cmd='check_upstart_job mongodb',
 
1397
        )
 
1398
 
 
1399
    nrpe.write()
 
1400
 
 
1401
 
1369
1402
def run(command, exit_on_error=True):
1370
1403
    '''Run a command and return the output.'''
1371
1404
    try: