This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

NCM config change template for logging source-interface

I am trying to create a change template that will look at each interface on a node and capture the IP. I then want to take that IP and apply it to a logging source-interface command only if the interface type is a Loopback. I have the following script to try and do this, but i don't have the scripting experience to know what I am missing.

/*
.CHANGE_TEMPLATE_DESCRIPTION
This change template is used to set the logging source-interface to the loopback interface if there is one.
.CHANGE_TEMPLATE_TAGGS
Logging
.PLATFORM_DESCRIPTION
Cisco IOS

.PARAMETER_LABEL @ContextNode
NCM Node
.PARAMETER_DESCRIPTION @ContextNode
The node the template will operate on.

*/

script LoggingSourceTemplate(NCM.Nodes @ContextNode)


//Loop through selected nodes
{

foreach (@interfaceItem in @ContextNode.Interfaces)
{

foreach(@ip in @interfaceItem.IpAddresses)

{

if (@interfaceItem.InterfaceType == 'Loopback')

{

CLI

{

logging source-interface @ip

}

}

}

}

}


{

  • Try this script....

    /*
    .CHANGE_TEMPLATE_DESCRIPTION
    This change template is used to set the syslog server and logging source-interface to the active NCM management interface
    .CHANGE_TEMPLATE_TAGGS
    Logging
    .PLATFORM_DESCRIPTION
    Cisco IOS

    .PARAMETER_LABEL @ContextNode
    NCM Node
    .PARAMETER_DESCRIPTION @ContextNode
    The node the template will operate on.

    */
    script UpdateLoggingConfiguration( NCM.Nodes @ContextNode)
    {
    // Configure the Syslog destination and Syslog logging level (<= informational)
    CLI
    {
      conf t
      logging host [IP-ADDRESS-OF-SYSLOG-SERVER-HERE]
      logging trap informational
    }

    // Loop through selected nodes to find the mangement interface of this node
    foreach (@interfaceItem in @ContextNode.Interfaces)
    {
      foreach(@ip in @interfaceItem.IpAddresses)
      {
       if (@ip.IPAddress == @ContextNode.AgentIP)
       {
        CLI
        {
         logging source-interface @interfaceItem.InterfaceName
        }
       }
      }
    }
    }

  • Thank you very much. It´s working perfectly!!!