Fix Bug no 1, where offline servers show 'Not Available' instead of 0 for power output.

This commit is contained in:
rasmus 2020-12-23 04:01:03 +02:00
parent 5d680ca370
commit 830db7f051

View File

@ -2,6 +2,7 @@
import paramiko # for ssh import paramiko # for ssh
import logging # for possible debugging import logging # for possible debugging
from time import sleep # for sleep() from time import sleep # for sleep()
from warnings import warn # you guessed it
import os # for CLI arguments import os # for CLI arguments
# Local deps # Local deps
@ -87,6 +88,11 @@ for n in range(baysInUseCount):
powerInfoTmp = ssh_runcmd('show system1/oemhp_power1') # Get the data 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. 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. servers[n].append(int(presentPower)) # And push it to our miniDB of the servers list.
logging.info("UsageRawDC: " + presentPower) logging.info("UsageRawDC: " + presentPower)