Issue
Service Mapping runs the command correctly, displays the process number in the result, but fails to extract it properly and displays an error message.
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, the following solution uses an external command to override the ProcessOnPort command for Linux:
- Go to System Definition > Tables.
- In the Name field, search for sa_mapping_ext_commands.
- Select the Mapping External Discovery Commands entry.
- Scroll down, and select the Operating System Type.
- On the Reference specification tab, set an additional condition:
- Select OR.
- From the first list, select Element.
- For the operator, select Is.
- From the second list, select os_type.
- Select Update.
- Go to Service Mapping > External discovery commands.
- Select New.
- In the Name field, enter Process on port IPv6 - Linux.
- Next to Operating System Type, select the padlock icon, and then select Linux.
- In the Type field, select PROCESS_ON_PORT.
- In the Order field, enter -1.
- In the Script pane, paste the following script:
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");
}
}
8. In the Order field, enter -1.
9. Select PROCESS_ON_PORT from the Type list.
10. Select Update.