sidetrak

WAD - Discover Switchport

May 16th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * Name: Discover Switchport
  3. * Table: Global [global]
  4. * Category: Runbook
  5. */
  6.  
  7. workflow.includeActivityDefinition("Run Powershell");
  8.  
  9. var Discover_SwitchportActivityHandler = Class.create();
  10. Discover_SwitchportActivityHandler.prototype = Object.extendsObject(Run_PowershellActivityHandler, {
  11.  
  12. initialize: function() {
  13. Run_PowershellActivityHandler.prototype.initialize.call(this);
  14. },
  15.  
  16. // Set up this.host and this.cmd
  17. _getValues: function(probe) {
  18. this.cmd = "[Diagnostics.EventLog]::WriteEntry(\"ServiceNow\", \"Service Now Runbook: DiscoverSwitchport.bat\");\n " +
  19. "cmd.exe /c \'\\\\10.6.8.49\\scripts\\Runbook\\RBDiscoverSwitchport.bat\' " +
  20. this.js(activity.vars.hostip) + " " +
  21. this.js(activity.vars.hostmac) + ";";
  22.  
  23. this.host = "10.211.1.27";
  24. },
  25.  
  26. onProbe_complete: function() {
  27. activity.state = 'finished';
  28. var switchport = this._parseSwitchport(document.result.output);
  29.  
  30. //this.setActivityOutput(this._getRawOutput());
  31.  
  32. var sensorScript = this.getSensorScript();
  33. if (!sensorScript)
  34. return;
  35.  
  36. workflow.setVariable("output", document.result.output);
  37. workflow.setVariable("switchport", switchport);
  38.  
  39. this._evalScript(sensorScript);
  40. },
  41.  
  42. // Find "Found Port:" and return switchport
  43. _parseSwitchport: function(output){
  44. var lines = output.split('\n');
  45.  
  46. for (var i = 0; i < lines.length; i++) {
  47. if (lines[i].match(/Found Port:\s/)) {
  48. var switchport = lines[i].substr(lines[i].length);
  49. } else {
  50. var switchport = "Switchport Not Found";
  51. }
  52. }
  53. return switchport;
  54. },
  55.  
  56. type: 'Discover_SwitchportActivityHandler'
  57. });
Advertisement
Add Comment
Please, Sign In to add comment