cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
440
Views
0
Helpful
3
Replies

Subscriber pushes //private// keypaths through regex filter

u.avsec
Spotlight
Spotlight

Hey,

I have a subscriber sitting in a non service PACKAGE that is monitoring ANOTHER_PACKAGE which is a service package with a top list of devices, where their names are the key. Subscriber is registered on /ANOTHER_PACKAGE/devices

I don't want to act on everything that is going on in ANOTHER_PACKAGE; only if device is deleted, or if a particular enum node (/ANOTHER_PACKAGE/devices{rtr}/onboarding/external-systems/rfs-nso-systems) under each device is changed. So I set up a regex filter to catch what I want to act upon. It looks something like this:

 

 

def iterate(self, keypath, operation, oldval, newval, state):
    """Filter subscription."""
    keypath = str(keypath)
    self.log.info(keypath)
    if match('/ANOTHER_PACKAGE/devices{.*}/onboarding/external-systems/rfs-nso-systems$', keypath) and operation == ncs.MOP_VALUE_SET:
        state.append([operation, keypath])
        return ncs.ITER_RECURSE
    if match('/ANOTHER_PACKAGE/devices{.*}$', keypath) and operation == ncs.MOP_DELETED:
        state.append([operation, keypath])
        return ncs.ITER_RECURSE
    state = []
    return ncs.ITER_RECURSE

 

 

 When I run it though, NSO does something which I understand where it is coming from and why but not how it passes the regexes. Following is a self.log.info print of a state attribute in post_iterate:

 

 

[[4, '/ANOTHER_PACKAGE/devices{rtr}/onboarding/external-systems/rfs-nso-systems'], 
[2, '/ANOTHER_PACKAGE/devices{rtr}/onboarding/external-systems/rfs-nso{rfs-58}'], 
[2, '/ANOTHER_PACKAGE/devices{rtr}/private/device-list{rfs-58}'], 
[2, '/ANOTHER_PACKAGE/devices{rtr}/private/ned-id-list{cisco-nso-nc-5.8:cisco-nso-nc-5.8}'], 
[4, '/ANOTHER_PACKAGE/devices{sw}/onboarding/external-systems/rfs-nso-systems'], 
[2, '/ANOTHER_PACKAGE/devices{sw}/private/device-list{rfs-58}'],
[2, '/ANOTHER_PACKAGE/devices{sw}/private/ned-id-list{cisco-nso-nc-5.8:cisco-nso-nc-5.8}']]

 

 

 I checked the regexes, they work as intended. 
I tried to put ITER_STOP on the returns, which fixes the issue for one device per transaction but if multiple devices get modified in the same transaction, the second device + n won't get processed by the subscriber.
Creating devices from scratch and deleting them completely works fine. Only if I change that enum on //rfs-nso-systems to a particular value which causes the //rfs-nso leaf-list to be deleted in the process, then I get the above output.

Help


3 Replies 3

u.avsec
Spotlight
Spotlight

I ended up ditching regex and did this:

 

if 'rfs-nso-systems' in keypath:
    state.append([operation, keypath])
    return ncs.ITER_RECURSE
if keypath.count('/') == 2 and operation == ncs.MOP_DELETED:
    state.append([operation, keypath])
    return ncs.ITER_RECURSE
state = []
return ncs.ITER_RECURSE

 

Now it is fine, and faster too, I found out. Looks a bit MacGyverish though.
I don't know how those private keypaths got in, perhaps bug in re or my lack of knowledge regarding the module. It would be interesting to know.

Hi, is match part of the re python library or something else? missing your import statement.

 

It is re, yes

EDIT: I just realised my initial delete regexe was too lax. The reason I didn't figure it out was because there was a not very obvious typo in the test string I was testing with. :facepalm:  

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: