blades-ssh-scraper/prom.py

29 lines
1.0 KiB
Python
Raw Normal View History

2020-12-23 02:37:15 +00:00
"""
ENV VARIABLES AVAILABLE:
- SSH_HOSTNAME
- SSH_KEYPATH
"""
"""
export FLASK_ENV=development
export FLASK_APP=prom.py
flask run
"""
from flask import Flask, request # General flask, and the handle requests on the fly thing.
import os # for ENV arguments
import scraperMain, prom_servers
PREFIX = 'bladetest_'
enc = 'k-space-blade-02' # for now ~~hard~~softcoded in, we'd need to add parsing in hostnames, and add a similar enc env var.
hostname = str(os.environ['SSH_HOSTNAME'])
sshkeypath = os.getenv('SSH_KEYPATH')
### FLASK ###
app = Flask(__name__)
@app.route('/', methods=['GET'])
def parse_request(): # If somebody accesses us
data = scraperMain.scraperMain(hostname, enc, sshkeypath) # Gather up, we're going to wait a few minutes on the data.
response_list = prom_servers.prom_servers(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 # The pizza is already cold.