From b07396c39a1702480bbfd60dde433404e2e7a137 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 13 Feb 2023 21:45:33 -0500 Subject: [PATCH] Fix bugs if plugins fail to load --- daemon-common/node.py | 10 ++++++++-- node-daemon/pvcnoded/objects/MonitoringInstance.py | 12 ++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/daemon-common/node.py b/daemon-common/node.py index ee97a267..9136d908 100644 --- a/daemon-common/node.py +++ b/daemon-common/node.py @@ -52,9 +52,15 @@ def getNodeInformation(zkhandler, node_name): node_running_domains = zkhandler.read(("node.running_domains", node_name)).split() try: node_health = int(zkhandler.read(("node.monitoring.health", node_name))) - except ValueError: + except Exception: 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() for plugin in node_health_plugins: plugin_last_run = zkhandler.read( diff --git a/node-daemon/pvcnoded/objects/MonitoringInstance.py b/node-daemon/pvcnoded/objects/MonitoringInstance.py index 7ae29f5b..db807ef1 100644 --- a/node-daemon/pvcnoded/objects/MonitoringInstance.py +++ b/node-daemon/pvcnoded/objects/MonitoringInstance.py @@ -190,6 +190,8 @@ class MonitoringInstance(object): self.all_plugins = list() self.all_plugin_names = list() + successful_plugins = 0 + # Load each plugin file into the all_plugins list for plugin_file in sorted(plugin_files): try: @@ -211,8 +213,6 @@ class MonitoringInstance(object): self.this_node, plugin_script.PLUGIN_NAME, ) - self.all_plugins.append(plugin) - self.all_plugin_names.append(plugin.plugin_name) # Create plugin key 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( f"Successfully loaded monitoring plugin '{plugin.plugin_name}'", 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 for plugin_key in self.zkhandler.children( ("node.monitoring.data", self.this_node.name)