def ajax_all(self): self.nexus_init() nodes_list = get_bridge_connections(self.config['bridge_host']) results = [] for node_id in nodes_list: app.logger.info(node_id) data = fetch_data(node_id, self.config) res = assess_data(data, self.config) if res.error: color = nexus.RED elif res.node_health != nexus.GREEN: color = nexus.YELLOW else: color = nexus.GREEN results.append((res.node_id, color, res.error or res.summary)) return render_template('ajax_search.html', results=results, nexus=nexus)
def ajax_index(self): c = sqlite3.connect(self.db_path).cursor() nodes_list = get_bridge_connections(self.config['bridge_host']) oldest_cache = arrow.utcnow() nodes = [] for node_id in sorted(nodes_list): c.execute('SELECT * FROM Cache WHERE node_id=?', [node_id]) for node_id, node_health, summary, cache_time in c.fetchall(): cache_time = arrow.get(cache_time, 'YYYY-MM-DD HH:mm:ss') oldest_cache = min(cache_time, oldest_cache) node_health = { 'RED': nexus.RED, 'YELLOW': nexus.YELLOW, 'GREEN': nexus.GREEN, 'FAIL': nexus.RED }[node_health] nodes.append((node_id, node_health, summary)) return render_template('ajax_index.html', nodes=nodes, oldest_cache=oldest_cache, nexus=nexus)
sys.path.append(PARENT) from monitor import get_bridge_connections with open(os.path.expanduser('~/piloteur-config/monitor/config.json')) as f: config = json.load(f) for _ in range(5): try: nexus.init(config) except paramiko.SSHException: continue break else: exit(1) online_nodes = get_bridge_connections(config['bridge_host']) DIR = os.path.dirname(os.path.abspath(__file__)) db_path = os.path.join(DIR, '..', 'cache.db') c = sqlite3.connect(db_path).cursor() nodes = [] c.execute('SELECT * FROM Cache') for node_id, node_health, summary, cache_time in c.fetchall(): nodes.append({ "node_id": node_id, "node_health": node_health, "summary": summary, "cache_time": cache_time, "online": node_id in online_nodes,
DIR = os.path.dirname(os.path.realpath(__file__)) with open(os.path.expanduser('~/piloteur-config/monitor/config.json')) as f: config = json.load(f) for _ in range(5): try: init(config) except paramiko.SSHException: continue break else: exit(1) nodes_list = get_bridge_connections(config['bridge_host']) results = [] for node_id in nodes_list: data = fetch_data(node_id, config) res = assess_data(data, config) if res.error: color = 'RED' elif res.node_health != GREEN: color = 'YELLOW' else: color = 'GREEN' print('[{}] {}... {}'.format(color, res.node_id, res.error or res.summary))