In NCM 6.0 the development team produced a very powerful and cool new feature – Config Change Templates. On the back end, these are scripts that use a SolarWinds scripting engine. On the front end, they are simple to use, menu driven templates that allow you to make bulk changes to devices across your network from the web interface. The other great thing about these templates is they are easily shareable directly within the product!
For example, say I need to change the enable password on all of the Cisco devices in my network. On the NCM website, hover on the Configs tab then click the “Config Change Templates” link. Now click “Shared Config Change Templates on thwack” and find the template you’re interested in. In this example, click Cisco (wow, it just happens there is an exact script to accomplish what I am trying to do ).
After importing the template, I can quickly run it by selecting the template, clicking “Define Variables & Run”, and providing the relevant variables (in this case, the nodes and new enable password).
After you click next, it will generate the full command output. You can preview what will be sent by expanding one of the nodes. For example, if I expand Bas-2621.lab.tex.local, I can see what will be run on the router. Also, you can specify whether the commands should be written to NVRAM or just to the running config.
Simply click Execute and you’re done. Easy enough right? Well now let’s really dig in and look at the actual script. Click on the “Config Change Templates” link again. Select the script you want to modify, and instead of clicking “Define Variables & Run”, click “Advanced Modify”. The interesting section is the “Config Change Template”, this is where the code is.
The scripting logic should appear familiar to most people with scripting or programming experience in other languages (except LISP, that’s just different((())) ).
The first section is commented out with the /* */. This is meta data to help the script engine know what variables it should ask for. To define variables, use the .PARAMETER_LABEL and .PARAMETER_DESCRIPTION pairs. Both of these are required for every variable you want to prompt the user for when they execute the script. The Context Node is the node that the script it being run against and is required for all scripts. In the example of the script to change the enable password we ran earlier, the only other information we needed was the new password.
After you have created all of your parameters, you are ready to begin with the script body itself. The next statement you should notice is “script ChangePassword”. ‘script’ should be followed by the name of the script, then the variable types and names. In our example, the new password is a string. Other valid data types are: int, string, and “swis.entity” (more on that in another blog).
After that, it is mainly a matter of defining the control flow, or logic, of your script. The standard statements are supported: If, If Else, and Foreach (see the documentation for full usage details). When you are ready to have your script write to the command line of the Node, use the follow structure:
make a cup of coffee for me
For example, in the Change Cisco Enable Password script, here is the CLI section:
enable secret @NewPassword
A great resource is the NCM documentation. Specifically, the Understanding Config Change Template Semantics help document goes into great detail about creating and modifying these scripts.
Whenever you use scripts, especially ones you download from thwack, make sure you review the script so you understand what it is doing. Also, before you click the final Execute button when running scripts, examine the output to make sure it is doing exactly what you intended.
Remember, “With great power comes great responsibility”.