def get_lisk_block_height(host): try: uri = host["host"] + "/api/node/status" response = requests.get(uri, timeout=10) if response.status_code == 200: json_response = response.json() return json_response["data"]["height"] elif response.status_code == 403: __print("403 block height, " + host["name"]) return 403 else: __print("500 block height, " + host["name"]) return 500 except Exception as e: __print('Unable to get block height ' + host["host"]) print(e) return 0
def get_block_height(host): try: uri = host["host"] + "/api/blocks/getHeight" response = requests.get(uri, timeout=5) if response.status_code == 200: json_response = response.json() if json_response["success"]: return json_response["height"] elif response.status_code == 403: __print("403 block height, " + host["name"]) return 403 else: __print("500 block height, " + host["name"]) return 500 except Exception as e: __print('Unable to get block height ' + host["host"]) print(e) return 0
def get_version(host): try: uri = host["host"] + "/api/peers/version" response = requests.get(uri, timeout=5) if response.status_code == 200: json_response = response.json() if json_response["success"]: return json_response["version"] elif response.status_code == 403: __print("403 version, " + host["name"]) return "403" else: __print("500 version, " + host["name"]) return "500" except Exception as e: __print('Unable to get version ' + host["host"]) print(e) return ""
def get_arkv2_block_height(host): try: uri = host["host"] + "/api/node/status" headers = {'Content-Type': 'application/json', 'API-Version': '2'} response = requests.get(uri, timeout=10, headers=headers) if response.status_code == 200: json_response = response.json() return json_response["data"]["now"] elif response.status_code == 403: __print("403 block height, " + host["name"]) return 403 else: __print("500 block height, " + host["name"]) return 500 except Exception as e: __print('Unable to get block height ' + host["host"]) print(e) return 0
def get_lisk_consensus_messages(status_result, max_block_height): block_height_consensus = 0 total_nodes = 0 for host in status_result["base_hosts"]: total_nodes += 1 try: if host.block_height == max_block_height: block_height_consensus += 1 for peer in host.peers: total_nodes += 1 if "height" in peer: if max_block_height >= peer["height"] >= max_block_height - 2: block_height_consensus += 1 except Exception as e: __print('Unable to get block height and version messages') print(e) for host in status_result["peer_nodes"]: total_nodes += 1 try: if host.block_height == max_block_height: block_height_consensus += 1 for peer in host.peers: total_nodes += 1 if "height" in peer: if max_block_height >= peer["height"] >= max_block_height - 2: block_height_consensus += 1 except Exception as e: __print('Unable to get block height and version messages') print(e) for host in status_result["nodes_to_monitor"]: total_nodes += 1 try: if host.block_height == max_block_height: block_height_consensus += 1 for peer in host.peers: total_nodes += 1 if "height" in peer: if max_block_height >= peer["height"] >= max_block_height - 2: block_height_consensus += 1 except Exception as e: __print('Unable to get block height and version messages') print(e) return {"block_height_consensus": block_height_consensus, "version_consensus": total_nodes, "total_nodes": total_nodes}
def get_consensus_messages(status_result, max_block_height, version): block_height_consensus = 0 version_consensus = 0 for host in status_result["base_hosts"]: try: if host.block_height == max_block_height: block_height_consensus += 1 if host.version == version: version_consensus += 1 except Exception as e: __print('Unable to get block height and version messages') print(e) for host in status_result["peer_nodes"]: try: if host.block_height == max_block_height: block_height_consensus += 1 if host.version == version: version_consensus += 1 except Exception as e: __print('Unable to get block height and version messages') print(e) for host in status_result["nodes_to_monitor"]: try: if host.block_height == max_block_height: block_height_consensus += 1 if host.version == version: version_consensus += 1 except Exception as e: __print('Unable to get block height and version messages') print(e) return { "block_height_consensus": block_height_consensus, "version_consensus": version_consensus }
def get_max_block_height_and_version(status_result): try: max_block_height = 0 version = "0.0.0" for host in status_result["base_hosts"]: if conf["check_block_height"] and host.block_height > max_block_height: max_block_height = host.block_height if conf["check_version"] and StrictVersion( host.version) > StrictVersion(version): version = host.version for peer in host.peers: if "height" in peer: if conf["check_block_height"] and peer[ "height"] > max_block_height: max_block_height = peer["height"] if "version" in peer: try: if conf["check_version"] and StrictVersion( peer["version"]) > StrictVersion(version): version = peer["version"] except Exception as exception: print(exception) for host in status_result["peer_nodes"]: if conf["check_block_height"] and host.block_height > max_block_height: max_block_height = host.block_height if conf["check_version"] and StrictVersion( host.version) > StrictVersion(version): version = host.version for peer in host.peers: if "height" in peer: if conf["check_block_height"] and peer[ "height"] > max_block_height: max_block_height = peer["height"] if "version" in peer: try: if conf["check_version"] and StrictVersion( peer["version"]) > StrictVersion(version): version = peer["version"] except Exception as exception: print(exception) for host in status_result["nodes_to_monitor"]: if conf["check_block_height"] and host.block_height > max_block_height: max_block_height = host.block_height if conf["check_version"] and StrictVersion( host.version) > StrictVersion(version): version = host.version for peer in host.peers: if "height" in peer: if conf["check_block_height"] and peer[ "height"] > max_block_height: max_block_height = peer["height"] if "version" in peer: try: if conf["check_version"] and StrictVersion( peer["version"]) > StrictVersion(version): version = peer["version"] except Exception as exception: print(exception) return {"max_block_height": max_block_height, "version": version} except Exception as e: __print('Unable to get max block height and version') print(e) return {"max_block_height": 0, "version": "0.0.0"}
def check_arkv2_block_height(host, max_block_height, block_height_consensus, total_nodes): if host.block_height == 0: return host.name + ":\nCould not reach the server, it might be down!\n" elif host.block_height == 403: return host.name + ":\nNode api access denied. Is the monitoring server ip whitelisted in the node's config?\n" elif host.block_height == 500: return host.name + ":\nNo (valid) response from the server, it might be down!\n" elif host.block_height < max_block_height - conf["max_blocks_behind"]: consensus_percentage = int( (block_height_consensus / total_nodes * 100) * 100) / 100 block_height_difference = max_block_height - host.block_height line1 = host.name line2 = ":\nincorrect block height " + str( host.block_height) + " (-" + str(block_height_difference) + ")" line3 = "\nshould be " + str(max_block_height) line4 = "\nconsensus " + str(consensus_percentage) + "% " + str( block_height_consensus) + "/" + str(total_nodes) + "\n" return line1 + line2 + line3 + line4 return None try: conf = json.load(open(args.cfile, 'r')) set_telegram_conf(conf["telegram_settings"]) check_all_nodes() except Exception as ex: __print('Unable to load config file.') print(ex) sys.exit()