~verterok/charms/trusty/tanuki-spec-manager/service-name-for-website-relation

« back to all changes in this revision

Viewing changes to hooks/actions.py

  • Committer: Celso Providelo
  • Date: 2015-09-21 14:51:30 UTC
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: celso.providelo@canonical.com-20150921145130-fgvfq569kwmsuncr
Negate store-poller nagios check when it gets disabled.

Show diffs side-by-side

added added

removed removed

Lines of Context:
323
323
        check_cmd="/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -p 8000 -e ' 200 OK' -u '/nagios/postgres'",
324
324
    )
325
325
 
 
326
    # Builds a nagios check command to verify `store-poller` log file age
 
327
    # according the service configuration.
 
328
    environment = hookenv.Config()['environment']
 
329
    log_path = os.path.join(LOG_DIR, 'store-poller.log')
 
330
    max_age_seconds = int(config['store_poller_nagios_file_age_max_minutes']) * 60
 
331
    check_cmd = "/usr/lib/nagios/plugins/check_file_age -w {0} -c {0} -f {1}".format(
 
332
        max_age_seconds,
 
333
        log_path,
 
334
    )
 
335
 
 
336
    # If `store-poller` cronscript is enabled in this unit, ensure the log file
 
337
    # exists. Otherwise 'negate' standard check (verifies cronscript is not running). 
326
338
    config_unit = config.get('store_poller_unit')
327
339
    local_unit = int(hookenv.local_unit().split('/')[-1])
328
 
 
329
340
    if local_unit == config_unit:
330
 
        environment = hookenv.Config()['environment']
331
 
        log_path = os.path.join(LOG_DIR, 'store-poller.log')
332
 
        # Create the file now, so the nagios check doesn't fail right after
333
 
        # we've completed the deployment.
334
341
        host.write_file(log_path,"", "www-data", "www-data", perms=0o660)
335
 
        max_age_seconds = int(config['store_poller_nagios_file_age_max_minutes']) * 60
336
 
        nrpe_compat.add_check(
337
 
            shortname="store_poller_check",
338
 
            description="Store poller check.",
339
 
            check_cmd="/usr/lib/nagios/plugins/check_file_age -w {0} -c {0} -f {1}".format(
340
 
                max_age_seconds,
341
 
                log_path,
342
 
            )
343
 
        )
 
342
    else:
 
343
        check_cmd = "negate {}".format(check_cmd)
 
344
 
 
345
    nrpe_compat.add_check(
 
346
        shortname="store_poller_check",
 
347
        description="Store poller check.",
 
348
        check_cmd=check_cmd
 
349
    )
 
350
 
344
351
    nrpe_compat.write()