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.

Config Change Template IF Statements

Hey Guys I am having trouble getting my Config Template to evaluate correctly I am not sure why.  When I select the two nodes to run the script against the output it gives me is

configure terminal

hostname1

exit

The system is not matching the below IF statements.   I threw the variable @ContextNode.SysName in the middle to verify the variable was being populated as expected.

script ShiftReport (   

NCM.Nodes @ContextNode,

string @PipeSymbol

)

{

// Enter configuration mode

CLI

{ configure terminal }

// Set variables for various nodes

foreach ( @Node in @ContextNode )

{

if (@ContextNode.SysName == 'hostname1')

{

  CLI

  {sh int TenGigabitEthernet0/3/0 @PipeSymbol i tx @PipeSymbol bit}

  CLI

  {sho ip bgp @PipeSymbol i 1.1.1.1}

  CLI

   { exit }

}

CLI

{ @ContextNode.SysName } 

if (@ContextNode.SysName == 'hostname2')

{

  CLI

  {sh int TenGigabitEthernet0/3/0 @PipeSymbol i tx @PipeSymbol bit}

  CLI

  {sho ip bgp @PipeSymbol i 2.2.2.2}

  CLI

   { exit }

}

// Exit configuration mode

CLI

  { exit }

}

}

}

  • Hi,

    you are looping through the nodes you pick from the list. But in your if-statement you try to access the whole array with .SysName, which will not work.

    You need to use @Node.SysName to access the current element in the loop and it should work.

    Example:

    foreach ( @Node in @ContextNode )

    {

    if (@Node.SysName == 'hostname1')

    {

      CLI

      {sh int TenGigabitEthernet0/3/0 @PipeSymbol i tx @PipeSymbol bit}

      CLI

      {sho ip bgp @PipeSymbol i 1.1.1.1}

      CLI

       { exit }

    }

    Best Regards

    Rene

  • Thank you fr the help, I changed the last 3 times @ContextNode is mentioned to @Node but I got the exact same result.    It gave me 2 scripts one says


    configure terminal

    hostname1

    exit

    the other says

    configure terminal

    hostname2

    exit

    I would expect it to be something like

    configure terminal

    sh int TenGigabitEthernet0/3/0 | i tx | bit

    sho ip bgp | i 1.1.1.1

    exit

    hostname1

    exit

  • Could you try to replace the double equal with 'contains' ?

    foreach ( @Node in @ContextNode )

    {

    if (@Node.SysName contains 'hostname1')

    {

      CLI

      {sh int TenGigabitEthernet0/3/0 @PipeSymbol i tx @PipeSymbol bit}

      CLI

      {sho ip bgp @PipeSymbol i 1.1.1.1}

      CLI

       { exit }

    }

  • I have no idea why that worked but it did.   The data in the @Node.SysName variable matched what I was specifying in the compare ...... but I will take it.   Thanks for the help!!