Using column values in RegEx

Started by rmpf2

rmpf2

Using column values in RegEx   17 January 2019, 07:02

I would like to know if it is possible to use column values in RegEx?

For example, let's say I have a column (***not virtual) named "port" with value 9, and I call another column with a telnet script with MAC address table display to find out what MAC is on
Gi1/0/[port] ;Gi1/0/9
SoftPerfect Support forum - Andrew avatar image

Re: Using column values in RegEx   18 January 2019, 13:41

I am not sure if I understood you correctly, but you if you are using a script similar to the one you posted in the other thread and your show mac address-table looks like this:

SoftPerfect support forum

then you could do something like this:
'Return port assignments
objTelnet.Send("show mac address-table" & vbCrLf)

'Wait for shell prompt (when command finishes)
data = objTelnet.Recv("#")

'Get port column value
port = "Gi1/0/" & Input.Column("port")

'Setup a regex object
Set objRegex = New RegExp
objRegex.IgnoreCase = True
objRegex.Multiline = True
objRegex.Global = True

'This will capture MAC address from strings like
'1    000a.b82d.10e0    DYNAMIC     Gi1/0/X
objRegex.Pattern = "^\s*\d+\s*([^\s]+)\s*[^\s]+\s*" & port & "$"

Set matches = objRegex.Execute(data)
For Each match in matches
  Output.Write match.SubMatches(0)
Next
This will extract a complete list of MAC addresses, get a value from the port column and then use that value in the regex to extract MAC addresses bound to the specific port.
rmpf2

Re: Using column values in RegEx   25 January 2019, 10:37

Hi Andrew,

Today I did some tests on this. It works but needs some kind of delay before column script execution. After the initial scan the column reflect an error response over the telnet communication. I believe it is because it depends on another column that's on process to show its final value. If I do a post rescan only over that column it shows the result of the show mac address-table as expected.

What do you think? Maybe some kind of wait (sleep-delay) command on top of the script?
SoftPerfect Support forum - Andrew avatar image

Re: Using column values in RegEx   25 January 2019, 10:49

I don't think it's a matter of delay: the script is executed after all other columns are finalised. Unless the port column is another script column, in which case it may not be executed in the expected order.

You can check whether the port is there by executing the following and see what gets printed:
port = "Gi1/0/" & Input.Column("port")
Output.Write port

Also, you mentioned an error. Could you please tell what exactly you are getting?
rmpf2

Re: Using column values in RegEx   25 January 2019, 11:25

Sorry, I did not take note of the message. I don't remember the exact error but I believe was of communication base on an unknown switch IP As you mention, depends on two scripts columns Switch IP column, and Switch Port column. The VoIP phone on its web page show both (neighbour cdp). Has to be a script and not with remote XML because we are dealing with different models with different path.
rmpf2

Re: Using column values in RegEx   25 January 2019, 12:58

I wonder if assigning that column to a virtual one might solve the dilemma?
SoftPerfect Support forum - Andrew avatar image

Re: Using column values in RegEx   25 January 2019, 13:03

I have checked and indeed found that when a script referred to other script-based columns, their value would be empty. This is essentially a bug. We have fixed this in the latest builds, but there is a couple of important points to consider:
  • The latest builds increase the maximum simultaneous number of dynamic columns of the same type from 10 to 50. The /maxcols switch has been removed. While this should provide more than enough columns for any practical purpose, there is a chance that RegExes and column colours may be lost or assigned to incorrect columns. Unfortunately this has to be fixed manually, but it only needs to be done once and for all. Please make a backup copy of your config files prior to the update.
  • If a script depends on other scripts, they need to be placed in a correct order as they are executed from top to bottom, as shown below:
SoftPerfect support forum
rmpf2

Re: Using column values in RegEx   26 January 2019, 02:41

All you have done, so far, its pretty amazing!!

Thanks!!!

Do you think it might be possible to add the following to ease the restore procedure:
  1. Allow windows to be resized and maximize. Example: Visible columns, Remote scripting, etc... This might allow big amounts of data rows, including visualized regex, to be manipulated (moved or relocated) in an easier and more comfortable way.
  2. Up and down arrow buttons, maybe move to end, and move to top also (drag and drop is fantastic please don't misunderstand me).
  3. Format copy (copy regex, text, highlighting and other properties of an specific row to others).
  4. Alternative to toggle the selected rows. Example: select all, or select only those that are not already selected.
rmpf2

Re: Using column values in RegEx   26 January 2019, 06:47

Hi again,

I have been doing some tests, but every time I do any changes the program restores all the hidden columns and erases the regex and properties (especially those that are not VC). Tests where executed on visible remote scripts changes or applying some regex to a column view.
SoftPerfect Support forum - Andrew avatar image

Re: Using column values in RegEx   29 January 2019, 17:20

Thank you for your feedback. Definitely your suggestions A to D above sound useful and we'll review and implement some or all of them.

Regarding the issue where the program restores all the hidden columns and erases the regex and properties, could you please provide a reproducible test case? What exactly did you do to make it happen?

In the meantime, good news: we've implemented column layout upgrade from old configuration files. If you download the latest build, it should correctly read all columns details from your configuration files, whether you used /maxcols or not.
rmpf2

Re: Using column values in RegEx   22 February 2019, 05:58

Hi Andrew, … sorry for the delay.

I submitted the config reproducible test case via your Contact Centre facility. And I forgot to mention in my message the error of scanning a specific column-row value:
Named argument not found: 'Input.Column'

Thanks.

Reply to this topic

Sometimes you can get the answer faster if you try the forum search and/or have a look at the software user manual to see if your question has already been answered.

Our forum rules are simple:

  • Be polite.
  • Do not spam.
  • If possible, check your spelling and grammar.

Author:

Email:

Subject

A brief and informative title for your message, approximately 4–8 words:

     

Spam prevention: please enter the following code in the input field below.

 **    **  **      **  **      **  **     **  **      ** 
 ***   **  **  **  **  **  **  **  ***   ***  **  **  ** 
 ****  **  **  **  **  **  **  **  **** ****  **  **  ** 
 ** ** **  **  **  **  **  **  **  ** *** **  **  **  ** 
 **  ****  **  **  **  **  **  **  **     **  **  **  ** 
 **   ***  **  **  **  **  **  **  **     **  **  **  ** 
 **    **   ***  ***    ***  ***   **     **   ***  ***  

Message: