Advertisement
Guest User

Cisco.Router.general.txt.custom

a guest
Dec 21st, 2011
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 7.53 KB | None | 0 0
  1. Attribute VB_Name = "Cisco.Router.general.txt.custom"
  2. ' ******************************* DO NOT ENTER ANY UNCOMMENTED CODE ABOVE THIS LINE ******************************
  3. '
  4. ' ------------------------------------------------- SCRIPT NOTES -------------------------------------------------
  5. '
  6. ' CUSTOM ACTIVITY FUNCTIONS:
  7. '   For each custom activity you wish to add to the device, create a Function as shown below.
  8. '   You must ensure that the function declaration contains the relevant parameters as defined in the associated
  9. '   Client custom script file, otherwise an error will occur at runtime.
  10. '
  11. '   All code added to this custom file, MUST be added within either a Function or a Sub routine.
  12. '   DO NOT try to add any other code (Constant or Global variable declarations, etc.) outside of a Function
  13. '   or Sub routine as this may well cause an error at runtime.
  14. '
  15. '
  16. ' ------------------------------------------------- DEVICE NOTES -------------------------------------------------
  17. '
  18. ' CUSTOM SCRIPT: ...[add your device specific information here]
  19. '
  20. ' ------------------------------------------------- END OF NOTES -------------------------------------------------
  21.  
  22.  
  23.  
  24. Function Custom_Activity_Template(sAltCommand)
  25. ' The Function Custom_Report_Activity() is called by a user defined Custom activity to create (in this example)
  26. ' a summary version report.
  27. ' The report is formated as follows:
  28. ' Group | Device Name | IP Address | SerialNumber | Processor | IOS | Uptime
  29. '
  30. ' Calls On:         SendCommandSingle
  31. '
  32. ' Date Created:     [AutoGenDateScriptCreated]
  33. ' Modifications:    (Date - Description of changes)
  34.    
  35.  
  36.     ' Declare variables
  37.     Dim iRetVal
  38.     Dim iCount
  39.     Dim iStart
  40.     Dim iLines
  41.     Dim sCmd
  42.     Dim sFindText
  43.    
  44.     ' Variables to hold report data
  45.     Dim sFieldSerialNumber
  46.     Dim sFieldProcessor
  47.     Dim sFieldIOS
  48.     Dim sFieldUptime
  49.  
  50.     ' Send message to Infolog
  51.     cl.Log 3, "Running custom activity example in custom device template script"
  52.  
  53.     ' Initialise activity return value
  54.     Custom_Activity_Template = ""
  55.    
  56.    
  57.     ' SEND COMMAND(S) TO DEVICE:
  58.     sCmd = "show version"
  59.     ' Ignore the sAltCommand for this example
  60.     'If len(sAltCommand) > 0 then
  61.     '   sCmd = sAltCommand
  62.     'End if
  63.    
  64.     ' Send the command to the device to get the information we need for the report (stored in cl.RxBuffer).  Exit activity if command fails
  65.     If SendCommandSingle(sCmd, 0, 1, 1) = False Then Exit Function
  66.    
  67.    
  68.     ' PARSE CAPTURED DATA:
  69.     ' Send message to Infolog that we are analysing the results (i.e. confirms the command was sent successfully)
  70.     cl.Log 4, "Parsing " & SCRIPT_NAME & " version information"
  71.  
  72.     ' Split the device data stored in the return buffer into separate lines so we can analyse.  Exit activity if no lines are found
  73.     iLines = Split(cl.RxBuffer, vbCrLf)
  74.     If UBound(iLines) = -1 Then Exit Function
  75.    
  76.    
  77.     ' Below is a few examples of different parsing methods. It is based on a Cisco 2509 device with output:
  78.    
  79.     '****************** CAPTURE DATA *******************
  80.     '2509# Show Version
  81.     'Cisco Internetwork Operating System Software
  82.     'IOS (tm) 2500 Software (C2500-IK8S-L), Version 12.2(5), RELEASE SOFTWARE (fc1)
  83.     'Copyright (c) 1986-2001 by cisco Systems, Inc.
  84.     'Compiled Wed 12-Sep-01 10:24 by jbloggs
  85.     'Image text-base: 0x030670B4, data-base: 0x00001000
  86.     '
  87.     'ROM: System Bootstrap, Version 11.0(10c)XB1, PLATFORM SPECIFIC RELEASE SOFTWARE (fc1)
  88.     'BOOTLDR: 3000 Bootstrap Software (IGS-BOOT-R), Version 11.0(10c)XB1, PLATFORM SPECIFIC RELEASE SOFTWARE (fc1)
  89.     '
  90.     '2509 uptime is 5 hours, 37 minutes
  91.     'System returned to ROM by power-on
  92.     'System image file is "flash:c2500-ik8s-l.122-5.bin"
  93.     '
  94.     'cisco 2509 (68030) processor (revision L) with 14336K/2048K bytes of memory.
  95.     'Processor board ID 03005689, with hardware revision 00000000
  96.     'Bridging software.
  97.     'X.25 software, Version 3.0.0.
  98.     '1 Ethernet/IEEE 802.3 interface(s)
  99.     '2 Serial network interface(s)
  100.     '8 terminal Line(S)
  101.     '32K bytes of non-volatile configuration memory.
  102.     '16384K bytes of processor board System flash (Read ONLY)
  103.     '
  104.     'Configuration register is 0x2102
  105.     '2509#
  106.     '***************** END OF CAPTURE ******************
  107.    
  108.    
  109.     ' Set default values in case nothing is found
  110.     sFieldSerialNumber = ""
  111.     sFieldProcessor = ""
  112.     sFieldIOS = ""
  113.     sFieldUptime = ""
  114.    
  115.     ' Loop through the lines and parse the data.
  116.     For iCount = 0 To UBound(iLines)
  117.         iLines(iCount) = Trim(iLines(iCount))
  118.        
  119.         ' Get Serial number:
  120.         sFindText = "Processor board ID "
  121.         ' Find line with text "Processor board ID " contained within it
  122.         If cl.TextInText(iLines(iCount), sFindText) > 0 Then
  123.             ' Found a line. Get the text between text we were looking for and the very next comma character ","
  124.             sFieldSerialNumber = cl.TextBetweenText(iLines(iCount), sFindText, ",", True)
  125.         End If
  126.  
  127.         ' Get Processor:
  128.         sFindText = "processor ("
  129.         ' Find line with text "processor (" contained within it
  130.         If cl.TextInText(iLines(iCount), sFindText) > 0 Then
  131.             ' Use the whole line of data
  132.             sFieldProcessor = iLines(iCount)
  133.         End If
  134.        
  135.         ' Get IOS version:
  136.         sFindText = "IOS"
  137.         ' Find line with text "IOS" contained within it
  138.         If cl.TextInText(iLines(iCount), sFindText) > 0 Then
  139.             ' With the selected line, get the text between the text "Version" and the very next comma character ","
  140.             sFieldIOS = cl.TextBetweenText(iLines(iCount), "Version", ",", True)
  141.         End If
  142.                
  143.         ' Get System Uptime:
  144.         sFindText = "uptime is"
  145.         ' Method 1: Find line containing the text "uptime is", and get its start position within the line
  146.         iStart = InStr(iLines(iCount), sFindText)
  147.         If iStart > 0 Then
  148.            ' Get the data from the end of the found text to the end of the data line
  149.            sFieldUptime = Trim(Mid(iLines(iCount), iStart + Len(sFindText)))
  150.         End If
  151.        
  152. '        ' Method 2: (using the TextBetweenText with no end value):
  153. '        If cl.TextInText(iLines(iCount), sFindText) > 0 Then
  154. '            ' Get the data from the end of the found text to the end of the data line
  155. '            sFieldUptime = cl.TextBetweenText(iLines(iCount), sFindText, "", True)
  156. '        End If
  157.  
  158.     Next
  159.    
  160.     ' RETURN RESULTS:
  161.     ' Return the results to the Client script for processing
  162.     Custom_Activity_Template = cl.CurDevGroup & vbTab & cl.DeviceName & vbTab & cl.CurDevHostAddress & vbTab _
  163.             & sFieldSerialNumber & vbTab _
  164.             & sFieldProcessor & vbTab _
  165.             & sFieldIOS & vbTab _
  166.             & sFieldUptime & vbCrLf
  167.            
  168. End Function
  169.  
  170.  
  171.  
  172.  
  173. ' Below is an example of a custom activity called "Custom_Activity_NotSupported" which (theoretically) has been added
  174. ' to CatTools, but is not yet coded for (or supported) in this device script.
  175. ' This prevents the CatTools Infolog error:
  176. '
  177. '       "Client script error: Type Mismatch: [activity name] on line: [line number]"
  178. '
  179. ' from appearing if the device is accidentally associated with the "Custom_Activity_NotSupported" activity
  180. ' Instead, the following Warning message will appear:
  181. '
  182. '       "Device type: [SCRIPT_NAME constant] has not had this functionality added yet.  Skipping this device"
  183. '
  184. Function Custom_Activity_NotSupported(sAltCommand)
  185.     Call cl.CatToolsNoSupport
  186. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement