|
|
|
@ -5,6 +5,7 @@ from time import sleep
|
|
|
|
|
import geoip2.database
|
|
|
|
|
import arrow
|
|
|
|
|
import requests
|
|
|
|
|
import click
|
|
|
|
|
from flask import Blueprint
|
|
|
|
|
from urllib.parse import urlparse
|
|
|
|
|
|
|
|
|
@ -22,14 +23,28 @@ def init():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.cli.command("check")
|
|
|
|
|
def check():
|
|
|
|
|
diff = datetime.utcnow() - timedelta(hours=24)
|
|
|
|
|
def check_nodes():
|
|
|
|
|
diff = datetime.utcnow() - timedelta(hours=72)
|
|
|
|
|
checks = HealthCheck.select().where(HealthCheck.datetime <= diff)
|
|
|
|
|
for check in checks:
|
|
|
|
|
print("Deleting check", check.id)
|
|
|
|
|
check.delete_instance()
|
|
|
|
|
nodes = Node.select().where(Node.validated == True)
|
|
|
|
|
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()
|
|
|
|
|
hc = HealthCheck(node=node)
|
|
|
|
|
logging.info(f"Attempting to check {node.url}")
|
|
|
|
|