From 4a9738f9c706c801e92e52d7c3ab293b3e6d45eb Mon Sep 17 00:00:00 2001 From: Ryan Morgan Date: Wed, 8 Jul 2009 12:06:48 -0700 Subject: [PATCH] [HHQ-3230] Add --conditionCount and --conditionType parameters to alertdefinition list CLI command. --- .../hqapi1/tools/AlertDefinitionCommand.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/org/hyperic/hq/hqapi1/tools/AlertDefinitionCommand.java b/src/org/hyperic/hq/hqapi1/tools/AlertDefinitionCommand.java index 2db3d205..d6eaddf2 100644 --- a/src/org/hyperic/hq/hqapi1/tools/AlertDefinitionCommand.java +++ b/src/org/hyperic/hq/hqapi1/tools/AlertDefinitionCommand.java @@ -11,10 +11,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 { @@ -33,6 +35,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"); @@ -80,6 +84,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); @@ -126,6 +138,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 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 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); }