Skip to content

Commit

Permalink
Merge getAlertDefinition APIs. Previously, fetching alerts by escalat…
Browse files Browse the repository at this point in the history
…ion would ignore other search parameters. [HHQ-3223]
  • Loading branch information
Ryan Morgan committed Jul 1, 2009
1 parent 5900bb4 commit 774e30f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
3 changes: 3 additions & 0 deletions hqu/hqapi1/app/AlertdefinitionController.groovy
Expand Up @@ -199,6 +199,9 @@ public class AlertdefinitionController extends ApiController {
} else {
// TODO: Add to alert helper
definitions = aMan.getUsing(escalation)
if (excludeTypeBased) {
definitions = definitions.findAll { it.parent == null }
}
}
} else {
definitions = alertHelper.findDefinitions(AlertSeverity.LOW, null,
Expand Down
30 changes: 7 additions & 23 deletions src/org/hyperic/hq/hqapi1/AlertDefinitionApi.java
Expand Up @@ -32,6 +32,7 @@ public class AlertDefinitionApi extends BaseApi {
*
* @param excludeTypeBased Flag to control whether instances of type based
* alerts will be included.
* @param escalation The {@link Escalation} to filter by
* @param alertNameFilter Filter returned definitions by definition name
* using the given regular expression. A value of null will result in no
* filtering being performed.
Expand All @@ -47,6 +48,7 @@ public class AlertDefinitionApi extends BaseApi {
* @throws java.io.IOException If a network error occurs while making the request.
*/
public AlertDefinitionsResponse getAlertDefinitions(boolean excludeTypeBased,
Escalation escalation,
String alertNameFilter,
String resourceNameFilter,
String groupName)
Expand All @@ -63,6 +65,9 @@ public AlertDefinitionsResponse getAlertDefinitions(boolean excludeTypeBased,
if (groupName != null) {
params.put("groupName", new String[] { groupName });
}
if (escalation != null) {
params.put("escalationId", new String[] { Integer.toString(escalation.getId())});
}

return doGet("alertdefinition/listDefinitions.hqu", params,
AlertDefinitionsResponse.class);
Expand All @@ -82,7 +87,7 @@ public AlertDefinitionsResponse getAlertDefinitions(boolean excludeTypeBased,
public AlertDefinitionsResponse getAlertDefinitions(boolean excludeTypeBased)
throws IOException
{
return getAlertDefinitions(excludeTypeBased, null, null, null);
return getAlertDefinitions(excludeTypeBased, null, null, null, null);
}

/**
Expand All @@ -99,35 +104,14 @@ public AlertDefinitionsResponse getAlertDefinitions(boolean excludeTypeBased)
public AlertDefinitionsResponse getAlertDefinitions(AlertDefinition parent)
throws IOException {

// TODO: This should allow for filtering
Map<String,String[]> params = new HashMap<String,String[]>();
params.put("parentId", new String[] { Integer.toString(parent.getId()) });

return doGet("alertdefinition/listDefinitions.hqu", params,
AlertDefinitionsResponse.class);
}


/**
* Find all {@link org.hyperic.hq.hqapi1.types.AlertDefinition}s that use
* the given escalation.
*
* @param e The {@link Escalation} to filter by
*
* @return On {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS},
* a list of AlertDefinitions are returned.
*
* @throws java.io.IOException If a network error occurs while making the request.
*/
public AlertDefinitionsResponse getAlertDefinitions(Escalation e)
throws IOException {

Map<String,String[]> params = new HashMap<String,String[]>();
params.put("escalationId", new String[] { Integer.toString(e.getId()) });

return doGet("alertdefinition/listDefinitions.hqu", params,
AlertDefinitionsResponse.class);
}

/**
* Find all type based {@link org.hyperic.hq.hqapi1.types.AlertDefinition}s in the system.
*
Expand Down
15 changes: 10 additions & 5 deletions src/org/hyperic/hq/hqapi1/tools/AlertDefinitionCommand.java
Expand Up @@ -10,6 +10,7 @@
import org.hyperic.hq.hqapi1.types.AlertDefinitionsResponse;
import org.hyperic.hq.hqapi1.types.StatusResponse;
import org.hyperic.hq.hqapi1.types.EscalationResponse;
import org.hyperic.hq.hqapi1.types.Escalation;

import java.io.InputStream;
import java.util.Arrays;
Expand Down Expand Up @@ -95,11 +96,6 @@ private void list(String[] args) throws Exception {
}

alertDefs = definitionApi.getTypeAlertDefinitions(excludeIds);
} else if (options.has(OPT_ESCLATION)) {
EscalationResponse escalationResponse = escalationApi.
getEscalation((String)getRequired(options, OPT_ESCLATION));
checkSuccess(escalationResponse);
alertDefs = definitionApi.getAlertDefinitions(escalationResponse.getEscalation());
} else {
boolean excludeTypeAlerts = false;
if (options.has(OPT_EXCLUDE_TYPEALERTS)) {
Expand All @@ -114,8 +110,17 @@ private void list(String[] args) throws Exception {
String alertNameFilter = (String)options.valueOf(OPT_ALERT_NAME);
String resourceNameFilter = (String)options.valueOf(OPT_RESOURCE_NAME);
String groupNameFilter = (String)options.valueOf(OPT_GROUP);
Escalation escalation = null;

if (options.has(OPT_ESCLATION)) {
EscalationResponse escalationResponse = escalationApi.
getEscalation((String)getRequired(options, OPT_ESCLATION));
checkSuccess(escalationResponse);
escalation = escalationResponse.getEscalation();
}

alertDefs = definitionApi.getAlertDefinitions(excludeTypeAlerts,
escalation,
alertNameFilter,
resourceNameFilter,
groupNameFilter);
Expand Down

0 comments on commit 774e30f

Please sign in to comment.