Skip to content

Commit

Permalink
Merge branch 'HHQ-5135' into hqapi-4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
wjs-broadcom committed Aug 9, 2011
2 parents 39b93bf + d8f9c0e commit 231e7e8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions hqapi1-tools/src/main/java/tools/AlertDefinitionCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
import org.hyperic.hq.hqapi1.types.User;
import org.hyperic.hq.hqapi1.types.UserResponse;

import org.hyperic.hq.hqapi1.AgentApi;
import org.hyperic.hq.hqapi1.types.AgentResponse;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -75,6 +78,7 @@ public class AlertDefinitionCommand extends AbstractCommand {

private static String[] COMMANDS = { CMD_LIST, CMD_DELETE, CMD_SYNC, CMD_CREATE };

private static String OPT_AGENTID = "agentId";
private static String OPT_TYPEALERTS = "typeAlerts";
private static String OPT_EXCLUDE_TYPEALERTS = "excludeTypeAlerts";
private static String OPT_EXCLUDE_IDS = "excludeTypeIds";
Expand Down Expand Up @@ -159,6 +163,9 @@ private void list(String[] args) throws Exception {

OptionParser p = getOptionParser();

p.accepts(OPT_AGENTID, "If specified, return alert definitions for resources" +
"serviced by agentId").
withRequiredArg().ofType(Integer.class);
p.accepts(OPT_ID, "If specified, return the alert definition with the given id.").
withRequiredArg().ofType(Integer.class);
p.accepts(OPT_TYPEALERTS, "If specified, only parent resource type " +
Expand Down Expand Up @@ -234,6 +241,29 @@ private void list(String[] args) throws Exception {
checkSuccess(resourceResponse);

alertDefs = definitionApi.getAlertDefinitions(resourceResponse.getResource(), true);
} else if (options.has(OPT_AGENTID)) {
Integer agentId = (Integer)getRequired(options, OPT_AGENTID);

AgentApi agentApi = api.getAgentApi();
AgentResponse agentResponse = agentApi.getAgent(agentId);
checkSuccess(agentResponse);

ResourcesResponse resourcesResponse =
rApi.getResources(agentResponse.getAgent(), false, true);
checkSuccess(resourcesResponse);
// Flatten the list to pass to getAlertDefinitions()
List <Resource> resources = new ArrayList<Resource>();
for (Iterator<Resource> i =
resourcesResponse.getResource().iterator(); i.hasNext(); ) {
Resource r = i.next();
resources.add(r);
for (Iterator<Resource> it =
r.getResource().iterator(); it.hasNext(); ) {
Resource server = it.next();
resources.addAll(server.getResource());
}
}
alertDefs = definitionApi.getAlertDefinitions(resources);
} else if (options.has(OPT_RESOURCE_DESC)) {
String description = (String)getRequired(options, OPT_RESOURCE_DESC);
ResourcesResponse resourcesResponse =
Expand Down

0 comments on commit 231e7e8

Please sign in to comment.