cancel
Showing results for 
Search instead for 
Did you mean: 

Regex to filter VoIP port given serial number

Regex to filter VoIP port given serial number

Roc156
New Contributor

I am trying to create a regular expression that will filter just the section of the port given the last numbers of the serial number using the command sh lldp neighbor med inventory

 

I have the following output:
Port: 1/3  Index: 48                 Time: 0 days, 00:02:32
        ChassisId: Network address    IPv4  x.x.x.x
        PortId:    MAC address        00:00:00:00:00:00
        SysName:   xxxxxxxxx
        SysCap:    TB / B             (Supported/Enabled) HWRev: 9620D02L                      FWRev: hb96xxua3_1_02_S.bin
 SWRev: ha96xxua3_1_02_S.bin          SerialNumber: 10FA00001231
 ManufName: Avaya                     ModelName: 9620
 AssetID:
-------------------------------------------------------------------------------
Port: 2/5   Index: 53                 Time: 0 days, 00:02:32
        ChassisId: Network address    IPv4  x.x.x.x
        PortId:    MAC address        00:00:00:00:00:00
        SysName:   x.x.x.x
        SysCap:    TB / B             (Supported/Enabled) HWRev: 9620D02L                      FWRev: hb96xxua3_1_02_S.bin
 SWRev: ha96xxua3_1_02_S.bin          SerialNumber: 10FA00001234
 ManufName: Avaya                     ModelName: 9620
 AssetID:
-------------------------------------------------------------------------------
Port: 3/40  Index: 54                 Time: 0 days, 00:02:33
        ChassisId: Network address    IPv4  x.x.x.x
        PortId:    MAC address        00:00:00:00:00:00
        SysName:   x.x.x.x
        SysCap:    TB / B             (Supported/Enabled) HWRev: 9620D02L                      FWRev: hb96xxua3_1_02_S.bin
 SWRev: ha96xxua3_1_02_S.bin          SerialNumber: 10FA00001235
 ManufName: Avaya                     ModelName: 9620
 AssetID:
-------------------------------------------------------------------------------

 

I would like to show the port for the serial number tat ends with 001234. So I would like the following output:


Port: 2/5   Index: 53                 Time: 0 days, 00:02:32
        ChassisId: Network address    IPv4  x.x.x.x
        PortId:    MAC address        00:00:00:00:00:00
        SysName:   x.x.x.x
        SysCap:    TB / B             (Supported/Enabled) HWRev: 9620D02L                      FWRev: hb96xxua3_1_02_S.bin
 SWRev: ha96xxua3_1_02_S.bin          SerialNumber: 10FA00001234
 ManufName: Avaya                     ModelName: 9620
 AssetID:
-------------------------------------------------------------------------------

 

So far I have tried the following regex expression, but it doesn’t display anything:

sh lldp neighbor med inventory | find /Port.001234/

1 ACCEPTED SOLUTION

Miguel-Angel_RO
Valued Contributor II

Roc156, Dilraj,

ERS is running on VxWorks with a limited support on regex expressions.

257b1ac9059f4483bd2d6f96d6be2daa_60933e68-65e0-4ddb-a62a-324a13c55db8.png
257b1ac9059f4483bd2d6f96d6be2daa_8c1fc0c1-9006-4d0f-b6f6-c153b9f59c7b.png

We cannot match the standard “\n” so the dirty solution I have is the following regex:

sh lldp neighbor med inventory | match "(Port: .+\/.+).+|SerialNumber: .+1234"

Regards

Mig

View solution in original post

20 REPLIES 20

Miguel-Angel_RO
Valued Contributor II

Just seen the wrong group ERS instead of EXOS 3e8d2aea91344457ab3960aea9e8bed1_1f601.png

I’ll see it on ERS

 

Miguel-Angel_RO
Valued Contributor II

Roc156,

 

Follow this method https://gtacknowledge.extremenetworks.com/articles/How_To/How-to-use-Python-on-EXOS using this script will give the good result:

import re
regex = r"(Port:\s\d+\/\d+).+\n.+\n.+\n.+\n.+\n.+(SerialNumber:\s.+1234)"
test_str = exsh.clicmd("sh lldp neighbor med inventory",True)
    matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
    for groupNum in range(0, len(match.groups())):
        groupNum = groupNum + 1
        print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))

Adapt it for your needs and enjoy c381854f6078423683e5c1a8b257570d_1f609.png

 

Mig

Miguel-Angel_RO
Valued Contributor II

Roc156,

 

You can try a dirty work around with this giving a set of information to be cleaned afterward:

Port:\s\d+\/\d+|SerialNumber:\s.+1234

 

Mig

Dilraj_Singh_Kh
Extreme Employee

Hi Miguel,

I didn’t test this on EXOS since the request from @Roc156 was for ERS 4900. Why I expect it to work for ERS is because the CLI help shows that it’s capable of doing so. See below:

4926GTS-PWR+#show lldp neighbor med inventory | ?
Pipe Filter
count Count lines of output
except Ignore lines of output matching a regular expression
find Begin with the line that matches a regular expression
head Display only the first few lines of output
match Only show output lines matching a regular expression
no-more Disable pagination for the current command
tail Display only the last few lines of output

Notice here, it says “regular expression” at the end of except, find and match option.

Regards,
DILRAJ

Miguel-Angel_RO
Valued Contributor II

Dilraj,

 

It seems that EXOS doesn’t like to output multilines.

On another hand I don’t see how to pass to the OS the definition of the groups in the regex.

See below on GNS3:

 

* EXOS-VM.25 # show lldp neighbors detailed 

-----------------------------------------------------------------------------

LLDP Port 10 detected 1 neighbor

  Neighbor: 0C:E7:6D:63:0B:00/10, age 3 seconds

    - Chassis ID type: MAC address (4)

      Chassis ID     : 0C:E7:6D:63:0B:00

    - Port ID type: ifName (5)

      Port ID     : "10"

    - Time To Live: 120 seconds

    - System Name: "EXOS-VM"

    - System Description: "ExtremeXOS (EXOS-VM) version 30.5.1.15 30.5.1.15 \

                           by release-manager on Thu Jan 30 21:18:36 EST 202\

                           0"

 

* EXOS-VM.26 # show lldp neighbors detailed | grep "LLDP Port .+\n"

LLDP Port 10 detected 1 neighbor

* EXOS-VM.27 # show lldp neighbors detailed | grep "LLDP Port .+\n\s"

* EXOS-VM.28 # 

Mig

GTM-P2G8KFN