Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
controller
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TFS
controller
Commits
2dac8825
Commit
2dac8825
authored
1 year ago
by
Lluis Gifre Renom
Browse files
Options
Downloads
Patches
Plain Diff
Pre-release fixing
parent
0223e106
No related branches found
No related tags found
2 merge requests
!142
Release TeraFlowSDN 2.1
,
!136
Pre release CI/CD fixes
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/monitoring/service/EventTools.py
+42
-8
42 additions, 8 deletions
src/monitoring/service/EventTools.py
with
42 additions
and
8 deletions
src/monitoring/service/EventTools.py
+
42
−
8
View file @
2dac8825
...
...
@@ -18,6 +18,7 @@ from common.method_wrappers.ServiceExceptions import ServiceException
from
common.proto
import
monitoring_pb2
from
common.proto.context_pb2
import
ConfigActionEnum
,
DeviceOperationalStatusEnum
,
Empty
,
EventTypeEnum
from
common.proto.kpi_sample_types_pb2
import
KpiSampleType
from
common.tools.grpc.Tools
import
grpc_message_to_json_string
from
context.client.ContextClient
import
ContextClient
from
monitoring.client.MonitoringClient
import
MonitoringClient
from
monitoring.service.MonitoringServiceServicerImpl
import
LOGGER
...
...
@@ -86,10 +87,12 @@ class EventsDeviceCollector:
event_type
=
event
.
event
.
event_type
device_uuid
=
event
.
device_id
.
device_uuid
.
uuid
if
event_type
in
{
EventTypeEnum
.
EVENTTYPE_REMOVE
}:
LOGGER
.
info
(
'
removing device
'
)
self
.
_device_to_state
.
pop
(
device_uuid
,
None
)
continue
if
event_type
not
in
{
EventTypeEnum
.
EVENTTYPE_CREATE
,
EventTypeEnum
.
EVENTTYPE_UPDATE
}:
LOGGER
.
info
(
'
unexpected event
'
)
# Unknown event type
continue
...
...
@@ -97,37 +100,68 @@ class EventsDeviceCollector:
self
.
_name_mapping
.
set_device_name
(
device_uuid
,
device
.
name
)
old_operational_status
=
self
.
_device_to_state
.
get
(
device_uuid
,
DEVICE_OP_STATUS_UNDEFINED
)
LOGGER
.
info
(
'
old_operational_status={:s}
'
.
format
(
str
(
old_operational_status
)))
device_was_not_enabled
=
(
old_operational_status
in
DEVICE_OP_STATUS_NOT_ENABLED
)
LOGGER
.
info
(
'
device_was_not_enabled={:s}
'
.
format
(
str
(
device_was_not_enabled
)))
new_operational_status
=
device
.
device_operational_status
LOGGER
.
info
(
'
new_operational_status={:s}
'
.
format
(
str
(
new_operational_status
)))
device_is_enabled
=
(
new_operational_status
==
DEVICE_OP_STATUS_ENABLED
)
LOGGER
.
info
(
'
device_is_enabled={:s}
'
.
format
(
str
(
device_is_enabled
)))
self
.
_device_to_state
[
device_uuid
]
=
new_operational_status
activate_monitoring
=
device_was_not_enabled
and
device_is_enabled
LOGGER
.
info
(
'
activate_monitoring={:s}
'
.
format
(
str
(
activate_monitoring
)))
if
not
activate_monitoring
:
LOGGER
.
info
(
'
device not ready for activation
'
)
# device is not ready for monitoring
continue
LOGGER
.
info
(
'
checking endpoints
'
)
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
LOGGER
.
info
(
grpc_message_to_json_string
(
config_rule
))
if
config_rule
.
action
!=
ConfigActionEnum
.
CONFIGACTION_SET
:
LOGGER
.
info
(
'
not set config rule
'
)
continue
if
config_rule
.
WhichOneof
(
'
config_rule
'
)
!=
'
custom
'
:
LOGGER
.
info
(
'
not custom
'
)
continue
str_resource_key
=
str
(
config_rule
.
custom
.
resource_key
)
if
not
str_resource_key
.
startswith
(
'
/interface[
'
):
continue
LOGGER
.
info
(
'
str_resource_key={:s}
'
.
format
(
str
(
str_resource_key
)))
if
not
str_resource_key
.
startswith
(
'
/interface[
'
):
LOGGER
.
info
(
'
not /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
LOGGER
.
info
(
'
json_resource_value={:s}
'
.
format
(
str
(
json_resource_value
)))
if
'
name
'
not
in
json_resource_value
:
LOGGER
.
info
(
'
missing name
'
)
continue
if
'
enabled
'
not
in
json_resource_value
:
LOGGER
.
info
(
'
missing enabled
'
)
continue
if
not
json_resource_value
[
'
enabled
'
]:
LOGGER
.
info
(
'
not enabled
'
)
continue
LOGGER
.
info
(
'
enabled
'
)
enabled_endpoint_names
.
add
(
json_resource_value
[
'
name
'
])
LOGGER
.
info
(
'
enabled_endpoint_names={:s}
'
.
format
(
str
(
enabled_endpoint_names
)))
for
endpoint
in
device
.
device_endpoints
:
if
endpoint
.
name
not
in
enabled_endpoint_names
:
continue
LOGGER
.
info
(
'
endpoint: {:s}
'
.
format
(
str
(
endpoint
.
name
)))
if
endpoint
.
name
not
in
enabled_endpoint_names
:
LOGGER
.
info
(
'
skipping not enabled
'
)
continue
endpoint_uuid
=
endpoint
.
endpoint_id
.
endpoint_uuid
.
uuid
self
.
_name_mapping
.
set_endpoint_name
(
endpoint_uuid
,
endpoint
.
name
)
for
value
in
endpoint
.
kpi_sample_types
:
if
value
==
KPISAMPLETYPE_UNKNOWN
:
continue
if
value
==
KPISAMPLETYPE_UNKNOWN
:
LOGGER
.
info
(
'
unknown kpi sample type
'
)
continue
kpi_descriptor
=
monitoring_pb2
.
KpiDescriptor
()
kpi_descriptor
.
kpi_description
=
device
.
device_type
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment