Welcome to Netcordia Community Sign in | Join | Help
in Search

Template-Trigger matching with '...'

Last post 02-11-2010 10:02 AM by tslattery. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 02-08-2010 4:57 PM

    • tslattery
    • Top 10 Contributor
    • Joined on 09-12-2007
    • Chesapeake Netcraftsmen

    Template-Trigger matching with '...'

    I am trying to match a section of a Cisco config:

    logging source-interface Loopback0
    logging 10.90.99.11
    access-list 1 permit 10.90.9.0 0.0.0.255
    access-list 1 permit 10.90.99.0 0.0.0.255
    access-list 1 permit 10.90.92.0 0.0.0.31
    snmp-server community test RO 1
    snmp-server trap-source Loopback0
    snmp-server enable traps snmp authentication linkdown linkup coldstart warmstart

    using the Trigger-Template:

    access-list 1 permit 10.90.9.0 0.0.0.255
    access-list 1 permit 10.90.99.0 0.0.0.255
    access-list 1 permit 10.90.92.0 0.0.0.31
    ...
    snmp-server community test RO 1

    The reason for the '...' is that there may be additional access lists, causing the config to look like this:

    logging source-interface Loopback0
    logging 10.90.99.11
    access-list 1 permit 10.90.9.0 0.0.0.255
    access-list 1 permit 10.90.99.0 0.0.0.255
    access-list 1 permit 10.90.92.0 0.0.0.31
    access-list 12 permit 10.90.92.0 0.0.0.31
    snmp-server community test RO 1
    snmp-server trap-source Loopback0
    snmp-server enable traps snmp authentication linkdown linkup coldstart warmstart

    The scripting docs say:

    The pattern matching notation “...” that appears in the above Trigger-Template means “match 0 or more lines” and is used to skip over multiple lines of text if you are scanning for the next occurrence of a specific pattern (e.g., the text Keepalive).

    But it looks to me like the '...' syntax wants to match at least one line, according to the tests I've been doing with the "Regular Expression Test" link that's available when editing a script.  Its operation matches what I'm seeing in the real script.

    Has anyone gotten this to work?  Am I doing something wrong?

    Thanks!

     

  • 02-08-2010 5:15 PM In reply to

    Re: Template-Trigger matching with '...'

    Terry,

    You're correct that "..." matches 1 or more lines.

    Please refer to this thread for a possible solution.

    http://www.netcordia.com/community/forums/t/1132.aspx

     

    Mike Griffin
    Netcordia TAC
    support@netcordia.com
    410 266 6161 option 3
  • 02-08-2010 7:10 PM In reply to

    • tslattery
    • Top 10 Contributor
    • Joined on 09-12-2007
    • Chesapeake Netcraftsmen

    Re: Template-Trigger matching with '...'

    Thanks, MIke.  I'll take a look at using it.  You should make a note to update the docs or have development change the way '...' works.

  • 02-11-2010 8:49 AM In reply to

    • tslattery
    • Top 10 Contributor
    • Joined on 09-12-2007
    • Chesapeake Netcraftsmen

    Re: Template-Trigger matching with '...'

    If I understand the other thread, I would need to enumerate all possible alternatives, each one to be 'or'ed with the others.  I doubt that using '.*' as the matching string would accomplish what I want, which is to match all the possible commands that could appear between two statements without globbing more than it should.

    To clarify, here's an example.

    The config currently contains the following:

    access-list 1 permit 10.90.9.0 0.0.0.255
    access-list 1 permit 10.90.99.0 0.0.0.255
    access-list 1 permit 10.90.92.0 0.0.0.31
    snmp-server community test RO 1

    But soon, I'll be adding another ACL, so the config will look like this:

    access-list 1 permit 10.90.9.0 0.0.0.255
    access-list 1 permit 10.90.99.0 0.0.0.255
    access-list 1 permit 10.90.92.0 0.0.0.31
    access-list 5 remark testing
    snmp-server community test RO 1

    And someone may add an extended access list, making it look like this:

    access-list 1 permit 10.90.9.0 0.0.0.255
    access-list 1 permit 10.90.99.0 0.0.0.255
    access-list 1 permit 10.90.92.0 0.0.0.31
    access-list 5 remark testing
    access-list 101 remark testing
    snmp-server community test RO 1

    There may be an arbitrary number of access lists, each with their own ID.  My thinking is that there will be other similar situations where enumerating the list of possilities is not very feasible.

    So I think the preferred approach is to fix the '...' syntax so it matches 0 or more, instead of updating the docs.

     

  • 02-11-2010 9:51 AM In reply to

    Re: Template-Trigger matching with '...'

    Terry,

    The purpose of linking you to the other post was to show you that an OR can be put into the template directive.

    If you rewrote your specific trigger-template to this, it would correctly match:

    access-list 1 permit 10.90.9.0 0.0.0.255
    access-list 1 permit 10.90.99.0 0.0.0.255
    access-list 1 permit 10.90.92.0 0.0.0.31
    ...
    snmp-server community test RO 1
    |
    access-list 1 permit 10.90.9.0 0.0.0.255
    access-list 1 permit 10.90.99.0 0.0.0.255
    access-list 1 permit 10.90.92.0 0.0.0.31
    snmp-server community test RO 1

    Mike Griffin
    Netcordia TAC
    support@netcordia.com
    410 266 6161 option 3
  • 02-11-2010 10:02 AM In reply to

    • tslattery
    • Top 10 Contributor
    • Joined on 09-12-2007
    • Chesapeake Netcraftsmen

    Re: Template-Trigger matching with '...'

    Good idea!  I hadn't thought of mixing the two.  Thanks!

Page 1 of 1 (6 items)