From 0ecf21991008d0688d3598f0bdc3d046de7e2813 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Wed, 15 Feb 2023 10:11:38 -0500 Subject: [PATCH] Run setup during plugin loads --- .../pvcnoded/objects/MonitoringInstance.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/node-daemon/pvcnoded/objects/MonitoringInstance.py b/node-daemon/pvcnoded/objects/MonitoringInstance.py index 5651b79f..4ccc620c 100644 --- a/node-daemon/pvcnoded/objects/MonitoringInstance.py +++ b/node-daemon/pvcnoded/objects/MonitoringInstance.py @@ -28,6 +28,14 @@ from datetime import datetime from json import dumps +class PluginError(Exception): + """ + An exception that results from a plugin failing setup + """ + + pass + + class PluginResult(object): def __init__(self, zkhandler, config, logger, this_node, plugin_name): self.zkhandler = zkhandler @@ -157,7 +165,11 @@ class MonitoringPlugin(object): def setup(self): """ setup(): Perform setup of the plugin; run once during daemon startup - OPTIONAL + + This step is optional and should be used sparingly. + + If you wish for the plugin to not load in certain conditions, do any checks here + and return a non-None failure message to indicate the error. """ pass @@ -214,6 +226,10 @@ class MonitoringInstance(object): plugin_script.PLUGIN_NAME, ) + failed_setup = plugin.setup() + if failed_setup is not None: + raise PluginError(f"{failed_setup}") + # Create plugin key self.zkhandler.write( [