How to use variables in string concatenation

Hi folks!

 

Is there any way to use variables in a string concatenation? What I'm exactly trying to do is to make use of a variable as part of an IP address, e.g.:

 

10.10.@DataNet.122

 

Which  should lead to an output similar to: 10.10.10.122, if 10 was the specified value.

 

Output fails with the following message:

Error:Variable @DataNet.80.5 could not be matched. Possible causes of this are:
1) It has not been declared.
2) You are referencing an entity property which does not exist.
3) You are missing a closing bracket in a prior native block.

I think this problem is located in the way entities are used. Is there any possibility to escape the period after the used variable or something?

 

Thanks in advance!

Parents
  • Hi all - this is a known issue - and we do have a workaround - but it's a tiny bit messy.  

     

    This is supported: 
     
    string @String1
    string @String2
    string @String3
     
    @String3 = @String1 + @String2
     
    This can be applied to the IP scenario 10.10.@DataNet.122 by setting string variables for the literal parts of the IP, then concatenating them all together:
     
    string @IpStart = ‘10.10.’
    string @IpEnd = ‘.122’
     
    @IpStart + @DataNet + @IpEnd

     
    I hope that helps!
    --Christine
  • Hi Christineb and MarieB,

    Thank you for responding to this thread. Can you please provide something in the form of an example ncm-template for this?

    I have attempted to implement your workaround, however the proof of concept below outputs the following error.

    Error:Cannot assign 3 of type System.Int32 to variable @String3 of type string.

     

    script CreateConfig (   

                                    NCM.Nodes @ContextNode)

    {

      //TODO - insert details of change template

     

    string @String1='1'

    string @String2='2'

    string @String3 = @String1 + @String2

      //Enter CLI commands

      CLI

      {

         configure terminal

         //Use variables in commands sent

    @String3

      }

    }

     

    Also tried the following and got 3 as the result.

    script CreateConfig (   

                                    NCM.Nodes @ContextNode)

    {

      //TODO - insert details of change template

     

    string @String1='1'

    string @String2='2'

      //Enter CLI commands

      CLI

      {

         configure terminal

         //Use variables in commands sent

    @String1+@String2

      }

    }

     

    Any additional help would be greatly appreciated.

  • Let me look into this - I'll get back to you on this thread. 

    --Christine 

  • Can you confirm that you are using the NCM application itself - and not the free tool? If you are using the free tool - then you'll want to download the latest version as we did an update to support string concatenation. However, if you are having this problem with NCM or the current tool, we'll need to talk further. 

    --Christine

  • Hi Christine,

     

    Thank you. Upgrading to the latest version allowed me to implement the workaround you provided. Really appreciate you following through on this. Speaks bounds for a company that Solarwinds even provide support for free tools.

    One strange thing I did notice though, if there is a / before a variable in the CLI section of the template such as in the following example:

    boot bootstrap tftp://192.168.1.30/@IosImage

    If the entered variable for @IosImage contains a t for the for the first letter, such as test, it escapes the character and outputs the following:

    boot bootstrap tftp://192.168.1.30 est

    However, if it the variable begins with a different character, such as nest, it outputs correctly:

    boot bootstrap tftp://192.168.1.30/nest

    Small quark, but thought I might as well bring it to your attention.

     

    Thanks again,

    Johnny

Reply
  • Hi Christine,

     

    Thank you. Upgrading to the latest version allowed me to implement the workaround you provided. Really appreciate you following through on this. Speaks bounds for a company that Solarwinds even provide support for free tools.

    One strange thing I did notice though, if there is a / before a variable in the CLI section of the template such as in the following example:

    boot bootstrap tftp://192.168.1.30/@IosImage

    If the entered variable for @IosImage contains a t for the for the first letter, such as test, it escapes the character and outputs the following:

    boot bootstrap tftp://192.168.1.30 est

    However, if it the variable begins with a different character, such as nest, it outputs correctly:

    boot bootstrap tftp://192.168.1.30/nest

    Small quark, but thought I might as well bring it to your attention.

     

    Thanks again,

    Johnny

Children