protected static final String PLUGINCONFIG_DETECTION_MECHANISM = "detectionMechanism"; // also used for operation results
protected static final String PLUGINCONFIG_EXECUTABLE = ScriptServerComponent.PLUGINCONFIG_EXECUTABLE;
@Override
public OperationResult invokeOperation(String name, Configuration params) throws Exception {
OperationResult result;
if ("getNetworkConnections".equals(name)) {
Configuration pluginConfiguration = getResourcContext().getPluginConfiguration();
DetectionMechanism mechanism = LsofDiscoveryComponent.getDetectionMechanism(pluginConfiguration);
if (mechanism == DetectionMechanism.EXTERNAL) {
log.info("Getting network connections using the external mechanism");
// compile the regex that will be used to parse the output
String regex = params.getSimpleValue("regex", "");
if (regex.length() == 0) {
throw new Exception("missing regex parameter");
}
Pattern pattern = Pattern.compile(regex);
// first run the executable
OperationResult intermediaryResult = super.invokeOperation(name, params);
Configuration intermediaryConfig = intermediaryResult.getComplexResults();
// now build our results object
result = new OperationResult();
Configuration config = result.getComplexResults();
config.put(new PropertySimple("detectionMechanism", mechanism.toString()));
config.put(intermediaryConfig.getSimple(OPERATION_RESULT_EXITCODE));
if (intermediaryResult.getErrorMessage() != null) {
result.setErrorMessage(intermediaryResult.getErrorMessage());
} else {
String output = intermediaryConfig.getSimpleValue(OPERATION_RESULT_OUTPUT, "");
if (output.length() > 0) {
PropertyList list = new PropertyList("networkConnections");
config.put(list);
String[] lines = output.split("\n");
for (String line : lines) {
Matcher matcher = pattern.matcher(line);
if (matcher.matches()) {
PropertyMap map = new PropertyMap("networkConnection");
list.add(map);
map.put(new PropertySimple("localHost", matcher.group(1)));
map.put(new PropertySimple("localPort", matcher.group(2)));
map.put(new PropertySimple("remoteHost", matcher.group(3)));
map.put(new PropertySimple("remotePort", matcher.group(4)));
}
}
}
}
} else {
log.info("Getting network connections using the internal mechanism");
result = new OperationResult();
Configuration config = result.getComplexResults();
config.put(new PropertySimple("detectionMechanism", mechanism.toString()));
try {
List<NetConnection> conns;