Solved

Regex to filter VoIP port given serial number

  • 8 September 2020
  • 20 replies
  • 190 views

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/

icon

Best answer by Miguel-Angel RODRIGUEZ-GARCIA 25 September 2020, 10:59

Roc156, Dilraj,

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

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 original

20 replies

Userlevel 2

What product is this question about and what version of software is being used?

What product is this question about and what version of software is being used?

 

I am testing specifically on a 4950GTS-PWR+ with SW version 7.7.1

Userlevel 4

Try this:

Port: \d+\/\d+.*\n.*\n.*\n.*\n.*\n.*SerialNumber: \S+001234\n.*\n.*

I ran the command sh lldp neighbor med inventory | find Port: \d+\/\d+.*\n.*\n.*\n.*\n.*\n.*SerialNumber: \S+001234\n.*\n.* , but got an Invalid input detected at the first \d after Port: .

Userlevel 4

I don’t think you can do a direct regex search on the CLI. You might want to copy the output and put it is some word editor like Notepad++ and try it there.

Userlevel 4

Did it work for you?

Did you mean that I should copy the output to Notepad and run a RegEx with that output?

I thought the ACLI had regex filtering.

Userlevel 4

Try this:

Port:\s\d+\/\d+.*\n.*\n.*\n.*\n.*\n.*SerialNumber:\s\S+001234\n.*\n.*

 

I think it has some problems processing space. I have now replaced it with “\s”

 

Let me know.

I don’t get an error, but it does not return anything.

Userlevel 5
Badge +1

Roc156,

 

Try with this (qick and dirty) regex: (Port: \d+\/\d+).+\n.+\n.+\n.+\n.+\n.+SerialNumber: (.+1234)

Playing on https://regex101.com/

As here:

Catching the different occurrences of the Group1 will give the portids

 

Mig

Userlevel 4

Hi Miguel,

Thanks for your help. If you do a normal regex it works, even mine worked as well. The main thing here is to execute the regex directly on the CLI which doesn’t seems to be working.

 

Hi Roc156,

I understand what you are saying. Even I am getting the same in my lab test. Maybe there is some limitation. You might want to open up a GTAC case for this so that the behavior can be verified by the engineering team.

 

Regards,
DILRAJ

Userlevel 5
Badge +1

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

Userlevel 4

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

Userlevel 5
Badge +1

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

Userlevel 5
Badge +1

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 :wink:

 

Mig

Userlevel 5
Badge +1

Just seen the wrong group ERS instead of EXOS :grin:

I’ll see it on ERS

 

Userlevel 5
Badge +1

Roc156, Dilraj,

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

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

@Miguel-Angel RODRIGUEZ-GARCIA I tried the dirty solution, but it only returns the first line for all the ports.I guess since it is a limited set of regex supported, maybe this may not be possible on the ERS.

Thanks a bunch, though!

Userlevel 5
Badge +1

Roc156,

It will return the the first line for all the ports and the serial if it meet the REGX pattern 1234

Example:

-------------------------------------------------------------------------------
Port: 4/46  Index: 676                Time: 230 days, 12:51:46
        ChassisId: Network address    IPv4  10.22.235.90
        PortId:    MAC address        00:08:5d:69:80:2f
        SysName:   Mitel IP Phone
        SysCap:    TB / TB            (Supported/Enabled)
        PortDesc:  port 0
        SysDescr:  Mitel IP Phone

 HWRev: 6865i                         FWRev: 5.1.0.5048
 SWRev: 5.1.0.5048                    SerialNumber: 00-08-5D-69-80-2F
 ManufName: Mitel                     ModelName: 6865i
 AssetID: 00-08-5D-69-80-2F
-------------------------------------------------------------------------------
Port: 3/44  Index: 677                Time: 230 days, 22:50:03
        ChassisId: MAC address        00:d8:61:48:5f:07
        PortId:    MAC address        00:d8:61:48:5f:07

-------------------------------------------------------------------------------
Sys capability: O-Other; R-Repeater; B-Bridge; W-WLAN accesspoint; r-Router;
T-Telephone; D-DOCSIS cable device; S-Station only.
Total neighbors: 43
XXX#sh lldp neighbor med inventory | match "(Port: .+\/.+).+|SerialNumber: .+80-2F"
Port: 1/49  Index: 1                  Time: 157 days, 01:09:35
Port: 3/49  Index: 3                  Time: 157 days, 04:30:24
Port: 1/37  Index: 422                Time: 179 days, 11:41:19
Port: 3/27  Index: 444                Time: 187 days, 11:24:38
Port: 1/25  Index: 453                Time: 187 days, 11:28:02
Port: 3/25  Index: 459                Time: 187 days, 11:30:27
Port: 3/15  Index: 461                Time: 187 days, 11:30:54
Port: 3/21  Index: 462                Time: 187 days, 11:31:22
Port: 3/8   Index: 477                Time: 187 days, 11:39:16
Port: 2/13  Index: 481                Time: 187 days, 11:40:58
Port: 3/23  Index: 493                Time: 187 days, 11:45:28
Port: 1/13  Index: 505                Time: 187 days, 11:49:03
Port: 1/31  Index: 536                Time: 187 days, 11:56:00
Port: 2/38  Index: 538                Time: 187 days, 11:56:21
Port: 2/8   Index: 539                Time: 187 days, 11:56:38
Port: 3/32  Index: 542                Time: 187 days, 12:02:14
Port: 1/27  Index: 556                Time: 187 days, 12:06:58
Port: 3/19  Index: 558                Time: 187 days, 12:07:27
Port: 2/12  Index: 574                Time: 187 days, 12:18:38
Port: 2/10  Index: 576                Time: 187 days, 12:20:16
Port: 1/40  Index: 578                Time: 187 days, 12:36:42
Port: 1/38  Index: 581                Time: 187 days, 12:49:10
Port: 2/14  Index: 592                Time: 188 days, 08:14:41
Port: 3/3   Index: 594                Time: 190 days, 01:42:30
Port: 3/12  Index: 595                Time: 190 days, 02:33:44
Port: 3/48  Index: 652                Time: 221 days, 20:10:38
Port: 1/46  Index: 657                Time: 227 days, 01:32:28
Port: 1/45  Index: 658                Time: 227 days, 01:32:30
Port: 2/46  Index: 659                Time: 227 days, 01:32:39
Port: 1/47  Index: 660                Time: 227 days, 01:32:46
Port: 2/48  Index: 661                Time: 227 days, 01:32:48
Port: 2/26  Index: 662                Time: 227 days, 01:33:28
Port: 4/47  Index: 663                Time: 227 days, 01:33:58
Port: 4/48  Index: 664                Time: 227 days, 01:33:59
Port: 1/42  Index: 665                Time: 227 days, 01:34:02
Port: 1/48  Index: 666                Time: 227 days, 01:34:09
Port: 1/29  Index: 668                Time: 227 days, 01:43:20
Port: 1/35  Index: 672                Time: 227 days, 01:45:14
Port: 1/36  Index: 673                Time: 227 days, 01:45:36
Port: 1/34  Index: 674                Time: 227 days, 01:46:09
Port: 1/26  Index: 675                Time: 228 days, 09:34:00
Port: 4/46  Index: 676                Time: 230 days, 12:51:46
 SWRev: 5.1.0.5048                    SerialNumber: 00-08-5D-69-80-2F

Port: 3/44  Index: 677                Time: 230 days, 22:50:03
XXX#

Up to you to adapt it 

Oh wait! I think I cancelled it before giving it a chance. LOL.

I guess this dirty fix, will have to do.

Thanks again!

Reply