Created
January 28, 2022 18:22
-
-
Save g-a-v-i-n/026d15465261ae3a55d2c8d861a05080 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import logging | |
from logging import Formatter | |
import json | |
import http.client | |
import time | |
from apscheduler.schedulers.background import BackgroundScheduler | |
from flask import Flask | |
from flask import Response, request, send_from_directory, jsonify | |
logger = logging.getLogger(__name__) | |
logger.info("Stackdriver webhook-sample starting up on %s" % (str.replace(sys.version, '\n', ' '))) | |
app = Flask("arvo-healthcheck", static_url_path='') | |
global galaxy_statuses | |
galaxy_statuses = {} | |
global latestPing | |
latestPing = 0 | |
global galaxies | |
# galaxies = [ | |
# 'zod', | |
# 'bus', | |
# 'dev', | |
# 'fed', | |
# 'def', | |
# 'feb', | |
# 'fet', | |
# 'marzod', | |
# 'binzod', | |
# 'dopzod', | |
# 'samzod', | |
# 'wanzod' | |
# ] | |
galaxies = [ | |
'bus', | |
'def', | |
'dev', | |
'feb', | |
'fet', | |
'lur', | |
'nes', | |
'nus', | |
'pem', | |
'pub', | |
'rel', | |
'rud', | |
'sud', | |
'ten', | |
'zod', | |
'marzod', | |
'binzod', | |
'samzod', | |
'wanzod', | |
'dopzod', | |
'bitpyx-dildus', | |
'bolbex-fogdys' | |
] | |
@app.route('/') | |
def root(): | |
return send_from_directory('dist', 'index.html') | |
@app.route('/js/<path:path>') | |
def send_js(path): | |
return send_from_directory('dist/js', path) | |
@app.route('/css/<path:path>') | |
def send_css(path): | |
return send_from_directory('dist/css', path) | |
@app.route('/galaxy-status') | |
def galaxy_status(): | |
statusAsArray=[] | |
for ship, respCode in galaxy_statuses.items(): | |
statusAsArray.append({ | |
'ship': ship, | |
'status': respCode, | |
}) | |
return jsonify({ | |
'status': statusAsArray, | |
'latestPing': latestPing, | |
}) | |
def healthcheck(): | |
global latestPing | |
latestPing = int(time.time()) | |
for gal in galaxies: | |
try: | |
conn = http.client.HTTPConnection(gal + ".arvo.network") | |
conn.request("GET", "/") | |
galaxy_statuses[gal] = conn.getresponse().status | |
except: | |
galaxy_statuses[gal] = 500 | |
if __name__ == '__main__': | |
scheduler = BackgroundScheduler() | |
scheduler.add_job(healthcheck, 'interval', seconds=60) | |
scheduler.start() | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment