Skip to content
Snippets Groups Projects
Commit edeb8902 authored by David Trattnig's avatar David Trattnig
Browse files

Added tank healthz info.

parent 51bcd73e
No related branches found
No related tags found
No related merge requests found
......@@ -45,6 +45,9 @@ class Monitoring:
self.status = dict()
self.status["soundsystem"] = dict()
self.status["api"] = dict()
self.status["api"]["steering"] = dict()
self.status["api"]["tank"] = dict()
def update_status(self):
......@@ -60,8 +63,9 @@ class Monitoring:
#self.status["soundsystem"]["recorder"] = self.soundsystem.get_recorder_status()
self.soundsystem.disable_transaction(self.soundsystem.client)
self.status["api"]["steering_ready"] = self.validate_url_connection(self.config.get("api_steering_status"))
self.status["api"]["tank_ready"] = self.validate_url_connection(self.config.get("api_tank_status"))
self.status["api"]["steering"]["available"] = self.validate_url_connection(self.config.get("api_steering_status"))
self.status["api"]["tank"]["available"] = self.validate_url_connection(self.config.get("api_tank_status"))
self.status["api"]["tank"]["status"] = self.get_url_response(self.config.get("api_tank_status"))
self.status["redis_ready"] = self.validate_redis_connection()
self.status["audio_store"] = self.validate_directory(self.config.get("audiofolder"))
......@@ -73,6 +77,7 @@ class Monitoring:
self.status["engine_status"] = "INVALID"
def get_io_state(self):
"""
Retrieves all input and outputs provided by the engine.
......@@ -155,4 +160,27 @@ class Monitoring:
if status["exists"]:
status["has_content"] = any([True for _ in os.scandir(dir_path)])
return status
\ No newline at end of file
return status
def get_url_response(self, url):
"""
Fetches JSON data from the given URL.
Args:
url (String): The API endpoint to call
Returns:
(dict[]): A Python object representing the JSON structure
"""
data = None
try:
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
data = response.read()
except (urllib.error.URLError, IOError, ValueError) as e:
self.logger.error("Error while connecting to URL '%s' - %s" % (url, e))
return json.loads(data, strict=False)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment