Run setup during plugin loads

This commit is contained in:
Joshua Boniface 2023-02-15 10:11:38 -05:00
parent 0f4edc54d1
commit 0ecf219910
1 changed files with 17 additions and 1 deletions

View File

@ -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(
[