T-Systems-MMS / check_springboot_actuator

Icinga/Nagios check for Spring Boot applications using the actuator framework
MIT License
12 stars 10 forks source link

Plugin timeout exceeded - output Unknown but status OK #45

Closed enidvx closed 9 months ago

enidvx commented 9 months ago

Hi, I am getting these output from the script Unknown - Plugin timeout exceeded after 58 seconds. But the status is Green and OK

image

The timeout doesn't come from the Icinga settings and is not Terminated by it (it is set to 3minutes actually)

Is there any way to output the correct status Unknown and not OK for this case?

Thank you, Enid

enidvx commented 9 months ago

I did this modification to the script in order to "fix" this. Actually it does what I am expecting it to do, adding a timeout and throwing an exception when that timeout is exceeded.

diff --git a/check_spring_actuator.py b/check_spring_actuator.py
index 9122f4602..f0e2de592 100755
--- a/check_spring_actuator.py
+++ b/check_spring_actuator.py
@@ -8,7 +8,7 @@ import logging

 from pynag.Plugins import PluginHelper, ok, critical, unknown
 from requests import get
-from requests.exceptions import ConnectionError
+from requests.exceptions import ConnectionError, Timeout

 helper = PluginHelper()

@@ -52,7 +52,7 @@ def request_data(url, **get_args):
   """executes get request to retrieve data from given url"""
   logging.captureWarnings(True)
   try:
-    response = get(url, **get_args)
+    response = get(url, **get_args, timeout=60) # set default timeout as Icinga checks
     if response.ok or response.status_code == 503:
       return response.json(), Exception(response.status_code, url)
     else:
@@ -60,6 +60,9 @@ def request_data(url, **get_args):
   except ConnectionError as e:
     helper.debug('error fetching data from {}'.format(url))
     return None, e
+  except Timeout as t:
+    helper.debug('timeout fetching data from {}'.format(url))
+    return None, t
   finally:
     logging.captureWarnings(False)

Please check if this makes sense to you. Thanks. Enid