|
|
@ -5,6 +5,7 @@ from time import sleep
|
|
|
|
import geoip2.database
|
|
|
|
import geoip2.database
|
|
|
|
import arrow
|
|
|
|
import arrow
|
|
|
|
import requests
|
|
|
|
import requests
|
|
|
|
|
|
|
|
import click
|
|
|
|
from flask import Blueprint
|
|
|
|
from flask import Blueprint
|
|
|
|
from urllib.parse import urlparse
|
|
|
|
from urllib.parse import urlparse
|
|
|
|
|
|
|
|
|
|
|
@ -22,14 +23,28 @@ def init():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.cli.command("check")
|
|
|
|
@bp.cli.command("check")
|
|
|
|
def check():
|
|
|
|
def check_nodes():
|
|
|
|
diff = datetime.utcnow() - timedelta(hours=24)
|
|
|
|
diff = datetime.utcnow() - timedelta(hours=72)
|
|
|
|
checks = HealthCheck.select().where(HealthCheck.datetime <= diff)
|
|
|
|
checks = HealthCheck.select().where(HealthCheck.datetime <= diff)
|
|
|
|
for check in checks:
|
|
|
|
for check in checks:
|
|
|
|
print("Deleting check", check.id)
|
|
|
|
print("Deleting check", check.id)
|
|
|
|
check.delete_instance()
|
|
|
|
check.delete_instance()
|
|
|
|
nodes = Node.select().where(Node.validated == True)
|
|
|
|
nodes = Node.select().where(Node.validated == True)
|
|
|
|
for node in nodes:
|
|
|
|
for node in nodes:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
check_node(node.url)
|
|
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
|
|
|
exit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_node(_node):
|
|
|
|
|
|
|
|
if _node.startswith("http"):
|
|
|
|
|
|
|
|
node = Node.select().where(Node.url == _node).first()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
node = Node.select().where(Node.id == _node).first()
|
|
|
|
|
|
|
|
if not node:
|
|
|
|
|
|
|
|
print('node found')
|
|
|
|
|
|
|
|
pass
|
|
|
|
now = datetime.utcnow()
|
|
|
|
now = datetime.utcnow()
|
|
|
|
hc = HealthCheck(node=node)
|
|
|
|
hc = HealthCheck(node=node)
|
|
|
|
logging.info(f"Attempting to check {node.url}")
|
|
|
|
logging.info(f"Attempting to check {node.url}")
|
|
|
|