0 Replies Latest reply on Jul 20, 2017 6:19 PM by jamann@mt.gov

    Possible to use RegEx in Config Change Document

    jamann@mt.gov

      I am trying to build a script for our NOSC to be able to block mac's on a Cisco wireless controller 8540. I am trying to add in some basic error correction to the script. The mac has to be in a specific format to work on the controller, XX:XX:XX:XX:XX:XX so my thought was to get the total length of the string(17) and count the number of : (5), if those matched then run the script. The length worked but my code for the : didn't work, it would only find 3 instead of 5. So then I thought I would regex for 0-9 and A-F and then count that, that should also be 17. Neither are working and need help. I didn't change my if statement to reflect the regex, I just moved the CLI statement up so it would execute the code on the controller to show me the results. I know the CLI statements have to be moved. Any suggestions or ideas would be much appreciated!!

       

      ### This is the counting of the colon ###

      /*
      .CHANGE_TEMPLATE_DESCRIPTION
              This is a base change template to act as a starting point for other templates.
      .PLATFORM_DESCRIPTION
              Replace with details of the device platform for which the template is being created.

      .PARAMETER_LABEL @ContextNode
              NCM Node
      .PARAMETER_DESCRIPTION @ContextNode
              The node the template will operate on.  All templates require this by default. The target node is selected during the first part of the wizard so it will not be available for selection when defining values of variables.

      .PARAMETER_LABEL @MacAddr
              Macc Address
      .PARAMETER_DESCRIPTION @MacAddr
              Enter MAC Address of Client to block.  Format:"XX:XX:XX:XX:XX:XX"

      .PARAMETER_LABEL @Desc
              Description
      .PARAMETER_DESCRIPTION @Desc
              Enter brief description here - "Case#-Reason-Location"(Only have 32 characters)
              If Deleting, put delete as description

      .PARAMETER_LABEL @Action
              Action

      .PARAMETER_DESCRIPTION @Action
              Add or Delete a MAC Block

      .PARAMETER_DISPLAY_TYPE  @Action
              listbox: 1=Add|2=Delete

      */

      script BaseChangeTemplate(  
                                   NCM.Nodes @ContextNode,
                                   string @MacAddr,
                                   string @Desc,
                                   string @Action )
      {
        int @len = StrLength(@MacAddr)
        int @Delim = indexof(@MacAddr,':'')
        CLI {
        if (@Action == 'Add')
        {
         if (@len == 17)
         {
           if (@Delim == 5)
           {
             CLI {config exclusionlist add @MacAddr @Desc}
           }
         }
        }}
       
        if (@Action == 'Delete')
        {
          if (@len == 17)
          {
            if (@Delim == 5)
            {
              CLI {config exclusionlist delete @MacAddr}
            }
          }
        }
      }

       

      ### This is the RegEX ###

      /*
      .CHANGE_TEMPLATE_DESCRIPTION
              This is a base change template to act as a starting point for other templates.
      .PLATFORM_DESCRIPTION
              Replace with details of the device platform for which the template is being created.

      .PARAMETER_LABEL @ContextNode
              NCM Node
      .PARAMETER_DESCRIPTION @ContextNode
              The node the template will operate on.  All templates require this by default. The target node is selected during the first part of the wizard so it will not be available for selection when defining values of variables.

      .PARAMETER_LABEL @MacAddr
              Macc Address
      .PARAMETER_DESCRIPTION @MacAddr
              Enter MAC Address of Client to block.  Format:"XX:XX:XX:XX:XX:XX"

      .PARAMETER_LABEL @Desc
              Description
      .PARAMETER_DESCRIPTION @Desc
              Enter brief description here - "Case#-Reason-Location"(Only have 32 characters)
              If Deleting, put delete as description

      .PARAMETER_LABEL @Action
              Action

      .PARAMETER_DESCRIPTION @Action
              Add or Delete a MAC Block

      .PARAMETER_DISPLAY_TYPE  @Action
              listbox: 1=Add|2=Delete

      */

      script BaseChangeTemplate(  
                                   NCM.Nodes @ContextNode,
                                   string @MacAddr,
                                   string @Desc,
                                   string @Action )
      {
        int @len = StrLength(@MacAddr)
        string @Search = '([0-9A-Fa-f])+'
        int @Delim = indexof(@MacAddr,@Search)
        CLI {
        if (@Action == 'Add')
        {
         if (@len == 17)
         {
           if (@Delim == 5)
           {
             CLI {config exclusionlist add @MacAddr @Desc}
           }
         }
        }}
       
        if (@Action == 'Delete')
        {
          if (@len == 17)
          {
            if (@Delim == 5)
            {
              CLI {config exclusionlist delete @MacAddr}
            }
          }
        }
      }