""" ENV VARIABLES AVAILABLE: - SSH_HOSTNAME - SSH_KEYPATH (defaults: /bss/id_rsa) - PREFIX (default: bladetest_) """ """ Run in development env: export FLASK_ENV=development export FLASK_APP=prom.py flask run """ from flask import Flask, Response, request # General flask, and the handle requests on the fly thing. import os # for ENV arguments import scraperMain, prom_servers ### ENV Vars ### hostname = str(os.environ['SSH_HOSTNAME']) encname = str(os.environ['ENC_NAME']) sshkeypath = os.getenv('SSH_KEYPATH','/bss/.ssh/id_rsa') PREFIX = os.getenv('PREFIX','bladetest_') ### Get git hash ### with open('.git/HEAD', 'r') as file: current_branch = file.read().replace('\n', '').replace('ref: ', '') with open('.git/' + current_branch, 'r') as file: git_hash = file.read().replace('\n', '') ### FLASK ### app = Flask(__name__) @app.route('/metrics', methods=['GET']) def parse_request(): # If somebody accesses us data = scraperMain.scraperMain(hostname, encname, sshkeypath) # Gather up, we're going to wait a few minutes on the data. #with open("prom_servers.out", "a") as f: # DO NOT UNCOMMENT IN PROD # print(data, file=f) response_list = prom_servers.prom_servers(git_hash, PREFIX, data[0], data[1]) # Convert our python lists to prometheus format whatever. response = '\n'.join(response_list) # Oh you still don't want a list? Fine, newlines! return Response(response + '\n', mimetype='text/plain') # The pizza is already cold.