diff --git a/proto/optical_attack_detector.proto b/proto/optical_attack_detector.proto index 9f03d9b75318fd1a92f172401a7c95c73a2321ee..4c5fcaa7676c4374df73630ffae1ab693bb589d4 100644 --- a/proto/optical_attack_detector.proto +++ b/proto/optical_attack_detector.proto @@ -17,10 +17,16 @@ syntax = "proto3"; package optical_attack_detector; import "context.proto"; +import "monitoring.proto"; service OpticalAttackDetectorService { - // rpc that triggers the attack detection loop - rpc DetectAttack (context.ServiceId ) returns (context.Empty) {} + // rpc that executes the detection loop for a particular service + rpc DetectAttack (DetectionRequest) returns (context.Empty) {} } + +message DetectionRequest { + KpiId kpi_id = 1; + context.ServiceId service_id = 7; +} diff --git a/src/opticalattackmanager/service/__main__.py b/src/opticalattackmanager/service/__main__.py index 589dd67b6edd6297c62cea80061fae0a7a546597..e07b857915329eef6a5ec5b2236df9d9abf4cb02 100644 --- a/src/opticalattackmanager/service/__main__.py +++ b/src/opticalattackmanager/service/__main__.py @@ -154,9 +154,6 @@ def get_context_updates(service_list: List[ServiceId]): LOGGER.info("Connected successfully... Waiting for events...") - for service in service_list: - kpi_id = create_kpi(monitoring_client, service["service"]) - time.sleep(20) while not terminate.wait(timeout=1): @@ -190,38 +187,6 @@ def get_context_updates(service_list: List[ServiceId]): events_collector.stop() - # for event in context_client.GetServiceEvents(Empty()): - # LOGGER.info("Event received: {}".format(event)) - # if event.event.event_type == EventTypeEnum.EVENTTYPE_CREATE: - # LOGGER.info("Service created: {}".format(event.service_id)) - # kpi_id = create_kpi(monitoring_client, event.service_id.service_uuid.uuid) - # service_list.append( - # { - # "context": event.service_id.context_id.context_uuid.uuid, - # "service": event.service_id.service_uuid.uuid, - # "kpi": kpi_id.kpi_id.uuid, - # } - # ) - - # elif event.event.event_type == EventTypeEnum.EVENTTYPE_REMOVE: - # LOGGER.info("Service removed: {}".format(event.service_id)) - # # find service and remove it from the list of currently monitored - # for service in service_list: - # if ( - # service["service"] == event.service_id.service_uuid.uuid - # and service["context"] - # == event.service_id.context_id.context_uuid.uuid - # ): - # service_list.remove(service) - # break - - # if terminate.is_set(): # if terminate is set - # LOGGER.warning("Stopping execution of the get_context_updates...") - # context_client.close() - # monitoring_client.close() - # break # break the while and stop execution - # LOGGER.debug("Waiting for next event...") - def main(): global LOGGER # pylint: disable=global-statement @@ -230,6 +195,28 @@ def main(): logging.basicConfig(level=log_level) LOGGER = logging.getLogger(__name__) + wait_for_environment_variables( + [ + get_env_var_name( + ServiceNameEnum.MONITORING, ENVVAR_SUFIX_SERVICE_HOST + ), + get_env_var_name( + ServiceNameEnum.MONITORING, ENVVAR_SUFIX_SERVICE_PORT_GRPC + ), + ] + ) + + wait_for_environment_variables( + [ + get_env_var_name( + ServiceNameEnum.CONTEXT, ENVVAR_SUFIX_SERVICE_HOST + ), + get_env_var_name( + ServiceNameEnum.CONTEXT, ENVVAR_SUFIX_SERVICE_PORT_GRPC + ), + ] + ) + wait_for_environment_variables( [ get_env_var_name( @@ -257,8 +244,10 @@ def main(): # creating a thread-safe list to be shared among threads service_list = Manager().list() - service_list.append({"context": "admin", "service": "1213"}) - service_list.append({"context": "admin", "service": "1456"}) + kpi_id = create_kpi(monitoring_client, "1213") + service_list.append({"context": "admin", "service": "1213", "kpi": kpi_id.kpi_id.uuid}) + kpi_id = create_kpi(monitoring_client, "1456") + service_list.append({"context": "admin", "service": "1456", "kpi": kpi_id.kpi_id.uuid}) context_ids: ContextIdList = context_client.ListContextIds(Empty()) diff --git a/src/opticalcentralizedattackdetector/requirements.in b/src/opticalcentralizedattackdetector/requirements.in deleted file mode 100644 index ea6b450c9c240c76b9f54ce4f3c0c6c25ec62289..0000000000000000000000000000000000000000 --- a/src/opticalcentralizedattackdetector/requirements.in +++ /dev/null @@ -1,10 +0,0 @@ -grpcio-health-checking -grpcio -prometheus-client -pytest -pytest-benchmark -redis -# from the monitoring component -influxdb -python-json-logger -coverage