619 views

 

Problem


Service Mapping executes the command correctly and the process number is displayed in the result, but is not extracted properly, and the error message is displayed.

 

Symptoms


The following discovery error is displayed: “Failed to find process on port. Failed to detect listening process. tcp 0 0 ::ffff:ip_address LISTEN process_num/process name”

 

Cause


When running the netstat command on Linux systems, Service Mapping may encounter unexpected information related to IPv6 in the result, which breaks the result parsing and prevents Service Mapping from detecting the process number.

 

Resolution


A code fix for Geneva P4 and higher addresses the issue.

For earlier Geneva releases, we recommend the following solution, which uses an external command to override the ProcessOnPort command for Linux:

  1. Navigate to System Definition > Tables.
  2. Search for sa_mapping_ext_commands in the name field.
  3. Click on the Mapping External Discovery Commands entry.
  4. Scroll down, and click on the Operating System Type.
  5. On the Reference specification tab, set an additional condition:
    1. Click OR.
    2. Select Element from the first list.
    3. Select Is for the operator.
    4. Select os_type from the second list.
  6. Click Update.Dictionary Entry page
  7. Navigate to Service Mapping > External discovery commands.
  8. Click New.
  9. Enter Process on port IPv6 - Linux in the Name field.
  10. Click the padlock icon next to Operating System Type and select Linux.
  11. In the Type field, select PROCESS_ON_PORT.
  12. In the order field, enter -1.
  13. Paste the following script in the Script pane:
var logger = Packages.com.snc.sw.log.DiscoLog.getLogger("LinuxProcessOnPortCommand");
logger.debugex("In external command process on port Linux");
var portCommand = new Packages.com.snc.sw.commands.ProcessOnPortCommand();
var input_port = new JSON().decode(input);
var portInt = +input_port['localPort'];
var portCommandArguments = new Packages.com.snc.sw.commands.arguments.PortCommandArguments(ctx, portInt);
var filter = portCommandArguments.getFilter();
var portCommandArguments2 = new Packages.com.snc.sw.commands.arguments.PortCommandArguments(ctx, portInt, input_port['localAddress'], filter);
var openPortsCommand = new Packages.com.snc.sw.commands.OpenPortsSshCommandLinux();
var openPorts = openPortsCommand.execute(portCommandArguments2);
if (openPorts.size() > 0) {
var proc = portCommand.execute(portCommandArguments2);
if (proc != null) {
var output = {};
output['pid'] = proc.pid;
output['commandLine'] = proc.commandLine;
output['executable'] = proc.executable;
output['executablePath'] = proc.executablePath;
output['parentProcessId'] = proc.parentProcessId;
output['userName'] = proc.userName;
output['currentDir'] = proc.currentDir;
output['workingDir'] = proc.workingDir;
if (proc.environmentVariables != null) {
var env = {};
for (var key in proc.environmentVariables.keySet()) {
var envVar = {};
envVar['name'] = key;
envVar['value'] = proc.environmentVariables[key];
env[key] = envVar;
}
output['environmentVariables'] = env;
}
output = new JSON().encodeObject(output);
logger.debugex("In external command process on port Linux - DONE");
} else {
// proc is null. try with similar ipv6 address
//Packages.com.glide.util.Log.debug('try to find listening port on ipv6 address');
var ipv6 = "::ffff:" + input_port['localAddress'];
var portCommandArguments3 = new Packages.com.snc.sw.commands.arguments.PortCommandArguments(ctx, portInt, ipv6, filter);
proc = portCommand.execute(portCommandArguments3);
if (proc != null) {
var output = {};
output['pid'] = proc.pid;
output['commandLine'] = proc.commandLine;
output['executable'] = proc.executable;
output['executablePath'] = proc.executablePath;
output['parentProcessId'] = proc.parentProcessId;
output['userName'] = proc.userName;
output['currentDir'] = proc.currentDir;
output['workingDir'] = proc.workingDir;
if (proc.environmentVariables != null) {
var env = {};
for (var key in proc.environmentVariables.keySet()) {
var envVar = {};
envVar['name'] = key;
envVar['value'] = proc.environmentVariables[key];
env[key] = envVar;
}
output['environmentVariables'] = env;
}
output = new JSON().encodeObject(output);
}
logger.debugex("In external command process on port Linux - DONE");
}
}
 

14. Enter -1 in the Order field.

15. Select PROCESS_ON_PORT from the Type list.

16. Click Update.

 

 

 

Article Information

Last Updated:2016-01-30 22:32:42
Published:2016-01-21