From 215d6026fb7c236261fea26d93952dada1366631 Mon Sep 17 00:00:00 2001
From: gifrerenom <lluis.gifre@cttc.es>
Date: Sat, 17 Jun 2023 17:17:12 +0000
Subject: [PATCH] Monitoring component:

- Only monitor enabled endpoints
---
 src/monitoring/service/EventTools.py | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/monitoring/service/EventTools.py b/src/monitoring/service/EventTools.py
index 0d351eee9..be3fe9b92 100644
--- a/src/monitoring/service/EventTools.py
+++ b/src/monitoring/service/EventTools.py
@@ -12,11 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import grpc, json, logging, queue, threading
 from typing import Dict
-import grpc, logging, queue, threading
 from common.method_wrappers.ServiceExceptions import ServiceException
 from common.proto import monitoring_pb2
-from common.proto.context_pb2 import DeviceOperationalStatusEnum, Empty, EventTypeEnum
+from common.proto.context_pb2 import ConfigActionEnum, DeviceOperationalStatusEnum, Empty, EventTypeEnum
 from common.proto.kpi_sample_types_pb2 import KpiSampleType
 from context.client.ContextClient import ContextClient
 from monitoring.client.MonitoringClient import MonitoringClient
@@ -108,7 +108,21 @@ class EventsDeviceCollector:
                         # device is not ready for monitoring
                         continue
 
+                    enabled_endpoint_names = set()
+                    for config_rule in device.device_config.config_rules:
+                        if config_rule.action != ConfigActionEnum.CONFIGACTION_SET: continue
+                        if config_rule.WhichOneof('config_rule') != 'custom': continue
+                        str_resource_key = str(config_rule.custom.resource_key)
+                        if not str_resource_key.startswith('/interface['): continue
+                        json_resource_value = json.loads(config_rule.custom.resource_value)
+                        if 'name' not in json_resource_value: continue
+                        if 'enabled' not in json_resource_value: continue
+                        if not json_resource_value['enabled']: continue
+                        enabled_endpoint_names.add(json_resource_value['name'])
+
                     for endpoint in device.device_endpoints:
+                        if endpoint.name not in enabled_endpoint_names: continue
+
                         endpoint_uuid = endpoint.endpoint_id.endpoint_uuid.uuid
                         self._name_mapping.set_endpoint_name(endpoint_uuid, endpoint.name)
 
-- 
GitLab