Skip to content

Commit

Permalink
[HHQ-3481] Add initial API support to fix alerts with a reason/comment
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen committed Feb 5, 2010
1 parent 3e44bb9 commit 7705da5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
9 changes: 5 additions & 4 deletions hqu/hqapi1/app/AlertController.groovy
Expand Up @@ -303,6 +303,7 @@ public class AlertController extends ApiController {

def fix(params) {
def ids = params.get("id")*.toInteger()
def reason = params.getOne("reason")
def failureXml = null
def alerts = []

Expand All @@ -317,20 +318,20 @@ public class AlertController extends ApiController {
if (!alert) {
failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
"Unable to find alert with id = " + id)
} else if (!canManageAlerts(alert.definition.resource)) {
failureXml = getFailureXML(ErrorCode.PERMISSION_DENIED)
} else {
alertsToFix << alert
}
}

if (!failureXml) {
try {
// TODO: Add to AlertCategory
for (alert in alertsToFix) {
aMan.setAlertFixed(alert)
alert.fix(user, reason)

alerts << getAlertById(alert.id)
}
} catch (PermissionException p) {
failureXml = getFailureXML(ErrorCode.PERMISSION_DENIED)
} catch (Exception e) {
failureXml = getFailureXML(ErrorCode.UNEXPECTED_ERROR,
e.getMessage())
Expand Down
37 changes: 36 additions & 1 deletion src/org/hyperic/hq/hqapi1/AlertApi.java
Expand Up @@ -162,7 +162,24 @@ public AlertsResponse findAlerts(Resource r, long begin, long end,
public AlertResponse fixAlert(Integer alertId)
throws IOException
{
AlertsResponse response = fixAlerts(new Integer[] { alertId });
return fixAlert(alertId, "");
}

/**
* Fix an Alert
*
* @param alertId The id of the Alert to fix.
* @param reason The reason for the fix.
*
* @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS},
* if the Alert was successfully fixed.
*
* @throws IOException If a network error occurs while making the request.
*/
public AlertResponse fixAlert(Integer alertId, String reason)
throws IOException
{
AlertsResponse response = fixAlerts(new Integer[] { alertId }, reason);

AlertResponse res = new AlertResponse();
res.setStatus(response.getStatus());
Expand All @@ -185,6 +202,23 @@ public AlertResponse fixAlert(Integer alertId)
*/
public AlertsResponse fixAlerts(Integer[] alertIds)
throws IOException
{
return fixAlerts(alertIds, "");
}

/**
* Fix multiple Alerts
*
* @param alertIds An array of Alert id's to fix.
* @param reason The reason for the fix.
*
* @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS},
* if the Alert was successfully fixed.
*
* @throws IOException If a network error occurs while making the request.
*/
public AlertsResponse fixAlerts(Integer[] alertIds, String reason)
throws IOException
{
Map<String,String[]> params = new HashMap<String,String[]>();
String[] ids = new String[alertIds.length];
Expand All @@ -193,6 +227,7 @@ public AlertsResponse fixAlerts(Integer[] alertIds)
}

params.put("id", ids);
params.put("reason", new String[] { reason });

return doGet("alert/fix.hqu", params, AlertsResponse.class);
}
Expand Down

0 comments on commit 7705da5

Please sign in to comment.