2020-12-23 02:37:15 +00:00
|
|
|
"""
|
|
|
|
ENV VARIABLES AVAILABLE:
|
|
|
|
- SSH_HOSTNAME
|
2020-12-23 04:52:52 +00:00
|
|
|
- SSH_KEYPATH (defaults: /bss/id_rsa)
|
|
|
|
- PREFIX (default: bladetest_)
|
2020-12-23 02:37:15 +00:00
|
|
|
"""
|
|
|
|
"""
|
2020-12-23 04:52:52 +00:00
|
|
|
Run in development env:
|
2020-12-23 02:37:15 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
hostname = str(os.environ['SSH_HOSTNAME'])
|
2020-12-23 05:40:52 +00:00
|
|
|
encname = str(os.environ['ENC_NAME'])
|
2020-12-23 04:52:52 +00:00
|
|
|
sshkeypath = os.getenv('SSH_KEYPATH','/bss/.ssh/id_rsa')
|
|
|
|
PREFIX = os.getenv('PREFIX','bladetest_')
|
2020-12-23 02:37:15 +00:00
|
|
|
|
|
|
|
### FLASK ###
|
|
|
|
app = Flask(__name__)
|
2020-12-23 06:05:40 +00:00
|
|
|
@app.route('/metrics', methods=['GET'])
|
2020-12-23 02:37:15 +00:00
|
|
|
def parse_request(): # If somebody accesses us
|
2020-12-23 05:40:52 +00:00
|
|
|
data = scraperMain.scraperMain(hostname, encname, sshkeypath) # Gather up, we're going to wait a few minutes on the data.
|
2020-12-23 04:01:21 +00:00
|
|
|
|
|
|
|
#with open("prom_servers.out", "a") as f: # DO NOT UNCOMMENT IN PROD
|
|
|
|
# print(data, file=f)
|
|
|
|
|
2020-12-23 02:37:15 +00:00
|
|
|
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!
|
2020-12-23 04:01:21 +00:00
|
|
|
return '<pre>' + response + '</pre>' # The pizza is already cold.
|