diff --git a/api/__init__.py b/api/__init__.py index 64e386d..471a3cc 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -2,3 +2,7 @@ import grpc from .sys_mon_agent_api_pb2 import AgentConfiguration, AgentConfigurationResponse, MonitoringStats, MonitoredServiceState, MonitoredService, MonitoredStorage from .sys_mon_agent_api_pb2_grpc import AgentServicer, AgentStub, add_AgentServicer_to_server +from .api_extensions import _MonitoringStats_get_storage_by_name, _MonitoringStats_get_service_by_name + +MonitoringStats.storage_by_name = _MonitoringStats_get_storage_by_name +MonitoringStats.service_by_name = _MonitoringStats_get_service_by_name diff --git a/api/api_extensions.py b/api/api_extensions.py new file mode 100644 index 0000000..02a5bde --- /dev/null +++ b/api/api_extensions.py @@ -0,0 +1,17 @@ +from typing import Optional + +from .sys_mon_agent_api_pb2 import MonitoringStats, MonitoredStorage, MonitoredService + +def _MonitoringStats_get_storage_by_name(self: MonitoringStats, name: str) -> Optional[MonitoredStorage]: + for storage in self.storage: + if storage.name == name: + return storage + + return None + +def _MonitoringStats_get_service_by_name(self: MonitoringStats, name: str) -> Optional[MonitoredService]: + for service in self.services: + if service.name == name: + return service + + return None