Skip to content

Commit

Permalink
Merge branch 'hqapi-1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Morgan committed Jul 8, 2009
2 parents 32b676a + 4a9738f commit bcae5c6
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/org/hyperic/hq/hqapi1/tools/AlertDefinitionCommand.java
Expand Up @@ -38,10 +38,12 @@
import org.hyperic.hq.hqapi1.types.StatusResponse;
import org.hyperic.hq.hqapi1.types.EscalationResponse;
import org.hyperic.hq.hqapi1.types.Escalation;
import org.hyperic.hq.hqapi1.types.AlertCondition;

import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;

public class AlertDefinitionCommand extends Command {

Expand All @@ -60,6 +62,8 @@ public class AlertDefinitionCommand extends Command {
private static String OPT_ID = "id";
private static String OPT_BATCH_SIZE = "batchSize";
private static String OPT_ESCLATION = "escalation";
private static String OPT_COND_COUNT = "conditionCount";
private static String OPT_COND_TYPE = "conditionType";

private void printUsage() {
System.err.println("One of " + Arrays.toString(COMMANDS) + " required");
Expand Down Expand Up @@ -107,6 +111,14 @@ private void list(String[] args) throws Exception {
p.accepts(OPT_ESCLATION, "If specified, only show alert definitions " +
"that are tied to the named escalation.").
withRequiredArg().ofType(String.class);
p.accepts(OPT_COND_COUNT, "If specified, only show alert definitions " +
"which have the number of conditions " +
"specified")
.withRequiredArg().ofType(Integer.class);
p.accepts(OPT_COND_TYPE, "If specified, only show alert definitions " +
"which have at least one condition of the " +
"given type")
.withRequiredArg().ofType(Integer.class);

OptionSet options = getOptions(p, args);

Expand Down Expand Up @@ -153,6 +165,34 @@ private void list(String[] args) throws Exception {
groupNameFilter);
}

if (options.has(OPT_COND_COUNT)) {
Integer count = (Integer)getRequired(options, OPT_COND_COUNT);
for (Iterator<AlertDefinition> i =
alertDefs.getAlertDefinition().iterator(); i.hasNext(); ) {
AlertDefinition d = i.next();
if (d.getAlertCondition().size() != count) {
i.remove();
}
}
}

if (options.has(OPT_COND_TYPE)) {
Integer type = (Integer)getRequired(options, OPT_COND_TYPE);
for (Iterator<AlertDefinition> i =
alertDefs.getAlertDefinition().iterator(); i.hasNext(); ) {
AlertDefinition d = i.next();
boolean hasType = false;
for (AlertCondition c : d.getAlertCondition()) {
if (c.getType() == type) {
hasType = true;
}
}
if (!hasType) {
i.remove();
}
}
}

checkSuccess(alertDefs);
XmlUtil.serialize(alertDefs, System.out, Boolean.TRUE);
}
Expand Down

0 comments on commit bcae5c6

Please sign in to comment.