Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Name: Discover Switchport
- * Table: Global [global]
- * Category: Runbook
- */
- workflow.includeActivityDefinition("Run Powershell");
- var Discover_SwitchportActivityHandler = Class.create();
- Discover_SwitchportActivityHandler.prototype = Object.extendsObject(Run_PowershellActivityHandler, {
- initialize: function() {
- Run_PowershellActivityHandler.prototype.initialize.call(this);
- },
- // Set up this.host and this.cmd
- _getValues: function(probe) {
- this.cmd = "[Diagnostics.EventLog]::WriteEntry(\"ServiceNow\", \"Service Now Runbook: DiscoverSwitchport.bat\");\n " +
- "cmd.exe /c \'\\\\10.6.8.49\\scripts\\Runbook\\RBDiscoverSwitchport.bat\' " +
- this.js(activity.vars.hostip) + " " +
- this.js(activity.vars.hostmac) + ";";
- this.host = "10.211.1.27";
- },
- onProbe_complete: function() {
- activity.state = 'finished';
- var switchport = this._parseSwitchport(document.result.output);
- //this.setActivityOutput(this._getRawOutput());
- var sensorScript = this.getSensorScript();
- if (!sensorScript)
- return;
- workflow.setVariable("output", document.result.output);
- workflow.setVariable("switchport", switchport);
- this._evalScript(sensorScript);
- },
- // Find "Found Port:" and return switchport
- _parseSwitchport: function(output){
- var lines = output.split('\n');
- for (var i = 0; i < lines.length; i++) {
- if (lines[i].match(/Found Port:\s/)) {
- var switchport = lines[i].substr(lines[i].length);
- } else {
- var switchport = "Switchport Not Found";
- }
- }
- return switchport;
- },
- type: 'Discover_SwitchportActivityHandler'
- });
Advertisement
Add Comment
Please, Sign In to add comment