Commit 215d6026 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Monitoring component:

- Only monitor enabled endpoints
parent ec4d1fa3
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -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)