Package org.rhq.core.domain.alert

Examples of org.rhq.core.domain.alert.AlertDefinition


        criteria.addFilterAlertDefinitionIds(alertDefinitionIds);
        return alertManager.findAlertsByCriteria(testData.getSubject(), criteria);
    }

    private int createResourceAlertDefinitionAndGetId(String name) {
        AlertDefinition alertDefinition = new AlertDefinition();
        alertDefinition.setName(name);
        alertDefinition.setPriority(AlertPriority.MEDIUM);
        alertDefinition.setAlertDampening(new AlertDampening(AlertDampening.Category.NONE));
        alertDefinition.setConditionExpression(BooleanExpression.ANY);
        alertDefinition.setRecoveryId(0);
        alertDefinition.setEnabled(true);
        alertDefinition = alertDefinitionManager.createAlertDefinitionInNewTransaction(testData.getSubject(),
            alertDefinition, testData.getResource().getId(), true);
        testData.setAlertDefinitionId(alertDefinition.getId());
        return alertDefinition.getId();
    }
View Full Code Here


        if (results.size() == 0) {
            throw new IllegalArgumentException("Alert with id " + alertId + " was not found");
        }

        Alert av = results.get(0);
        AlertDefinition adv = av.getAlertDefinition();
        request.setAttribute("alert", av);
        request.setAttribute(AttrConstants.ALERT_DEFINITION_ATTR, adv);

        // conditions
        Set<AlertConditionLog> condLogs = av.getConditionLogs();
        Set<AlertCondition> conds = new LinkedHashSet<AlertCondition>(condLogs.size());

        for (AlertConditionLog condLog : condLogs) {
            conds.add(condLog.getCondition());
        }

        List<AlertConditionBean> alertCondBeans = AlertDefUtil.getAlertConditionBeanList(subject, request, conds);

        Iterator<AlertCondition> condsIterator = conds.iterator();
        Iterator<AlertConditionLog> condLogsIterator = condLogs.iterator();

        for (AlertConditionBean alertCondBean : alertCondBeans) {
            AlertCondition cond = condsIterator.next();
            AlertConditionLog condLog = condLogsIterator.next();
            AlertConditionCategory category = cond.getCategory();

            if (category == AlertConditionCategory.CONTROL) {
                alertCondBean.setActualValue(RequestUtils.message(request, "alert.current.list.ControlActualValue"));
            } else if ((category == AlertConditionCategory.THRESHOLD) || (category == AlertConditionCategory.BASELINE)
                || (category == AlertConditionCategory.CHANGE)) {

                // Format threshold and value.
                MeasurementDefinition definition = condLog.getCondition().getMeasurementDefinition();
                String firedValue;

                try {
                    firedValue = MeasurementConverter.format(Double.valueOf(condLog.getValue()), definition.getUnits(),
                        true);
                } catch (Exception e) {
                    // check if this is Calltime data
                    if (definition.getDataType() == DataType.CALLTIME)
                        firedValue = condLog.getValue();
                    else
                        firedValue = "??";
                }

                alertCondBean.setActualValue(firedValue);
            } else if ((category == AlertConditionCategory.RESOURCE_CONFIG)
                || (category == AlertConditionCategory.EVENT)) {
                // TODO: jmarques - add validation to make sure condition is a valid regex Pattern
                alertCondBean.setActualValue(condLog.getValue());
            } else if (category == AlertConditionCategory.TRAIT) {
                alertCondBean.setActualValue(condLog.getValue());
            } else {
                alertCondBean.setActualValue("??");
            }
        }

        request.setAttribute("conditionExpression", adv.getConditionExpression().name());
        request.setAttribute("alertDefConditions", alertCondBeans);

        List<AlertNotificationLog> notificationLogs = av.getAlertNotificationLogs();

        request.setAttribute("aNotifLogs", notificationLogs);

        int recoveryAlertDefId = adv.getRecoveryId();
        if (recoveryAlertDefId != 0) {
            String recoveryAlertName = getRecoveryAlertName(recoveryAlertDefId, subject);
            request.setAttribute("recoveryAlertName", recoveryAlertName);
        }
