~thomir-deactivatedaccount/charms/trusty/tanuki-spec-manager/trunk-fix-ng-alert

« back to all changes in this revision

Viewing changes to hooks/actions.py

  • Committer: Thomi Richards
  • Date: 2015-09-22 04:32:19 UTC
  • Revision ID: thomi.richards@canonical.com-20150922043219-sjo4xlny8jsc26ur
Fix race condition in nagios check for store poller.

Show diffs side-by-side

added added

removed removed

Lines of Context:
325
325
 
326
326
    # Builds a nagios check command to verify `store-poller` log file age
327
327
    # according the service configuration.
328
 
    environment = hookenv.Config()['environment']
329
328
    log_path = os.path.join(LOG_DIR, 'store-poller.log')
330
329
    max_age_seconds = int(config['store_poller_nagios_file_age_max_minutes']) * 60
331
330
    check_cmd = "/usr/lib/nagios/plugins/check_file_age -w {0} -c {0} -f {1}".format(
334
333
    )
335
334
 
336
335
    # If `store-poller` cronscript is enabled in this unit, ensure the log file
337
 
    # exists. Otherwise 'negate' standard check (verifies cronscript is not running). 
 
336
    # exists. Otherwise 'negate' standard check (verifies cronscript is not running).
338
337
    config_unit = config.get('store_poller_unit')
339
338
    local_unit = int(hookenv.local_unit().split('/')[-1])
340
339
    if local_unit == config_unit:
341
 
        host.write_file(log_path,"", "www-data", "www-data", perms=0o660)
 
340
        host.write_file(log_path, "", "www-data", "www-data", perms=0o660)
342
341
    else:
 
342
        # The poller might have been run on this unit before, possibly before
 
343
        # the timeout period. To avoid spurious alerts, we rename the file if
 
344
        # it exists.
 
345
        if os.path.exists(log_path):
 
346
            os.rename(log_path, log_path + ".old")
343
347
        check_cmd = "negate {}".format(check_cmd)
344
348
 
345
349
    nrpe_compat.add_check(