From: <rm...@hy...> - 2009-06-15 21:43:57
|
Author: rmorgan Date: 2009-06-15 14:43:52 -0700 (Mon, 15 Jun 2009) New Revision: 590 URL: http://svn.hyperic.org/?view=rev&root=HQApi&revision=590 Modified: dist/HQAPI_2_0/app/AlertdefinitionController.groovy dist/HQAPI_2_0/app/ApiController.groovy dist/HQAPI_2_0/app/GroupController.groovy dist/HQAPI_2_0/lib/hqapi1-2.0.jar dist/HQAPI_2_0/public/hqapi1-2.0.tar.gz Log: 2.0 binaries from git rev 3175b4a79229cd48e60ac56c946fb54e843bcaad Modified: dist/HQAPI_2_0/app/AlertdefinitionController.groovy =================================================================== --- dist/HQAPI_2_0/app/AlertdefinitionController.groovy 2009-05-27 22:47:09 UTC (rev 589) +++ dist/HQAPI_2_0/app/AlertdefinitionController.groovy 2009-06-15 21:43:52 UTC (rev 590) @@ -164,6 +164,10 @@ def listDefinitions(params) { + def alertNameFilter = params.getOne('alertNameFilter') + def resourceNameFilter = params.getOne('resourceNameFilter') + def groupName = params.getOne('groupName') + def excludeTypeBased = params.getOne('excludeTypeBased')?.toBoolean() if (excludeTypeBased == null) { excludeTypeBased = false; @@ -192,7 +196,30 @@ definitions = alertHelper.findDefinitions(AlertSeverity.LOW, null, excludeTypeBased) } - + + // Filter + try { + if (alertNameFilter) { + definitions = definitions.findAll { it.name ==~ alertNameFilter } + } + if (resourceNameFilter) { + definitions = definitions.findAll { it.resource.name ==~ resourceNameFilter } + } + } catch (java.util.regex.PatternSyntaxException e) { + failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS, + "Invalid syntax: " + e.getMessage()) + } + if (groupName) { + def group = getGroup(null, groupName) + if (!group) { + failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND, + "Unable to find group with name " + groupName) + } else { + def resources = group.resources + definitions = definitions.findAll { resources.contains(it.resource) } + } + } + renderXml() { out << AlertDefinitionsResponse() { if (failureXml) { @@ -456,6 +483,8 @@ templs = resource.metrics } + def isRecovery = false + for (xmlCond in xmlDef['AlertCondition']) { AlertConditionValue acv = new AlertConditionValue() def acError @@ -588,6 +617,8 @@ break } + isRecovery = true + // If a resource alert, look up alert by name if (resource) { log.debug("Looking up alerts for resource=" + resource.id) @@ -701,7 +732,13 @@ // Deal with Escalations if (escalation) { - pojo.setEscalation(user, escalation) + // TODO: Backend should handle escalations on recovery alerts + if (isRecovery) { + log.warn("Skipping escalation for definition '" + pojo.name + + "'. Escalations not allowed for recovery alerts.") + } else { + pojo.setEscalation(user, escalation) + } } else { pojo.unsetEscalation(user) } Modified: dist/HQAPI_2_0/app/ApiController.groovy =================================================================== --- dist/HQAPI_2_0/app/ApiController.groovy 2009-05-27 22:47:09 UTC (rev 589) +++ dist/HQAPI_2_0/app/ApiController.groovy 2009-06-15 21:43:52 UTC (rev 590) @@ -105,6 +105,21 @@ } } + /** + * Get a group by id or name + * + * @return The group with the given id or name. If the passed in id is null, + * then the group with the given name is returned. If no group could be found + * for either the id or name, null is returned. + */ + protected getGroup(Integer id, String name) { + if (id != null) { + return resourceHelper.findGroup(id) + } else { + return resourceHelper.findGroupByName(name) + } + } + def dispatchRequest() { long start = System.currentTimeMillis() Modified: dist/HQAPI_2_0/app/GroupController.groovy =================================================================== --- dist/HQAPI_2_0/app/GroupController.groovy 2009-05-27 22:47:09 UTC (rev 589) +++ dist/HQAPI_2_0/app/GroupController.groovy 2009-06-15 21:43:52 UTC (rev 590) @@ -25,14 +25,6 @@ } } - private getGroup(Integer id, String name) { - if (id != null) { - return resourceHelper.findGroup(id) - } else { - return resourceHelper.findGroupByName(name) - } - } - def get(params) { def id = params.getOne('id')?.toInteger() def name = params.getOne('name') Modified: dist/HQAPI_2_0/lib/hqapi1-2.0.jar =================================================================== (Binary files differ) Modified: dist/HQAPI_2_0/public/hqapi1-2.0.tar.gz =================================================================== (Binary files differ) |