View Full Code Here

        return null;
    }

    private String getRecoveryAlertName(int alertDefinitionId, Subject user) {
        try {
            AlertDefinition alertDefinition = LookupUtil.getAlertDefinitionManager().getAlertDefinitionById(user,
                alertDefinitionId);
            return alertDefinition.getName();
        } catch (Exception ex) {
            return null;
        }
    }
View Full Code Here

     * alertDef is already in the request attributes. If it is, return it. If not, look for an "ad" parameter and then
     * get the alert definition from the bizapp and return it.
     */
    @Deprecated
    public static AlertDefinition getAlertDefinition(HttpServletRequest request) throws ServletException {
        AlertDefinition alertDefinition = (AlertDefinition) request.getAttribute(Constants.ALERT_DEFINITION_ATTR);

        if (null == alertDefinition) {
            String alertDefinitionParameter = request.getParameter(Constants.ALERT_DEFINITION_PARAM);

            if (null == alertDefinitionParameter) {
                throw new ParameterNotFoundException(Constants.ALERT_DEFINITION_PARAM);
            } else {
                Subject user = RequestUtils.getSubject(request);
                int alertDefinitionId = Integer.parseInt(alertDefinitionParameter);
                alertDefinition = LookupUtil.getAlertDefinitionManager()
                    .getAlertDefinitionById(user, alertDefinitionId);
                request.setAttribute(Constants.ALERT_DEFINITION_ATTR, alertDefinition);
                request.setAttribute("alertNotifCount", alertDefinition.getAlertNotifications().size());

                AlertDefinitionContext context = AlertDefinitionContext.get(alertDefinition);
                if (context == AlertDefinitionContext.Type) {
                    RequestUtils.setResourceType(request, alertDefinition.getResourceType());
                } else if (context == AlertDefinitionContext.Group) {
                    RequestUtils.setResourceGroup(request, alertDefinition.getGroup());
                } else {
                    RequestUtils.setResource(request, alertDefinition.getResource());
                }

                log.trace("adv.id=" + alertDefinitionId);
            }
        }
View Full Code Here

        Subject subject = EnterpriseFacesContextUtility.getSubject();

        if (alert.getRecoveryId() != 0) {
            Integer recoveryAlertId = alert.getRecoveryId();
            AlertDefinitionManagerLocal alertDefinitionManagerLocal = LookupUtil.getAlertDefinitionManager();
            AlertDefinition recoveryAlertDefinition = alertDefinitionManagerLocal.getAlertDefinitionById(subject,
                recoveryAlertId);
            //return recoveryAlertDefinition.getName();
            return "Triggered '<a href=\"/alerts/Config.do?mode=viewRoles&id=" + resourceId + "&ad" + recoveryAlertId
                + "\">" + recoveryAlertDefinition.getName() + "</a>' to be re-enabled";
        }

        if (alert.getWillRecover()) {
            return "This alert caused its alert definition to be disabled";
        }
View Full Code Here

        if (results.size() == 0) {
            request.setAttribute(AttrConstants.TITLE_PARAM2_ATTR, "! Alert not found !");
        } else {
            Alert alert = results.get(0);
            AlertDefinition alertDefinition = alert.getAlertDefinition();

            request.setAttribute(AttrConstants.TITLE_PARAM2_ATTR, alertDefinition.getName());
        }

        return null;
    }
