Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Attribute VB_Name = "Cisco.Router.general.txt.custom"
- ' ******************************* DO NOT ENTER ANY UNCOMMENTED CODE ABOVE THIS LINE ******************************
- '
- ' ------------------------------------------------- SCRIPT NOTES -------------------------------------------------
- '
- ' CUSTOM ACTIVITY FUNCTIONS:
- ' For each custom activity you wish to add to the device, create a Function as shown below.
- ' You must ensure that the function declaration contains the relevant parameters as defined in the associated
- ' Client custom script file, otherwise an error will occur at runtime.
- '
- ' All code added to this custom file, MUST be added within either a Function or a Sub routine.
- ' DO NOT try to add any other code (Constant or Global variable declarations, etc.) outside of a Function
- ' or Sub routine as this may well cause an error at runtime.
- '
- '
- ' ------------------------------------------------- DEVICE NOTES -------------------------------------------------
- '
- ' CUSTOM SCRIPT: ...[add your device specific information here]
- '
- ' ------------------------------------------------- END OF NOTES -------------------------------------------------
- Function Custom_Activity_Template(sAltCommand)
- ' The Function Custom_Report_Activity() is called by a user defined Custom activity to create (in this example)
- ' a summary version report.
- ' The report is formated as follows:
- ' Group | Device Name | IP Address | SerialNumber | Processor | IOS | Uptime
- '
- ' Calls On: SendCommandSingle
- '
- ' Date Created: [AutoGenDateScriptCreated]
- ' Modifications: (Date - Description of changes)
- ' Declare variables
- Dim iRetVal
- Dim iCount
- Dim iStart
- Dim iLines
- Dim sCmd
- Dim sFindText
- ' Variables to hold report data
- Dim sFieldSerialNumber
- Dim sFieldProcessor
- Dim sFieldIOS
- Dim sFieldUptime
- ' Send message to Infolog
- cl.Log 3, "Running custom activity example in custom device template script"
- ' Initialise activity return value
- Custom_Activity_Template = ""
- ' SEND COMMAND(S) TO DEVICE:
- sCmd = "show version"
- ' Ignore the sAltCommand for this example
- 'If len(sAltCommand) > 0 then
- ' sCmd = sAltCommand
- 'End if
- ' Send the command to the device to get the information we need for the report (stored in cl.RxBuffer). Exit activity if command fails
- If SendCommandSingle(sCmd, 0, 1, 1) = False Then Exit Function
- ' PARSE CAPTURED DATA:
- ' Send message to Infolog that we are analysing the results (i.e. confirms the command was sent successfully)
- cl.Log 4, "Parsing " & SCRIPT_NAME & " version information"
- ' Split the device data stored in the return buffer into separate lines so we can analyse. Exit activity if no lines are found
- iLines = Split(cl.RxBuffer, vbCrLf)
- If UBound(iLines) = -1 Then Exit Function
- ' Below is a few examples of different parsing methods. It is based on a Cisco 2509 device with output:
- '****************** CAPTURE DATA *******************
- '2509# Show Version
- 'Cisco Internetwork Operating System Software
- 'IOS (tm) 2500 Software (C2500-IK8S-L), Version 12.2(5), RELEASE SOFTWARE (fc1)
- 'Copyright (c) 1986-2001 by cisco Systems, Inc.
- 'Compiled Wed 12-Sep-01 10:24 by jbloggs
- 'Image text-base: 0x030670B4, data-base: 0x00001000
- '
- 'ROM: System Bootstrap, Version 11.0(10c)XB1, PLATFORM SPECIFIC RELEASE SOFTWARE (fc1)
- 'BOOTLDR: 3000 Bootstrap Software (IGS-BOOT-R), Version 11.0(10c)XB1, PLATFORM SPECIFIC RELEASE SOFTWARE (fc1)
- '
- '2509 uptime is 5 hours, 37 minutes
- 'System returned to ROM by power-on
- 'System image file is "flash:c2500-ik8s-l.122-5.bin"
- '
- 'cisco 2509 (68030) processor (revision L) with 14336K/2048K bytes of memory.
- 'Processor board ID 03005689, with hardware revision 00000000
- 'Bridging software.
- 'X.25 software, Version 3.0.0.
- '1 Ethernet/IEEE 802.3 interface(s)
- '2 Serial network interface(s)
- '8 terminal Line(S)
- '32K bytes of non-volatile configuration memory.
- '16384K bytes of processor board System flash (Read ONLY)
- '
- 'Configuration register is 0x2102
- '2509#
- '***************** END OF CAPTURE ******************
- ' Set default values in case nothing is found
- sFieldSerialNumber = ""
- sFieldProcessor = ""
- sFieldIOS = ""
- sFieldUptime = ""
- ' Loop through the lines and parse the data.
- For iCount = 0 To UBound(iLines)
- iLines(iCount) = Trim(iLines(iCount))
- ' Get Serial number:
- sFindText = "Processor board ID "
- ' Find line with text "Processor board ID " contained within it
- If cl.TextInText(iLines(iCount), sFindText) > 0 Then
- ' Found a line. Get the text between text we were looking for and the very next comma character ","
- sFieldSerialNumber = cl.TextBetweenText(iLines(iCount), sFindText, ",", True)
- End If
- ' Get Processor:
- sFindText = "processor ("
- ' Find line with text "processor (" contained within it
- If cl.TextInText(iLines(iCount), sFindText) > 0 Then
- ' Use the whole line of data
- sFieldProcessor = iLines(iCount)
- End If
- ' Get IOS version:
- sFindText = "IOS"
- ' Find line with text "IOS" contained within it
- If cl.TextInText(iLines(iCount), sFindText) > 0 Then
- ' With the selected line, get the text between the text "Version" and the very next comma character ","
- sFieldIOS = cl.TextBetweenText(iLines(iCount), "Version", ",", True)
- End If
- ' Get System Uptime:
- sFindText = "uptime is"
- ' Method 1: Find line containing the text "uptime is", and get its start position within the line
- iStart = InStr(iLines(iCount), sFindText)
- If iStart > 0 Then
- ' Get the data from the end of the found text to the end of the data line
- sFieldUptime = Trim(Mid(iLines(iCount), iStart + Len(sFindText)))
- End If
- ' ' Method 2: (using the TextBetweenText with no end value):
- ' If cl.TextInText(iLines(iCount), sFindText) > 0 Then
- ' ' Get the data from the end of the found text to the end of the data line
- ' sFieldUptime = cl.TextBetweenText(iLines(iCount), sFindText, "", True)
- ' End If
- Next
- ' RETURN RESULTS:
- ' Return the results to the Client script for processing
- Custom_Activity_Template = cl.CurDevGroup & vbTab & cl.DeviceName & vbTab & cl.CurDevHostAddress & vbTab _
- & sFieldSerialNumber & vbTab _
- & sFieldProcessor & vbTab _
- & sFieldIOS & vbTab _
- & sFieldUptime & vbCrLf
- End Function
- ' Below is an example of a custom activity called "Custom_Activity_NotSupported" which (theoretically) has been added
- ' to CatTools, but is not yet coded for (or supported) in this device script.
- ' This prevents the CatTools Infolog error:
- '
- ' "Client script error: Type Mismatch: [activity name] on line: [line number]"
- '
- ' from appearing if the device is accidentally associated with the "Custom_Activity_NotSupported" activity
- ' Instead, the following Warning message will appear:
- '
- ' "Device type: [SCRIPT_NAME constant] has not had this functionality added yet. Skipping this device"
- '
- Function Custom_Activity_NotSupported(sAltCommand)
- Call cl.CatToolsNoSupport
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement