Fix bugs if plugins fail to load

This commit is contained in:
Joshua Boniface 2023-02-13 21:45:33 -05:00
parent 71139fa66d
commit b07396c39a
2 changed files with 18 additions and 4 deletions

View File

@ -52,9 +52,15 @@ def getNodeInformation(zkhandler, 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: try:
node_health = int(zkhandler.read(("node.monitoring.health", node_name))) node_health = int(zkhandler.read(("node.monitoring.health", node_name)))
except ValueError: except Exception:
node_health = "N/A" node_health = "N/A"
node_health_plugins = zkhandler.read(("node.monitoring.plugins", node_name)).split() try:
node_health_plugins = zkhandler.read(
("node.monitoring.plugins", node_name)
).split()
except Exception:
node_health_plugins = list()
node_health_details = list() node_health_details = list()
for plugin in node_health_plugins: for plugin in node_health_plugins:
plugin_last_run = zkhandler.read( plugin_last_run = zkhandler.read(

View File

@ -190,6 +190,8 @@ class MonitoringInstance(object):
self.all_plugins = list() self.all_plugins = list()
self.all_plugin_names = list() self.all_plugin_names = list()
successful_plugins = 0
# Load each plugin file into the all_plugins list # Load each plugin file into the all_plugins list
for plugin_file in sorted(plugin_files): for plugin_file in sorted(plugin_files):
try: try:
@ -211,8 +213,6 @@ class MonitoringInstance(object):
self.this_node, self.this_node,
plugin_script.PLUGIN_NAME, plugin_script.PLUGIN_NAME,
) )
self.all_plugins.append(plugin)
self.all_plugin_names.append(plugin.plugin_name)
# Create plugin key # Create plugin key
self.zkhandler.write( self.zkhandler.write(
@ -273,6 +273,11 @@ class MonitoringInstance(object):
), ),
] ]
) )
self.all_plugins.append(plugin)
self.all_plugin_names.append(plugin.plugin_name)
successful_plugins += 1
self.logger.out( self.logger.out(
f"Successfully loaded monitoring plugin '{plugin.plugin_name}'", f"Successfully loaded monitoring plugin '{plugin.plugin_name}'",
state="o", state="o",
@ -292,6 +297,9 @@ class MonitoringInstance(object):
] ]
) )
if successful_plugins < 1:
return
# Clean up any old plugin data for which a plugin file no longer exists # Clean up any old plugin data for which a plugin file no longer exists
for plugin_key in self.zkhandler.children( for plugin_key in self.zkhandler.children(
("node.monitoring.data", self.this_node.name) ("node.monitoring.data", self.this_node.name)