def list_machines(request): """Lists machines with monitoring. Returns a dict with uuid's as keys and machine dicts as values. """ return {machine.uuid: {'rules': [rule_id]} for machine in get_all_machines() for rule_id in machine.rules}
def update_collectd_conf(): """Update collectd.passwd and collectd.conf.local file. Reconstructs collectd.passwd adding a uuid/password entry for every machine. """ lines = ["%s: %s\n" % (machine.uuid, machine.collectd_password) for machine in get_all_machines()] with open(os.getcwd() + "/conf/collectd.passwd", "w") as f: if CAN_LOCK: fcntl.flock(f.fileno(), fcntl.LOCK_EX) f.writelines(lines)
def main(): pool = ThreadPool(config.ALERT_THREADS) while True: t0 = time() pool.map(check_machine, get_all_machines()) t1 = time() dt = t1 - t0 run_msg = "Run completed in %.1f seconds." % dt sleep_time = config.ALERT_PERIOD - dt if sleep_time > 0: log.info("%s Sleeping for %.1f seconds. ==========", run_msg, sleep_time) sleep(sleep_time) else: log.warning("%s Will not sleep because ALERT_PERIOD=%d ==========", run_msg, config.ALERT_PERIOD)
def update_collectd_conf(): """Update collectd.passwd and collectd.conf.local file. Reconstructs collectd.passwd adding a uuid/password entry for every machine. """ path = config.AUTH_FILE_PATH tmp_path = path + '.tmp' with open(tmp_path, 'w') as f: # write new auth file to temporary file if CAN_LOCK: # disallow concurrent rewrites of authfile fcntl.flock(f.fileno(), fcntl.LOCK_EX) f.writelines(["%s: %s\n" % (machine.uuid, machine.collectd_password) for machine in get_all_machines()]) os.rename(tmp_path, path) # move tmp file to authfile location os.utime(path, None) # touch authfile to notify bucky that it changed