The purpose of this blog is to provide basic explanation of how variables and custom properties can be used in NCM scripts. Both of them enable network administrator to

 

  • replace hardcoded statements by node-dependent values
  • execute actions on many devices automatically, which means reducing the amount of tasks that must be performed manually

 

Examples of activities you may want to automate are

  1. Using scripts
    • Downloading configuration files
    • Uploading configuration files
    • Uploading IOS images
    • Updating login banners
    • Updating access control lists (ACLs)
  2. Using config change templates
    • Changing VLAN membership by device port
    • Configuring device interfaces based on description
    • Enabling IPSLA for VOIP implementations
    • Managing NetFlow collection at the source devices

 

Custom properties enable you to attach additional information to your nodes to help you with e.g.

  • Organization – physical location of the device, its purpose / category, distinguishing between testing devices and those in production etc.
  • Bulk updates – create a custom property like ${NewIP}, populate with values and perform bulk update for all devices with one script.
  • Customer support (e.g. for MSPs) – support contact information per device, SLA type, contract number, etc.
  • Many other tasks where node-dependent information plays an important role.

 

Custom Properties Management

 

Custom properties must be first created using Custom Property Editor on your Orion server (Start -> All Programs -> SolarWinds Orion -> Grouping and Access Control -> Custom Property Editor).

 

You can either add some of the predefined properties, or build a property from scratch.

CP-Editor.PNG

Then you need to populate the newly created properties with values.You can do it manually

CP-Editor2.PNG

or import the values from a file.

CP-Editor3.PNG

 

For more information, please watch http://www.solarwinds.com/resources/videos/video-tutorial-managing-custom-properties-in-orion-npm.html.

 

Command Scripts

NCM-Web-Scripts.PNG

With the appropriate use of variables, a single script can be executed on several different devices, without concern for syntax differences. Scripts are delivered one line at a time to the target devices.

 

Variables and Custom Properties within Scripts

 

Variables and custom properties always begin with a dollar sign and a curly brace (${) and end with a curly brace (}).

 

Example: The following script contains commands with variables to remove the public read-only community string.

${EnterConfigMode}                         enter configuration mode – device-dependent
no snmp-server community public RO        
remove the community string – common for many devices
${ExitConfigMode}                         
exit configuration mode
${SaveConfig}                             
write configuration to memory
${Reboot}                                 
reboot the device

 

The script is parsed in a different way for e.g. Cisco IOS devices and e.g. a Dell PowerConnect switch. Device-dependent variables like the above ${EnterConfigMode}, ${ExitConfigMode}, etc. are defined in device command templates (located in <Orion directory>\NCM\Device Types).

 

Custom properties, previously created and populated in the Custom Property Editor, can be referenced in the same way – for example ${City}, ${Department}, etc.

 

More details, together with the list of predefined variables that can be used in command scripts, can be found in Orion Network Configuration Manager Administrator Guide.

 

Config Change Templates

 

Config Change Templates are even more powerful than the scripts alone; they have the power of a programming language that enables you to create very sophisticated config change routines.

NCM-CCT.PNG

Most fundamentally, the framework for creating config change templates depends on the SolarWinds Information Service (SWIS), an API installed with NCM that interacts with inventory data in the NCM database. Any device that has not been inventoried in NCM cannot be targeted with a config change template. Each object in a device inventory is a SWIS entity that can be referenced in specific ways within scripts.

 

Variables within Templates

 

Variables in config change templates always begin with an at sign, e.g. @TargetPorts. Variables that you can use are given by the input parameters that you specified for your template. Example:

 

script ConfigureVLANmembershipCiscoIOS (
NCM.Nodes @ContextNode,
NCM.Interfaces[] @TargetPorts,
NCM.VLANs[] @VlansToRemove,
NCM.VLANs[] @VlanToAssign
)


In our example, the variables that you can use in the body of the template are @ContextNode, @TargetPorts, @VlansToRemove, and @VlanToAssign.

 

Note: Each template must have at least one parameter – the node. Other parameters are optional and depend on what you want to achieve with the template.

 

As the declaration suggests, variables @TargetPorts, @VlansToRemove, and @VlanToAssign are arrays; you can iterate through them:

foreach (@portItem in @TargetPorts)
{
  CLI
  {
    …

 

Please note that @portItem is declared implicitly, i.e. when used for the first time.

 

Custom Properties within Templates

 

Custom properties are tied with nodes, and therefore can be referenced via the node parameter:

 

script BaseChangeTemplate (NCM.Nodes @ContextNode)
{
  CLI
  {
    show @ContextNode.MyCustomProperty
  }
}

 

Assuming we have created and filled in the AssetTag custom property for our devices, we can make use of e.g. it in the following way to change access lists:

 

script ChangeAccessList (NCM.Nodes @ContextNode)
{
  string @myip = '10.10.'
  @myip = @myip + @ContextNode.AssetTag        
here we make the asset tag part of the IP address
  @myip = @myip + '.32'                        
finish building IP
  CLI                                          
commands within a CLI block are sent to the device
  {
    configure terminal
    no access-list 112
    access-list 112 remark This is a test
    access-list 112 permit tcp @myip 0.0.0.31 host 123.234.123.234 eq 445      
include the IP with asset tag info in the access list
  }
}

 

For exhaustive information on config change templates, please see Orion Network Configuration Manager Administrator Guide.