public String getDetailedHelp() {
return MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_DETAILED_HELP);
}
private void processCommand(AgentMain agent, String[] args, PrintWriter out) {
AgentConfiguration agentConfig = agent.getConfiguration();
String pcName = agentConfig.getAgentName();
String pluginName = null;
String resourceTypeName = null;
Integer resourceId = null;
boolean verbose = false;
boolean full = false;
String sopts = "-p:i:r:fvb:";
LongOpt[] lopts = { new LongOpt("plugin", LongOpt.REQUIRED_ARGUMENT, null, 'p'), //
new LongOpt("resourceId", LongOpt.REQUIRED_ARGUMENT, null, 'i'), //
new LongOpt("resourceType", LongOpt.REQUIRED_ARGUMENT, null, 'r'), //
new LongOpt("full", LongOpt.NO_ARGUMENT, null, 'f'), //
new LongOpt("verbose", LongOpt.NO_ARGUMENT, null, 'v'), //
new LongOpt("blacklist", LongOpt.REQUIRED_ARGUMENT, null, 'b') };
Getopt getopt = new Getopt("discovery", args, sopts, lopts);
int code;
while ((code = getopt.getopt()) != -1) {
switch (code) {
case ':':
case '?':
case 1: {
out.println(MSG.getMsg(AgentI18NResourceKeys.HELP_SYNTAX_LABEL, getSyntax()));
return;
}
case 'p': {
pluginName = getopt.getOptarg();
break;
}
case 'i': {
resourceId = Integer.valueOf(getopt.getOptarg());
break;
}
case 'r': {
resourceTypeName = getopt.getOptarg();
break;
}
case 'f': {
full = true;
break;
}
case 'b': {
String opt = getopt.getOptarg();
InventoryManager inventoryManager = PluginContainer.getInstance().getInventoryManager();
DiscoveryComponentProxyFactory factory = inventoryManager.getDiscoveryComponentProxyFactory();
if (opt.equalsIgnoreCase("list")) {
HashSet<ResourceType> blacklist = factory.getResourceTypeBlacklist();
out.println(MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_BLACKLIST_LIST, blacklist));
} else if (opt.equalsIgnoreCase("clear")) {
factory.clearResourceTypeBlacklist();
out.println(MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_BLACKLIST_CLEAR));
} else {
out.println(MSG.getMsg(AgentI18NResourceKeys.HELP_SYNTAX_LABEL, getSyntax()));
}
return;
}
case 'v': {
verbose = true;
break;
}
}
}
if ((getopt.getOptind() + 1) < args.length) {
out.println(MSG.getMsg(AgentI18NResourceKeys.HELP_SYNTAX_LABEL, getSyntax()));
return;
}
if (full) {
// do a full discovery - we ignore the -p and -r and -i options and do everything
if (!agent.getClientCommandSender().isSending()) {
out.println(MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_AGENT_NOT_CONNECTED_TO_SERVER));
}
InventoryManager inventoryManager = PluginContainer.getInstance().getInventoryManager();
if (inventoryManager.isDiscoveryScanInProgress()) {
out.println(MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_SCAN_ALREADY_IN_PROGRESS));
return;
}
HashSet<ResourceType> blacklist = inventoryManager.getDiscoveryComponentProxyFactory()
.getResourceTypeBlacklist();
if (!blacklist.isEmpty()) {
out.println(MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_BLACKLISTED_TYPES, blacklist));
}
long start = System.currentTimeMillis();
InventoryReport scan1 = inventoryManager.executeServerScanImmediately();
InventoryReport scan2 = inventoryManager.executeServiceScanImmediately();
out.println(MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_FULL_RUN, (System.currentTimeMillis() - start)));
printInventoryReport(scan1, out, verbose);
printInventoryReport(scan2, out, verbose);
} else {
try {
if (resourceId == null) {
discovery(pcName, out, pluginName, resourceTypeName, verbose);
} else {
// specifying a resource ID implies we must ignore -r and -p (since type/plugin is determined by the resource)
InventoryManager im = PluginContainer.getInstance().getInventoryManager();
ResourceContainer resourceContainer = im.getResourceContainer(resourceId);
if (resourceContainer != null) {
Resource resource = resourceContainer.getResource();
PluginContainerConfiguration pcc = agentConfig.getPluginContainerConfiguration();
RuntimeDiscoveryExecutor scanner = new RuntimeDiscoveryExecutor(im, pcc, resource);
InventoryReport report = scanner.call();
out.println(MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_RESOURCE_SERVICES, resource.getName()));
printInventoryReport(report, out, verbose);
} else {