Commit 3f8d702f authored by douomo's avatar douomo
Browse files

check on interfaces metrics

parent 436013f3
Loading
Loading
Loading
Loading
+154 B (7.06 KiB)

File changed.

No diff preview for this file type.

+5 −2
Original line number Diff line number Diff line
@@ -32,8 +32,11 @@ def get_iface_metrics(m, int_name, metric):
    iface = tree.findall(".//ns0:"+"interface", namespaces={'ns0': 'urn:ietf:params:xml:ns:yang:ietf-interfaces','ns1': 'urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link'})
    if len(iface)>0:
        BuiltIn().log_to_console("Found iface")
        metric = iface[0].findall(".//ns1:"+metric, namespaces={'ns0': 'urn:ietf:params:xml:ns:yang:ietf-interfaces','ns1': 'urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link'})
        return metric[0].text
        value = iface[0].findall(".//ns1:"+metric, namespaces={'ns0': 'urn:ietf:params:xml:ns:yang:ietf-interfaces','ns1': 'urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link'})
        if len(value)==0:
            BuiltIn().log_to_console(metric+" not found")
            return metric+" not found"        
        return value[0].text
    else:
        return "No iface found"
    
+12 −14
Original line number Diff line number Diff line
@@ -4,31 +4,29 @@ import xml.etree.ElementTree as ET
from ncclient import manager


def check_qos(xml_reply):
    tree = ET.fromstring(xml_reply.encode())
    #print(tree)
    ns = {'ns0': 'urn:ietf:params:xml:ns:yang:ietf-interfaces','ns1': 'urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link'}
    value = tree.findall(".//ns0:"+"interface", namespaces=ns)
    print(value)
    txlvl = value[0].findall(".//ns1:"+"actual-transmitted-level", namespaces=ns)
    print(txlvl[0].text)

def get_iface_metrics(m, metric):
    cfg = m
    print(cfg)
    tree = ET.fromstring(cfg)
    iface = tree.findall(".//ns0:interface", namespaces={'ns0': 'urn:ietf:params:xml:ns:yang:ietf-interfaces','ns1': 'urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link'})
    iface = tree.findall(".//ns0:"+"interface", namespaces={'ns0': 'urn:ietf:params:xml:ns:yang:ietf-interfaces','ns1': 'urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link'})
    if len(iface)>0:
        print("Found iface")
        metric = iface[0].findall(".//ns1:"+metric, namespaces={'ns0': 'urn:ietf:params:xml:ns:yang:ietf-interfaces','ns1': 'urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link'})
        return metric[0].text
        print("Found iface: ")
        print(iface[0])
        value = iface[0].findall(".//ns1:"+metric, namespaces={'ns0': 'urn:ietf:params:xml:ns:yang:ietf-interfaces','ns1': 'urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link'})
        if len(value)==0:
            print(metric+" not found")
            return metric+" not found"        
        return value[0].text
    else:
        return "No iface found"
    

if __name__=="__main__":
    xml_reply = """<?xml version="1.0" encoding="UTF-8"?><data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"><interface><name>CT 1/2/1</name><type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:microwaveCarrierTermination</type><actual-transmitted-level xmlns="urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link">11.3</actual-transmitted-level><actual-received-level xmlns="urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link">-31.0</actual-received-level><actual-snir xmlns="urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link">47.7</actual-snir></interface></interfaces></data>
"""
    ret = check_qos(xml_reply)
    #print(ret)
    ret = get_iface_metrics(xml_reply, "actual-transmitted-level")
    print(ret)
    
    #ret = find_in_xml(xml_reply,"actual-transmitted-level", "urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link")
    #print(ret)
 No newline at end of file