Submit a ticketCall us

Get a crash course on Network Monitoring delivered right to your inbox
This free 7-day email course provides a primer to the philosophy, theory, and fundamental concepts involved in IT monitoring. Lessons will explain not only how to perform various monitoring tasks, but why and when you should use them. Sign up now.

Home > Success Center > Kiwi CatTools > Kiwi CatTools 3.11 Administrator Guide > Activities > Activities list > Device.CLI.Send commands > Running External Scripts

Running External Scripts

Table of contents
No headers
Created by Caroline Juszczak, last modified by Caroline Juszczak on Jun 28, 2016

Views: 15 Votes: 0 Revisions: 1

 

Overview

 

It is possible to run an external VB script from within the Device.CLI.Send commands activity and use the return value from the external script as part of a CLI command to be executed.

 

When creating external scripts for use within CatTools, you will need to edit the script files using a script editor.

 

A number of useful Functions and Variables are exposed for use by external scripts.

 

Supported Device Scripts

 

Cisco.Switch.IOS
Cisco.Router.General
Cisco.Other.CUE
Cisco.Wireless.LAN
Cisco.WAE
Aruba.ArubaOS.General

Usage

 

To run an external script from within the Device.CLI.Send commands activity a command should be entered in the following format:

 

%ctRunExternalScript("PathToScript",["VariableString"])

 

PathToScript;

Is the full path to the script to be run.

It must be wrapped in quotes as shown.

 

VariableString;

Is a string containing values to pass to the external script.

It must be wrapped in quotes as shown.

It cannot contain any quotes.

It is optional as the script may not require variables.

If you need to pass more than one variable to the script then it is up to you how you achieve this within the confines of the variable string. For example you could pass "255|127|1|2" as your variable string and then use the external script to parse these into their individual number values.

 

Only one %ctRunExternalScript command can exist per line.

 

The External Script

 

The external script must have a function Main which is the scripts entry point.

Function Main must accept a string parameter. eg. Function Main(VariableString)

The script must always return a value even if it is a nul value.

The script may need to parse VariableString to seperate it into individual variables for use within the script.

The script has these Functions and Variables exposed to it.

The script can store values for use later using the functionality exposed by a scripting dictionary.

 

Example Usage:

 

1. In the below example a script is run which deletes all files from the TFTP folder before the running config is copied into it. The external script doesn't require any parameters and returns a nul value, after which the next command, copy running tftp is executed.

 

%ctRunExternalScript("C:\DeleteFiles.txt")

copy running tftp

192.168.1.200

%ctGroupName/%ctDeviceName-Config.txt 

 

2. In the below example a script is run which returns a value of the ports to enable based on the value of the StringVariable sent. The variable is 5 in this case, which could, for example, represent the slot number.

 

Set Port %ctRunExternalScript("C:\PortToEnable.txt","5") enable

 

So after execution of the script, the command which would actually be processed by the Device.CLI.Send commands activity in CatTools may be,

 

Set Port 5/1-12 enable

 

Where the writing in red is the returned value from the function, which is then inserted into the final command used.

 

3. In this example the hostname is changed to a new hostname. (No variables are passed )

 

Conf term

hostname %ctRunExternalScript("C:\hostnames.txt")

wri mem

 

Example External Scripts

 

(see example 2 above)

In the example below the function returns a value based on that of the input string.

 

Function Main(inputString)

Dim SelectionValue

SelectionValue = Val(inputString)

Main = ""

Select Case SelectionValue

Case 1

Main = "1/1-12"

Case 2

Main = "2/1-12"

Case 5

Main = "5/1-12"

End Select

End Function

 

(see example 3 above)

In this example, although the user is not passing an input string, CatTools will pass a default nul string so the 'inputString' variable is still required ??in the function definition.

 

The function itself is referencing cl.DeviceHostnameId which is one of the variables made available to external scripts.

 

Function Main(inputString)

Main=""

If cl.DeviceHostnameId="MyRouter1" Then Main="MyNewRouterName1"

If cl.DeviceHostnameId="MyRouter2" Then Main="MyNewRouterName2"

End Function

Last modified
07:19, 28 Jun 2016

Tags

Classifications

Public