Skip to content

Commit

Permalink
[HHQ-3231,HHQ-3786] Allow alert definitions to be listed by platform.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Morgan committed Mar 9, 2010
1 parent c10564f commit b417716
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
@@ -1,6 +1,8 @@

Changes in HQApi 2.4

*) [HHQ-3231,HHQ-3786] Allow alert definitions to be listed by platform.

*) [HHQ-3768] Add --id and --name options to the group list CLI command.

*) [HHQ-3785] Add command lines options to alertdefinition sync command
Expand Down
14 changes: 14 additions & 0 deletions hqu/hqapi1/app/AlertdefinitionController.groovy
Expand Up @@ -215,6 +215,7 @@ public class AlertdefinitionController extends ApiController {
def resourceNameFilter = params.getOne('resourceNameFilter')
def groupName = params.getOne('groupName')
def escalationId = params.getOne('escalationId')?.toInteger()
def resourceId = params.getOne('resourceId')?.toInteger()

def excludeTypeBased = params.getOne('excludeTypeBased')?.toBoolean()
if (excludeTypeBased == null) {
Expand Down Expand Up @@ -253,6 +254,19 @@ public class AlertdefinitionController extends ApiController {
definitions = definitions.findAll { it.parent == null }
}
}
} else if (resourceId != null) {
def resource = getResource(resourceId)
if (!resource) {
failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
"Resource with id = " + resourceId +
" not found")
} else {
// TODO: Add to alert helper
definitions = aMan.findRelatedAlertDefinitions(user, resource)
if (excludeTypeBased) {
definitions = definitions.findAll { it.parent == null }
}
}
} else {
definitions = alertHelper.findDefinitions(AlertSeverity.LOW, null,
excludeTypeBased)
Expand Down
22 changes: 22 additions & 0 deletions src/org/hyperic/hq/hqapi1/AlertDefinitionApi.java
Expand Up @@ -28,6 +28,7 @@
package org.hyperic.hq.hqapi1;

import org.hyperic.hq.hqapi1.types.AlertDefinitionsResponse;
import org.hyperic.hq.hqapi1.types.Resource;
import org.hyperic.hq.hqapi1.types.StatusResponse;
import org.hyperic.hq.hqapi1.types.AlertDefinition;
import org.hyperic.hq.hqapi1.types.AlertDefinitionsRequest;
Expand Down Expand Up @@ -139,6 +140,27 @@ public AlertDefinitionsResponse getAlertDefinitions(AlertDefinition parent)
AlertDefinitionsResponse.class);
}

