Correct error handling if monitoring plugins fail
This commit is contained in:
@ -332,7 +332,14 @@ class MonitoringInstance(object):
|
|||||||
|
|
||||||
def run_plugin(self, plugin):
|
def run_plugin(self, plugin):
|
||||||
time_start = datetime.now()
|
time_start = datetime.now()
|
||||||
result = plugin.run()
|
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_end = datetime.now()
|
||||||
time_delta = time_end - time_start
|
time_delta = time_end - time_start
|
||||||
runtime = "{:0.02f}".format(time_delta.total_seconds())
|
runtime = "{:0.02f}".format(time_delta.total_seconds())
|
||||||
@ -357,13 +364,13 @@ class MonitoringInstance(object):
|
|||||||
plugin_results.append(future.result())
|
plugin_results.append(future.result())
|
||||||
|
|
||||||
for result in sorted(plugin_results, key=lambda x: x.plugin_name):
|
for result in sorted(plugin_results, key=lambda x: x.plugin_name):
|
||||||
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:
|
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)",
|
||||||
|
)
|
||||||
total_health -= result.health_delta
|
total_health -= result.health_delta
|
||||||
|
|
||||||
if total_health < 0:
|
if total_health < 0:
|
||||||
|
Reference in New Issue
Block a user