Correct error handling if monitoring plugins fail

This commit is contained in:
2023-02-23 22:28:34 -05:00
parent d66e33041e
commit d69c4b9662

View File

@ -332,7 +332,14 @@ class MonitoringInstance(object):
def run_plugin(self, plugin):
time_start = datetime.now()
try:
result = plugin.run()
except Exception as e:
self.logger.out(
f"Monitoring plugin {plugin.plugin_name} failed: {e}",
state="e",
)
return None
time_end = datetime.now()
time_delta = time_end - time_start
runtime = "{:0.02f}".format(time_delta.total_seconds())
@ -357,13 +364,13 @@ class MonitoringInstance(object):
plugin_results.append(future.result())
for result in sorted(plugin_results, key=lambda x: x.plugin_name):
if result is not None:
if self.config["log_keepalive_plugin_details"]:
self.logger.out(
result.message + f" [-{result.health_delta}]",
state="t",
prefix=f"{result.plugin_name} ({result.runtime}s)",
)
if result is not None:
total_health -= result.health_delta
if total_health < 0: