Fix several bugs and optimize output

This commit is contained in:
Joshua Boniface 2023-02-13 16:36:15 -05:00
parent 1ea4800212
commit e6f9e6e0e8
2 changed files with 42 additions and 14 deletions

View File

@ -215,7 +215,8 @@ def node_list(
# Output display functions # Output display functions
# #
def getOutputColours(node_information): def getOutputColours(node_information):
node_health = node_information.get("health", 999) node_health = node_information.get("health", "N/A")
if isinstance(node_health, int):
if node_health <= 50: if node_health <= 50:
health_colour = ansiprint.red() health_colour = ansiprint.red()
elif node_health <= 90: elif node_health <= 90:
@ -224,6 +225,8 @@ def getOutputColours(node_information):
health_colour = ansiprint.green() health_colour = ansiprint.green()
else: else:
health_colour = ansiprint.blue() health_colour = ansiprint.blue()
else:
health_colour = ansiprint.blue()
if node_information["daemon_state"] == "run": if node_information["daemon_state"] == "run":
daemon_state_colour = ansiprint.green() daemon_state_colour = ansiprint.green()
@ -304,7 +307,7 @@ def format_info(node_information, long_output):
else: else:
node_health_text = node_health node_health_text = node_health
ainformation.append( ainformation.append(
"{}Health Value:{} {}{}{}".format( "{}Health:{} {}{}{}".format(
ansiprint.purple(), ansiprint.purple(),
ansiprint.end(), ansiprint.end(),
health_colour, health_colour,
@ -313,6 +316,28 @@ def format_info(node_information, long_output):
) )
) )
node_health_details = node_information.get("health_details", [])
if long_output:
node_health_messages = "\n ".join(
[f"{plugin['name']}: {plugin['message']}" for plugin in node_health_details]
)
else:
node_health_messages = "\n ".join(
[
f"{plugin['name']}: {plugin['message']}"
for plugin in node_health_details
if int(plugin.get("health_delta", 0)) > 0
]
)
if len(node_health_messages) > 0:
ainformation.append(
"{}Health Plugin Details:{} {}".format(
ansiprint.purple(), ansiprint.end(), node_health_messages
)
)
ainformation.append("")
ainformation.append( ainformation.append(
"{}Daemon State:{} {}{}{}".format( "{}Daemon State:{} {}{}{}".format(
ansiprint.purple(), ansiprint.purple(),
@ -340,11 +365,6 @@ def format_info(node_information, long_output):
ansiprint.end(), ansiprint.end(),
) )
) )
ainformation.append(
"{}Active VM Count:{} {}".format(
ansiprint.purple(), ansiprint.end(), node_information["domains_count"]
)
)
if long_output: if long_output:
ainformation.append("") ainformation.append("")
ainformation.append( ainformation.append(
@ -363,6 +383,11 @@ def format_info(node_information, long_output):
) )
) )
ainformation.append("") ainformation.append("")
ainformation.append(
"{}Active VM Count:{} {}".format(
ansiprint.purple(), ansiprint.end(), node_information["domains_count"]
)
)
ainformation.append( ainformation.append(
"{}Host CPUs:{} {}".format( "{}Host CPUs:{} {}".format(
ansiprint.purple(), ansiprint.end(), node_information["vcpu"]["total"] ansiprint.purple(), ansiprint.end(), node_information["vcpu"]["total"]

View File

@ -50,7 +50,10 @@ def getNodeInformation(zkhandler, node_name):
zkhandler.read(("node.count.provisioned_domains", node_name)) zkhandler.read(("node.count.provisioned_domains", node_name))
) )
node_running_domains = zkhandler.read(("node.running_domains", node_name)).split() node_running_domains = zkhandler.read(("node.running_domains", node_name)).split()
try:
node_health = int(zkhandler.read(("node.monitoring.health", node_name))) node_health = int(zkhandler.read(("node.monitoring.health", node_name)))
except ValueError:
node_health = "N/A"
node_health_plugins = zkhandler.read(("node.monitoring.plugins", node_name)).split() node_health_plugins = zkhandler.read(("node.monitoring.plugins", node_name)).split()
node_health_details = list() node_health_details = list()
for plugin in node_health_plugins: for plugin in node_health_plugins: