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

Extend monitoring.

parent 57317de7
No related branches found
No related tags found
No related merge requests found
......@@ -21,11 +21,19 @@ import urllib
import logging
import json
import os.path
from os import path
from enum import Enum
from modules.communication.redis.adapter import ClientRedisAdapter
class MonitorResponseCode(Enum):
OK = "OK"
INVALID_STATE = "INVALID-STATE"
class Monitoring:
"""
Engine Monitoring
......@@ -47,7 +55,7 @@ class Monitoring:
self.status["api"] = dict()
self.status["api"]["steering"] = dict()
self.status["api"]["tank"] = dict()
self.status["api"]["engine"] = dict()
def update_status(self):
......@@ -63,18 +71,24 @@ class Monitoring:
#self.status["soundsystem"]["recorder"] = self.soundsystem.get_recorder_status()
self.soundsystem.disable_transaction(self.soundsystem.client)
self.status["api"]["steering"]["url"] = self.config.get("api_steering_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"))
self.status["api"]["tank"]["url"] = self.config.get("api_tank_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["api"]["engine"]["url"] = self.config.get("exposed_api_url")
self.status["api"]["engine"]["available"] = self.validate_url_connection(self.config.get("exposed_api_url"))
self.status["redis_ready"] = self.validate_redis_connection()
self.status["audio_store"] = self.validate_directory(self.config.get("audiofolder"))
# Set overall status
if self.has_valid_status():
self.status["engine_status"] = "OK"
self.status["engine_status"] = MonitorResponseCode.OK.value
else:
self.status["engine_status"] = "INVALID"
self.status["engine_status"] = MonitorResponseCode.INVALID_STATE.value
......@@ -90,7 +104,7 @@ class Monitoring:
return ios
except Exception as e:
self.logger.warn("Got invalid JSON from soundsystem - " + str(e))
return "[ERROR]"
return MonitorResponseCode.INVALID_STATE.value
......@@ -179,8 +193,8 @@ class Monitoring:
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
data = response.read()
return json.loads(data, strict=False)
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
return MonitorResponseCode.INVALID_STATE.value
\ 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