Advertisement
Guest User

client custom

a guest
Dec 20th, 2011
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Attribute VB_Name = "Act_Custom_Template"
  3. ' ------------------------------------------------- SCRIPT NOTES -------------------------------------------------
  4. '
  5. ' OVERVIEW:
  6. '   Client scripts are run by the CatTools Client program (CatTools_Client.exe).
  7. '   A client script is called by an activity's main script.
  8. '   Client scripts contain a number of common function calls to the device scripts, i.e. the scripts that send
  9. '   device specific commands in order to get the device to log in, issue the commands required to perform the
  10. '   activity, then log out of the device again.
  11. '
  12. ' FUNCTIONS:
  13. '   There is only one function within a ClientScript file, which is Function Client().
  14. '   The Client() function contains all of the necessary program code to call the common device functions and save
  15. '   the activity results to a file for the main activity script to process.
  16. '
  17. '   Below is an example of the device script functions calls required for an activity that needs to login to a
  18. '   device, then enter the Enable mode in order to run a command:
  19. '
  20. '       Login
  21. '       SendPostLoginCommands
  22. '       EnterEnableMode
  23. '       SendPostEnterEnableModeCommands
  24. '       SendSessionTerminationCommands
  25.  
  26. '       * Note: The call to the device script function ExitEnableMode which sends the command to exit enable mode
  27. '       on the device is not required within the Client script as it is called within SendSessionTerminationCommands
  28. '       function within the device script file.
  29. '
  30. '   There are also a number of calls to the internal CatTools Client functions which are prefixed with "cl."
  31. '   A full list of cl. functions exposed to the custom client activity template, including a brief description and
  32. '   example how to use them, can be found within the 'Activities' chapter of our on-line help file at
  33. '   http://www.kiwisyslog.com/help/cattools/index.html
  34. '
  35. ' ACTIVITY OPTIONS:
  36. '   List each of the activity options you have defined in the .INI file for this custom activity within the
  37. '   --- ACTIVITY NOTES --- section below.
  38. '   NOTE: For ease of reference, it is recommended you list ALL the activity options (and in numerical order) whether
  39. '   they apply to the activity client script or activity main script; however if the option is specific to the main
  40. '   script (i.e. additional parsing, sorting or filtering of the combined results from the clients), then it isn't
  41. '   necessary to describe its function within this client script.
  42. '   Simply add the text (see MAIN script) and add the description to the activity main script file.
  43. '
  44. '
  45. ' TASKS POST INITIAL CLIENT SCRIPT SETUP:
  46. '
  47. '   Main script.
  48. '   If you haven't already created one, a main script file will also need to be created for your new custom
  49. '   activity/report script.
  50. '   A main script template file "Main.Custom.Activity.Template.txt" has been created for you and can be found in the
  51. '   \Templates folder within the main CatTools root directory.
  52. '
  53. '   Device scripts.
  54. '   For each of the device types (custom or predefined) that you want your custom activity to run for, you will need
  55. '   to create a new custom function within each of the device scripts (.txt files).
  56. '   Ensure you define your new function using the Custom_ prefix.   (i.e.  "Function Custom_    " ), to avoid the
  57. '   possibility of conflict with one of the CatTools predefined activities.
  58. '   For custom device types, you simply need to modify your custom device script file with your new activity function.
  59. '   If you are adding a custom activity function to one of the CatTools predefined device types, you will need to
  60. '   create a new file for your custom activity code, which will then be appended to the CatTools encrypted script code
  61. '   at run-time. The file must be given the same name as the CatTools device file, but with the addition of a '.custom'
  62. '   suffix.
  63. '   For example:
  64. '       If you are adding a custom activity to the Cisco.Switch.IOS device type (script file Cisco.Switch.IOS.txt),
  65. '   then you need to create a new file called Cisco.Switch.IOS.txt.custom in the \Scripts folder within the root
  66. '   CatTools directory.
  67. '   An example file for the Custom Device (Custom.Device.Template.txt.custom) can be found in the \Templates folder
  68. '   within the main CatTools root directory.
  69. '
  70. '   If you associate a device with your custom activity (within the activity setup screen - Devices tab)
  71. '   and that device does not have the corresponding activity function within the custom device script
  72. '   (or .custom extension file for a predefined device), then you will receive the run-time error:
  73. '
  74. '        "Client script error: Type Mismatch: [activity name] on line: [line number]"
  75. '
  76. '   If you don't want this error to appear, then create the custom activity function within the device script
  77. '   and simply add the following line within the function:
  78. '
  79. '        cl.CatToolsNoSupport
  80. '
  81. '   This will then display the following Warning message in the Info Log rather than an error:
  82. '
  83. '        "Device type: ___ has not had this functionality added yet.  Skipping this device"
  84. '
  85. ' ------------------------------------------------ ACTIVITY NOTES ------------------------------------------------
  86. '   ACTIVITY OPTIONS: (see above)
  87. '   1 = Use Alternate command : (checkbox + string) : Overrides the default device script command.
  88. '   2 = ... (add as required for your activity)
  89. '
  90. '   Add any other activity specific information here...
  91. '
  92. ' ------------------------------------------------- END OF NOTES -------------------------------------------------
  93.  
  94. Function Client()
  95.    
  96.     ' Set function return value to tell the CatTools_Client that the script completed normally
  97.    Client = "OK"
  98.    
  99.     ' Declare variables
  100.    Dim sAltCommand
  101.     Dim sResults
  102.     Dim bResults    
  103.    
  104.     ' Check whether an alternate command has been specified.
  105.    ' This command will then be passed to the device scripts as an overriding command to any default commands
  106.    ' that may have been specified in the device script
  107.    If cl.DBCheckScheduleOption(cl.ScheduleNumber, 1) = 1 Then
  108.        sAltCommand = cl.DBScheduleGetField(cl.ScheduleNumber, "OptionsString1")
  109.     Else
  110.        sAltCommand = ""
  111.     End If
  112.    
  113.     ' Test current connection status
  114.    If StrComp(cl.TelnetConnectionStatus, "OK", vbTextCompare) <> 0 Then Exit Function
  115.    
  116.     ' If CatTools receives a request to 'STOP' activity immediately, then exit the function
  117.    If cl.QuitNow = 1 Then Exit Function
  118.    
  119.    
  120.     ' Call the device script function Login
  121.    If login = False Then
  122.         ' Exit the activity if the login fails
  123.        Exit Function
  124.     Else ' Login OK, so call device script function SendPostLoginCommands
  125.        'Note: this is just a call to the function. If it fails, the activity will continue on regardless
  126.        Call SendPostLoginCommands
  127.     End If
  128.     ' Check again whether an immediate STOP activity has been requested.
  129.    If cl.QuitNow = 1 Then Exit Function
  130.    
  131.    
  132.     ' Call device script function to EnterEnableMode. If successful, then call device script function
  133.    ' SendPostEnterEnableModeCommands. If EnterEnableMode failed, then continue with activity anyway without
  134.    ' calling SendPostEnterEnableModeCommands
  135.    If EnterEnableMode Then
  136.         ' Call device script function SendPostEnterEnableModeCommands
  137.        Call SendPostEnterEnableModeCommands
  138.     End If
  139.     ' Check for STOP request
  140.    If cl.QuitNow = 1 Then Exit Function
  141.    
  142.    
  143.     ' Do the activity.
  144.    ' Call the custom activity function 'Custom_Activity_Template' in the device script file and store any
  145.    ' results in the sResults variable
  146.    
  147.     cl.Log 3, "Test"
  148.     '
  149.    
  150.     Activity_UpdatePassword
  151.     sResults = Custom_Activity_Template(sAltCommand)
  152.     'If EnterConfigMode = False Then
  153.     '   Exit Function
  154.     'Else setInterface
  155.    
  156.    
  157.     'End If
  158.     'If cl.QuitNow = 1 Then Exit Function
  159.    
  160.     'cl.Log 3, "Test2"
  161.    
  162.     ' Save the results to a temporary file within the \ClientTemp folder
  163.    Call cl.SaveResults(sResults, 0)
  164.    
  165.     ' Check for STOP request
  166.    If cl.QuitNow = 1 Then Exit Function
  167.    
  168.    
  169.     ' Call device script function SendSessionTerminationCommands to exit or logout the session on the device
  170.    Call SendSessionTerminationCommands
  171.    
  172.    
  173.     ' Disconnect from client
  174.    cl.DisconnectHost
  175.  
  176. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement