netenglabs / suzieq

Using network observability to operate and design healthier networks
https://www.stardustsystems.net/
Apache License 2.0
793 stars 106 forks source link

fix statusChangeTimestamp for alternative routes #419

Open aegiacometti opened 3 years ago

aegiacometti commented 3 years ago

Describe the bug The template is matching only one value for a route and its alternatives.

ospf 2 routes

Suzie-cli display only one reference time (evidence)

root> route show columns='hostname prefix nexthopIps oifs statusChangeTimestamp'                                                                                                                                                      
    hostname           prefix          nexthopIps                                oifs  statusChangeTimestamp
1   OSPF-0-4       1.0.1.0/24  [3.5.0.1, 3.4.0.1]  [FastEthernet1/0, FastEthernet0/0]          1633737065340

It would be necessary to change the Value statusChangeTimestamp to a List in the TextFSM template iosxe_show_route.tfsm.

Then adapt the script routes.py to support a list of values instead of only one. Change ending lines of function def _clean_iosxr_data to something like this

            lastchange = []
            for ele in entry.get('statusChangeTimestamp', ''):
                if ele:
                    if re.match(r'^\d{2}:\d{2}:\d{2}$', ele):
                        ele = ele.split(':')
                        ele = (f'{ele[0]} hour '
                               f'{ele[1]}:{ele[2]} mins ago')
                    ele = parse(
                        ele,
                        settings={'RELATIVE_BASE':
                                  datetime.fromtimestamp(
                                      (raw_data[0]['timestamp'])/1000), })
                if ele:
                    entry['statusChangeTimestamp'] = ele.timestamp()*1000
                else:
                    entry['statusChangeTimestamp'] = 0

                lastchange.append(ele)

            entry['statusChangeTimestamp'] = lastchange

And then more changes would be needed in the rest of the code. I will investigate more...

aegiacometti commented 3 years ago

Also, the schema routes.avsc for statusChangeTimestamp key should be updated to

    {
        "name": "statusChangeTimestamp",
        "type": {
            "type": "array",
            "items": {
                "name": "statusChangeTimeSt",
                "type": "long"
            }
        },
        "description": "The last time this route changed"
    },

Which I think will trigger a major update in all the templates and scripts for "routes"