make encname an env var

This commit is contained in:
rasmus 2020-12-23 07:40:52 +02:00
parent d22766ba88
commit 49c973707f
3 changed files with 7 additions and 8 deletions

View File

@ -15,9 +15,8 @@ import os # for ENV arguments
import scraperMain, prom_servers
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'])
encname = str(os.environ['ENC_NAME'])
sshkeypath = os.getenv('SSH_KEYPATH','/bss/.ssh/id_rsa')
PREFIX = os.getenv('PREFIX','bladetest_')
@ -25,7 +24,7 @@ PREFIX = os.getenv('PREFIX','bladetest_')
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.
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)

View File

@ -102,7 +102,7 @@ def prom_servers(PREFIX, baysInUseCount, servers):
#PREFIX = 'bladetest_'
#baysInUseCount = 11
# 0~ 1~ 2~ 3~ 4~ 5~ 6~ 7~ 8~
# [BayNumber "Server Name", "Serial Number", "Status", "Power", "UID Partner", presentPowerDirectDC, relativeUsageAC, "enc"]
# [BayNumber "Server Name", "Serial Number", "Status", "Power", "UID Partner", presentPowerDirectDC, relativeUsageAC, "encname"]
#servers = [[1, 'foo-lab-1', '', 'OK', 'On', 'Off', 142, 222, "k-space-blade-02"], [2, 'foo-lab-2', 'CZ302243P9', 'OK', 'On', 'Off', 87, 136, "k-space-blade-02"], [3, 'foo-lab-3', 'CZJI441OKP', 'Failed', 'On', 'Off', 127, 198, "k-space-blade-02"], [4, 'kspve1', 'CZJ18450FK', 'OK', 'On', 'Off', 86, 134, "k-space-blade-02"], [5, 'kspve2-2', '', 'OK', 'On', 'Off', 71, 111, "k-space-blade-02"], [6, 'kspve3', '', 'OK', 'On', 'Off', 80, 125, "k-space-blade-02"], [7, 'foo-blade', '', 'OK', 'On', 'Off', 81, 127, "k-space-blade-02"], [8, 'Bar-01', 'CZ241274CC', 'OK', 'On', 'Off', 126, 197, "k-space-blade-02"], [9, 'baz-sar', 'CZ3217FNYE', 'OK', 'On', 'Off', 129, 202, "k-space-blade-02"], [10, 'baz-sar2', 'CZ3217FFSS', 'OK', 'On', 'Off', 97, 152, "k-space-blade-02"], [12, 'bee-bar', '', 'OK', 'On', 'Off', 86, 134, "k-space-blade-02"]]
#print(prom_servers(PREFIX, baysInUseCount, servers))

View File

@ -49,13 +49,13 @@ def ssh_runcmd(command): # Some abstraction to run ssh commands.
#cmdout = '\n'.join(cmdout) # DO NOT UNCOMMENT THIS, HERE FOR ONLY REFERENCE TO JOIN THE LINES BACK.
return(cmdout) # Return list of output stuff.
def scraperMain(hostname, enc, sshkeypath):
def scraperMain(hostname, encname, sshkeypath):
global channel # needed for ssh_runcmd
# Input validation
if not type(hostname) is str:
raise TypeError("scraperMain: hostname must be a string, '" + str(hostname) + "' is not.")
if not type(enc) is str:
raise TypeError("scraperMain: enc must be a string, '" + str(enc) + "' is not.")
if not type(encname) is str:
raise TypeError("scraperMain: enc must be a string, '" + str(encname) + "' is not.")
if not type(sshkeypath) is str:
raise TypeError("scraperMain: sshkeypath must be a string, '" + str(sshkeypath) + "' is not.")
@ -125,7 +125,7 @@ def scraperMain(hostname, enc, sshkeypath):
# Fields: [BayNumber "Server Name", "Serial Number", "Status", "Power", "UID Partner", presentPowerDirectDC, relativeUsageAC]
for n in range(baysInUseCount):
servers[n].append( enc ) # Add what enc was used.
servers[n].append( encname ) # Add what enc was used.
# Fields: [BayNumber "Server Name", "Serial Number", "Status", "Power", "UID Partner", presentPowerDirectDC, relativeUsageAC, "enc"]
return(baysInUseCount, servers) # we could return more, but nobody wants our data :/