View Full Code Here

            return forward;
        }

        Subject subject = RequestUtils.getSubject(request);

        AlertDefinition alertDef = new AlertDefinition();

        try {
            defForm.exportProperties(alertDef);
            defForm.exportConditionsEnablement(alertDef, request, subject);
        } catch (Exception e) {
            log.debug("alert definition update failed:", e);
            RequestUtils.setError(request, "alert.config.edit.definition.error", e.getMessage(), "global");
            return returnFailure(request, mapping, null);
        }

        int alertDefinitionId;
        try {
            if (context == FormContext.Type) {
                AlertTemplateManagerLocal alertTemplateManager = LookupUtil.getAlertTemplateManager();
                alertDefinitionId = alertTemplateManager.createAlertTemplate(subject, alertDef, defForm.getType());
            } else if (context == FormContext.Resource) {
                AlertDefinitionManagerLocal alertDefinitionManager = LookupUtil.getAlertDefinitionManager();
                AlertDefinition alertDefinition = alertDefinitionManager.createAlertDefinitionInNewTransaction(subject,
                    alertDef, defForm.getId(), true);
                alertDefinitionId = alertDefinition.getId();
            } else if (context == FormContext.Group) {
                GroupAlertDefinitionManagerLocal groupAlertDefinitionManager = LookupUtil
                    .getGroupAlertDefinitionManager();
                alertDefinitionId = groupAlertDefinitionManager.createGroupAlertDefinitions(subject, alertDef,
                    defForm.getGroupId());
View Full Code Here

        } else {
            throw new IllegalArgumentException("Unsupported form context: " + formContext);
        }

        Subject subject = RequestUtils.getSubject(request);
        AlertDefinition alertDefinition = AlertDefUtil.getAlertDefinition(request);
        List<OptionItem> operationNames = AlertDefUtil.getControlActions(subject, id, formContext);

        // drop-downs
        /* replaced by custom alert senders
        operationsForm.setControlActions(operationNames);
View Full Code Here

            log.trace("returning " + forward);
            return forward;
        }

        Subject subject = RequestUtils.getSubject(request);
        AlertDefinition alertDef = AlertDefUtil.getAlertDefinition(request);

        alertDef.setName(defForm.getName());
        alertDef.setDescription(defForm.getDescription());
        alertDef.setPriority(AlertPriority.values()[defForm.getPriority()]);
        alertDef.setEnabled(defForm.isActive());

        try {
            if (context == FormContext.Type) {
                AlertTemplateManagerLocal alertTemplateManager = LookupUtil.getAlertTemplateManager();
                alertTemplateManager.updateAlertTemplate(subject, alertDef, false);
            } else if (context == FormContext.Resource) {
                AlertDefinitionManagerLocal alertDefinitionManager = LookupUtil.getAlertDefinitionManager();
                // this will disallow updates if the alert definition has been deleted
                alertDef.setReadOnly(defForm.isReadOnly());
                alertDefinitionManager.updateAlertDefinition(subject, alertDef.getId(), alertDef, false);
            } else if (context == FormContext.Group) {
                GroupAlertDefinitionManagerLocal groupAlertDefinitionManager = LookupUtil
                    .getGroupAlertDefinitionManager();
                groupAlertDefinitionManager.updateGroupAlertDefinitions(subject, alertDef, false);
            } else {
View Full Code Here

        AlertTemplateManagerLocal alertTemplateManager = LookupUtil.getAlertTemplateManager();
        AlertDefinitionManagerLocal alertDefinitionManager = LookupUtil.getAlertDefinitionManager();
        GroupAlertDefinitionManagerLocal groupAlertDefinitionManager = LookupUtil.getGroupAlertDefinitionManager();

        Subject subject = RequestUtils.getSubject(request);
        AlertDefinition alertDefinition = AlertDefUtil.getAlertDefinition(request);

        OperationDefinition operationDefinition = null;

        if (selectedOperation.equals(EventConstants.CONTROL_ACTION_NONE) == false) {
            Integer operationId = Integer.parseInt(selectedOperation);

            operationDefinition = operationManager.getOperationDefinition(subject, operationId);
        }

        try {
            if (context == FormContext.Type) {
                alertTemplateManager.updateAlertTemplate(subject, alertDefinition, false);
            } else if (context == FormContext.Group) {
                groupAlertDefinitionManager.updateGroupAlertDefinitions(subject, alertDefinition, false);
            } else if (context == FormContext.Resource) {
                alertDefinitionManager.updateAlertDefinition(subject, alertDefinition.getId(), alertDefinition, false);
            } else {
                throw new IllegalArgumentException("Unsupported form context: " + context);
            }
        } catch (AlertDefinitionException iade) {
            log.debug("alert definition update failed:", iade);
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.alert.AlertDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.