/**
* Find all {@link org.hyperic.hq.hqapi1.types.AlertDefinition}s on the
* given {@link Resource} including all descendant resources.
*
* @param r The Resource to query for alert definitions
*
* @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(Resource r)
throws IOException {

Map<String,String[]> params = new HashMap<String,String[]>();
params.put("resourceId", new String[] { Integer.toString(r.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
@@ -0,0 +1,29 @@
package org.hyperic.hq.hqapi1.test;

import org.hyperic.hq.hqapi1.AlertDefinitionApi;
import org.hyperic.hq.hqapi1.types.AlertDefinitionsResponse;
import org.hyperic.hq.hqapi1.types.Resource;

public class AlertDefinitionGetByResource_test extends AlertDefinitionTestBase {

public AlertDefinitionGetByResource_test(String name) {
super(name);
}

public void testGetByResource() throws Exception {
AlertDefinitionApi api = getApi().getAlertDefinitionApi();

Resource localPlatform = getLocalPlatformResource(false, false);
AlertDefinitionsResponse response = api.getAlertDefinitions(localPlatform);
hqAssertSuccess(response);
}

public void testGetByInvalidResource() throws Exception {
AlertDefinitionApi api = getApi().getAlertDefinitionApi();

Resource r = new Resource();
r.setId(Integer.MAX_VALUE);
AlertDefinitionsResponse response = api.getAlertDefinitions(r);
hqAssertFailureObjectNotFound(response);
}
}
15 changes: 15 additions & 0 deletions src/org/hyperic/hq/hqapi1/tools/AlertDefinitionCommand.java
Expand Up @@ -32,11 +32,14 @@
import org.hyperic.hq.hqapi1.AlertDefinitionApi;
import org.hyperic.hq.hqapi1.AlertDefinitionBuilder;
import org.hyperic.hq.hqapi1.HQApi;
import org.hyperic.hq.hqapi1.ResourceApi;
import org.hyperic.hq.hqapi1.XmlUtil;
import org.hyperic.hq.hqapi1.EscalationApi;
import org.hyperic.hq.hqapi1.types.AlertAction;
import org.hyperic.hq.hqapi1.types.AlertDefinition;
import org.hyperic.hq.hqapi1.types.AlertDefinitionsResponse;
import org.hyperic.hq.hqapi1.types.Resource;
import org.hyperic.hq.hqapi1.types.ResourceResponse;
import org.hyperic.hq.hqapi1.types.StatusResponse;
import org.hyperic.hq.hqapi1.types.EscalationResponse;
import org.hyperic.hq.hqapi1.types.Escalation;
Expand Down Expand Up @@ -67,6 +70,7 @@ public class AlertDefinitionCommand extends Command {
private static String OPT_COND_COUNT = "conditionCount";
private static String OPT_COND_INCLUDE = "conditionTypeInclude";
private static String OPT_COND_EXCLUDE = "conditionTypeExclude";
private static String OPT_PLATFORM = "platform";

// Command line syncing options
private static String OPT_ASSIGN_ESC = "assignEscalation";
Expand Down Expand Up @@ -111,6 +115,9 @@ private void list(String[] args) throws Exception {
p.accepts(OPT_GROUP, "If specified, only show alert definitions for " +
"resources that belong to the specified group.").
withRequiredArg().ofType(String.class);
p.accepts(OPT_PLATFORM, "Return all alerts on the given platform and " +
"all descendant children").
withRequiredArg().ofType(String.class);
p.accepts(OPT_RESOURCE_NAME, "If specified, only show alert definitions " +
"belonging to a resource with the given " +
"resource name regex.").
Expand Down Expand Up @@ -139,6 +146,7 @@ private void list(String[] args) throws Exception {
HQApi api = getApi(options);
AlertDefinitionApi definitionApi = api.getAlertDefinitionApi();
EscalationApi escalationApi = api.getEscalationApi();
ResourceApi rApi = api.getResourceApi();

AlertDefinitionsResponse alertDefs;

Expand All @@ -149,6 +157,13 @@ private void list(String[] args) throws Exception {
}

alertDefs = definitionApi.getTypeAlertDefinitions(excludeIds);
} else if (options.has(OPT_PLATFORM)) {
String platformName = (String)getRequired(options, OPT_PLATFORM);
ResourceResponse resourceResponse =
rApi.getPlatformResource(platformName, false, false);
checkSuccess(resourceResponse);

alertDefs = definitionApi.getAlertDefinitions(resourceResponse.getResource());
} else {
boolean excludeTypeAlerts = false;
if (options.has(OPT_EXCLUDE_TYPEALERTS)) {
Expand Down
8 changes: 8 additions & 0 deletions xsd/HQApi1.wadl
Expand Up @@ -820,6 +820,14 @@
contained in the specified Group.
</wadl:doc>
</wadl:param>
<wadl:param name="resourceId" style="query" required="false"
type="xs:int">
<wadl:doc>
If specified, only return AlertDefinitions that are
assigned to the specified Resource or any descendent
Resource.
</wadl:doc>
</wadl:param>
<wadl:param name="escalationId" style="query" required="false"
type="xs:int">
<wadl:doc>
Expand Down

0 comments on commit b417716

Please sign in to comment.