Reply

CSS: List Pattern Matching

NMay
Techie
Posts: 5
3539     0

Hi,

Just wondering if there is a way to include/exclude SVI's using patterns in a list, for a trigger filter.  So far I've only been able to match exact values in the list using getListValue().  Thanks for any help you can offer!

Ok, sorry for the typo...I

NMay
Techie
Posts: 5
3539     0

Ok, sorry for the typo...I meant CCS.

Nathan,

MGriffin
Techie
Posts: 37
3539     0

Nathan,

It's always most helpful to provide example of what you're doing, with a thorough explanation of the end-goal.

Could you attach the script, or relevant segment of, being used?

 

Thanks Mike!  See below.

NMay
Techie
Posts: 5
3539     0

Thanks Mike!  See below.  Just want to exclude ranges a bit more efficiently, as with "172.*", but I've only been able to match a list item exactly, such as "172.16.15.25/25".

 

 

Script-Filter:
    $Vendor eq "Cisco"
    and ($Type like /Switch/ or $Type like /Switch-Router/)
    and $sysDescr like /IOS/

########################################################################
Action:
    Get All Interfaces

Action-Description:
    Execute the "show interfaces" command and process the output
    using the "Process Interfaces" trigger.

Action-Commands:
    SET: $updateMade = "no"
    show interfaces

Output-Triggers:
    Process Interfaces
    
    

########################################################################
Trigger:
          Process Interfaces

Trigger-Description:
    For each vlan  interface, check interface status and IP.

Trigger-Variables:
    $ifName    string
    $IPAddress    string

Trigger-Template:
    [[$ifName]] is up, line protocol is up
    ...
    Internet address is [[$IPAddress]]

Trigger-Commands:
    SET: $excludedIP = getListValue(UserVlan_Net_Exclusions,IP,$IPAddress,IP,no)

Output-Triggers:
    Apply Config

########################################################################
Trigger:
    Apply Config

Trigger-Description:
    Apply config if interface attributes are not excluded

Trigger-Filter:
    $excludedIP eq "no"

Trigger-Commands:
    conf t
    interface $ifName 
    desc user_data
    exit
    exit
    SET: $updateMade = "yes"
    
########################################################################
Action:
    Write Memory

Action-Description:
    If the $updateMade variable is "yes", save the current configuration.

Action-Filter:
    $updateMade eq "yes"

Action-Commands:
    write memory

########################################################################


           
########################################################################

Any ideas?   Thanks, Nathan

NMay
Techie
Posts: 5
3539     0

Any ideas?

 

Thanks,
Nathan

Nathan,

MGriffin
Techie
Posts: 37
3539     0

Nathan,

A list lookup is intended to be exact.

From what I can tell of your script, the iface info is being pulled and stored in a variable, specifically $ifName & $IPAddress, which is then used for a list lookup match.  If the IP does not exist in the list, the default of 'no' is assigned to the control variable, which then permits the script to proceed.

I'm still not clear on exactly what your intentions are.

You stated:

'Just want to exclude ranges a bit more efficiently, as with "172.*"',

This statement doesn't translate very well, could you provide example?

I notice in your list lookup, you're also returning the same value that you're comparing - is this done on purpose or is it something that could be further utilized to resolve your query?

In an attempt at translation of your statement; I will go out on a limb here and say that you want to cut down the matched iface IP to the first octet, for use in the list lookup match.


Trigger-Template:
    [[$ifName]] is up, line protocol is up
    ...
    Internet address is [[$IPAddress]]

Trigger-Commands:
    SET: $IPAddress =~ s/\.\d{1,3}\.\d{1,3}\.\d{1,3}$//
    SET: $excludedIP = getListValue(UserVlan_Net_Exclusions,IP,$IPAddress,IP,no)

Now, the IPAddress is trimmed to the first octet, and that is what will be used for the list lookup match; I.E. "172", instead of "172.10.128.128".

For more sophisticated use

Adviser
Posts: 357
3539     0

For more sophisticated use cases, you are better off with a Perl script. You still won't be able to do pattern-based searches of a list, but you can pull the list elements all back and do the search directly in Perl.

Highlighted

Thanks guys!

NMay
Techie
Posts: 5
3539     0

Thanks guys!

Showing results for 
Search instead for 
Do you mean 

Recommended for You