Skip to content

Commit

Permalink
[HHQ-3230] Add --conditionTypeExclude to allow definitions to be excl…
Browse files Browse the repository at this point in the history
…uded based on conditions. As part of this change --conditionType has been renamed to --conditionTypeInclude
  • Loading branch information
Ryan Morgan committed Jul 14, 2009
1 parent e6c3ab2 commit bfb0991
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/org/hyperic/hq/hqapi1/tools/AlertDefinitionCommand.java
Expand Up @@ -36,7 +36,8 @@ public class AlertDefinitionCommand extends Command {
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 static String OPT_COND_INCLUDE = "conditionTypeInclude";
private static String OPT_COND_EXCLUDE = "conditionTypeExclude";

private void printUsage() {
System.err.println("One of " + Arrays.toString(COMMANDS) + " required");
Expand Down Expand Up @@ -88,9 +89,13 @@ private void list(String[] args) throws Exception {
"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")
p.accepts(OPT_COND_INCLUDE, "If specified, only show alert definitions " +
"which have at least one condition of the " +
"given type")
.withRequiredArg().ofType(Integer.class);
p.accepts(OPT_COND_EXCLUDE, "If specified, exclude 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 @@ -149,8 +154,8 @@ private void list(String[] args) throws Exception {
}
}

if (options.has(OPT_COND_TYPE)) {
Integer type = (Integer)getRequired(options, OPT_COND_TYPE);
if (options.has(OPT_COND_INCLUDE)) {
Integer type = (Integer)getRequired(options, OPT_COND_INCLUDE);
for (Iterator<AlertDefinition> i =
alertDefs.getAlertDefinition().iterator(); i.hasNext(); ) {
AlertDefinition d = i.next();
Expand All @@ -166,6 +171,20 @@ private void list(String[] args) throws Exception {
}
}

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

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

0 comments on commit bfb0991

Please sign in to comment.