From 830db7f0510bb69196d232ecb7f02d91b62e6d65 Mon Sep 17 00:00:00 2001 From: rasmus Date: Wed, 23 Dec 2020 04:01:03 +0200 Subject: [PATCH] Fix Bug no 1, where offline servers show 'Not Available' instead of 0 for power output. --- scraperMain.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scraperMain.py b/scraperMain.py index 11e19cd..0439bf0 100644 --- a/scraperMain.py +++ b/scraperMain.py @@ -2,6 +2,7 @@ import paramiko # for ssh import logging # for possible debugging from time import sleep # for sleep() +from warnings import warn # you guessed it import os # for CLI arguments # Local deps @@ -87,6 +88,11 @@ for n in range(baysInUseCount): powerInfoTmp = ssh_runcmd('show system1/oemhp_power1') # Get the data presentPower = [i for i in powerInfoTmp if i.startswith(' oemhp_PresentPower=')][0][23:-7] # Get the line with PresentPower, then remove first 23, and last 7 chars to end up with the Watts DC the blade is directly using. + if presentPower == 'Not Ava': # When the server is powered off, it's not zero (LIKE LITERALLY EVERYWHERE ELSE). It is NoT aVaILAbLe. 'Not Ava' because the previous command takes last 7 chars (normally 'Watts') off of it. Ah my fault for not checking all possible input from hpe. + presentPower = 0 + elif not presentPower.isdigit(): # Just in case some other anomalities come up in the future, like negative power draw or something… + warn('presentPower for bay ' + bay + 'was corrected to 0 from it\'s abnormal state: ' + presentPower) + presentPower = 0 servers[n].append(int(presentPower)) # And push it to our miniDB of the servers list. logging.info("UsageRawDC: " + presentPower)