Package org.rhq.core.domain.alert

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


    @Test(enabled = ENABLED)
    public void testBZ830463_updateDef() throws Exception {
        // create our resource with alert definition
        MeasurementDefinition metricDef = createResourceWithMetricSchedule();
        AlertDefinition alertDef = createAlertDefinitionWithOneInsideRangeCondition(metricDef, resource.getId());

        assert alertDef.getConditions().size() == 1 : "1 alertDef condition should exist";
        AlertCondition condition = alertDef.getConditions().iterator().next();
        int conditionId = condition.getId();

        // re-load the resource so we get the measurement schedule
        Resource resourceWithSchedules = loadResourceWithSchedules(resource.getId());
        MeasurementSchedule schedule = resourceWithSchedules.getSchedules().iterator().next();

        // simulate a measurement report coming from the agent - one values that fits in our range, so 1 alert is fired
        MeasurementScheduleRequest request = new MeasurementScheduleRequest(schedule);
        MeasurementReport report = new MeasurementReport();
        report.addData(new MeasurementDataNumeric(getTimestamp(15), request, 50.0)); // 50 < 60 AND 50 > 40
        MeasurementDataManagerLocal dataManager = LookupUtil.getMeasurementDataManager();
        dataManager.mergeMeasurementReport(report);

        // wait for our JMS messages to process and see if we get any alerts
        Thread.sleep(5000);

        // make sure one alert was triggered
        List<Alert> alerts = getAlerts(resourceWithSchedules.getId());
        assert alerts.size() == 1 : "1 alert should have fired: " + alerts;
        Alert alert = alerts.get(0);

        assert alert.getConditionLogs().size() == 1 : "1 condition log should exist";
        AlertConditionLog conditionLog = alert.getConditionLogs().iterator().next();
        Assert.assertEquals(conditionLog.getCondition().getId(), conditionId,
            "original condition should have been associated with the alert");

        // update a non-condition aspect of the def and then update the def
        String updatedDesc = "Updated Description";
        alertDef.setDescription(updatedDesc);
        AlertDefinition updatedAlertDef = LookupUtil.getAlertDefinitionManager().updateAlertDefinition(getOverlord(),
            alertDef.getId(), alertDef, false); // note that resetMatching is false
        assert updatedDesc.equals(updatedAlertDef.getDescription()) : "Description should be updated";
        assert updatedAlertDef.getConditions().size() == 1 : "1 alertDef condition should exist after the update";
        assert updatedAlertDef.getConditions().iterator().next().getId() == condition.getId() : "condition should not be updated";

        // get the alert again, and make sure it still has a log with the same condition
        alerts = getAlerts(resourceWithSchedules.getId());
        assert alerts.size() == 1 : "1 alert should have fired: " + alerts;
        alert = alerts.get(0);

        assert alert.getConditionLogs().size() == 1 : "1 condition log should exist after the update";
        conditionLog = alert.getConditionLogs().iterator().next();
        Assert.assertEquals(conditionLog.getCondition().getId(), conditionId,
            "original condition should still have been associated with the alert");

        // update the condition on the def and then update the def
        condition.setThreshold(41.0);
        updatedAlertDef = LookupUtil.getAlertDefinitionManager().updateAlertDefinition(getOverlord(), alertDef.getId(),
            alertDef, true); // note that resetMatching is true
        assert updatedAlertDef.getConditions().size() == 1 : "1 alertDef condition should exist after the update";
        assert updatedAlertDef.getConditions().iterator().next().getId() != condition.getId() : "condition should be updated";

        // get the alert again, and make sure it still has a log with the same condition
        alerts = getAlerts(resourceWithSchedules.getId());
        assert alerts.size() == 1 : "1 alert should have fired: " + alerts;
        alert = alerts.get(0);
View Full Code Here


    @Test(enabled = ENABLED)
    public void testBZ1058534_changeCondition() throws Exception {
        // create our resource with alert definition
        MeasurementDefinition metricDef = createResourceWithMetricSchedule("type-with-trait.xml", "TypeWithTrait");

        AlertDefinition alertDef = createAlertDefinitionWithChangeFromNull(metricDef, resource.getId());

        assert alertDef.getConditions().size() == 1 : "1 alertDef condition should exist";
        AlertCondition condition = alertDef.getConditions().iterator().next();
        int conditionId = condition.getId();

        // re-load the resource so we get the measurement schedule
        final Resource resourceWithSchedules = loadResourceWithSchedules(resource.getId());
        MeasurementSchedule schedule = resourceWithSchedules.getSchedules().iterator().next();
View Full Code Here

        cond2.setThreshold(60.0); // value < 60 threshold
        cond2.setOption(null);
        cond2.setMeasurementDefinition(metricDef);
        conditions.add(cond2);

        AlertDefinition alertDefinition = new AlertDefinition();
        alertDefinition.setName("two condition ALL alert");
        alertDefinition.setEnabled(true);
        alertDefinition.setPriority(AlertPriority.HIGH);
        alertDefinition.setAlertDampening(new AlertDampening(Category.NONE));
        alertDefinition.setRecoveryId(0);
        alertDefinition.setConditionExpression(BooleanExpression.ALL);
        alertDefinition.setConditions(conditions);

        AlertDefinitionManagerLocal alertDefManager = LookupUtil.getAlertDefinitionManager();
        alertDefinition = alertDefManager.createAlertDefinitionInNewTransaction(getOverlord(), alertDefinition,
            resourceId, true);
        assert alertDefinition != null && alertDefinition.getId() > 0 : "did not persist alert def properly: "
            + alertDefinition;

        // now that we created an alert def, we have to reload the alert condition cache
        reloadAllAlertConditionCaches();
View Full Code Here

        cond.setMeasurementDefinition(metricDef);

        AlertDampening dampening = new AlertDampening(Category.CONSECUTIVE_COUNT);
        dampening.setValue(3);

        AlertDefinition alertDefinition = new AlertDefinition();
        alertDefinition.setName("alert with consecutive count = 3 dampening");
        alertDefinition.setEnabled(true);
        alertDefinition.setPriority(AlertPriority.HIGH);
        alertDefinition.setAlertDampening(dampening);
        alertDefinition.setRecoveryId(0);
        alertDefinition.setConditionExpression(BooleanExpression.ALL);
        alertDefinition.setConditions(Collections.singleton(cond));

        AlertDefinitionManagerLocal alertDefManager = LookupUtil.getAlertDefinitionManager();
        alertDefinition = alertDefManager.createAlertDefinitionInNewTransaction(getOverlord(), alertDefinition,
            resourceId, true);
        assert alertDefinition != null && alertDefinition.getId() > 0 : "did not persist alert def properly: "
            + alertDefinition;

        // now that we created an alert def, we have to reload the alert condition cache
        reloadAllAlertConditionCaches();
View Full Code Here

        cond1.setOption(Double.valueOf(60.0).toString()); // option is a stringified double that is always the high value of the range
        cond1.setComparator("<"); // the value must be inside the range
        cond1.setMeasurementDefinition(metricDef);
        conditions.add(cond1);

        AlertDefinition alertDefinition = new AlertDefinition();
        alertDefinition.setName("one inside-range condition alert");
        alertDefinition.setEnabled(true);
        alertDefinition.setPriority(AlertPriority.HIGH);
        alertDefinition.setAlertDampening(new AlertDampening(Category.NONE));
        alertDefinition.setRecoveryId(0);
        alertDefinition.setConditionExpression(BooleanExpression.ALL);
        alertDefinition.setConditions(conditions);

        AlertDefinitionManagerLocal alertDefManager = LookupUtil.getAlertDefinitionManager();
        alertDefinition = alertDefManager.createAlertDefinitionInNewTransaction(getOverlord(), alertDefinition,
            resourceId, true);
        assert alertDefinition != null && alertDefinition.getId() > 0 : "did not persist alert def properly: "
            + alertDefinition;

        // now that we created an alert def, we have to reload the alert condition cache
        reloadAllAlertConditionCaches();
View Full Code Here

        cond1.setCategory(AlertConditionCategory.TRAIT);
        cond1.setName(metricDef.getDisplayName());
        cond1.setMeasurementDefinition(metricDef);
        conditions.add(cond1);

        AlertDefinition alertDefinition = new AlertDefinition();
        alertDefinition.setName("one trait change from null alert");
        alertDefinition.setEnabled(true);
        alertDefinition.setPriority(AlertPriority.HIGH);
        alertDefinition.setAlertDampening(new AlertDampening(Category.NONE));
        alertDefinition.setRecoveryId(0);
        alertDefinition.setConditionExpression(BooleanExpression.ALL);
        alertDefinition.setConditions(conditions);

        AlertDefinitionManagerLocal alertDefManager = LookupUtil.getAlertDefinitionManager();
        alertDefinition = alertDefManager.createAlertDefinitionInNewTransaction(getOverlord(), alertDefinition,
            resourceId, true);
        assert alertDefinition != null && alertDefinition.getId() > 0 : "did not persist alert def properly: "
            + alertDefinition;

        // now that we created an alert def, we have to reload the alert condition cache
        reloadAllAlertConditionCaches();
View Full Code Here

        cond1.setOption(null);
        cond1.setComparator(null);
        cond1.setMeasurementDefinition(null);
        conditions.add(cond1);

        AlertDefinition alertDefinition = new AlertDefinition();
        alertDefinition.setName("avail change: " + condition.name());
        alertDefinition.setEnabled(true);
        alertDefinition.setPriority(AlertPriority.HIGH);
        alertDefinition.setAlertDampening(new AlertDampening(Category.NONE));
        alertDefinition.setRecoveryId(0);
        alertDefinition.setConditionExpression(BooleanExpression.ALL);
        alertDefinition.setConditions(conditions);

        AlertDefinitionManagerLocal alertDefManager = LookupUtil.getAlertDefinitionManager();
        alertDefinition = alertDefManager.createAlertDefinitionInNewTransaction(getOverlord(), alertDefinition,
            resourceId, true);
        assert alertDefinition != null && alertDefinition.getId() > 0 : "did not persist alert def properly: "
            + alertDefinition;

        // now that we created an alert def, we have to reload the alert condition cache
        reloadAllAlertConditionCaches();
View Full Code Here

        cond1.setOption(String.valueOf(duration));
        cond1.setComparator(null);
        cond1.setMeasurementDefinition(null);
        conditions.add(cond1);

        AlertDefinition alertDefinition = new AlertDefinition();
        alertDefinition.setName(alertDefName);
        alertDefinition.setEnabled(true);
        alertDefinition.setPriority(AlertPriority.HIGH);
        alertDefinition.setAlertDampening(new AlertDampening(Category.NONE));
        alertDefinition.setRecoveryId(0);
        alertDefinition.setConditionExpression(BooleanExpression.ALL);
        alertDefinition.setConditions(conditions);

        AlertDefinitionManagerLocal alertDefManager = LookupUtil.getAlertDefinitionManager();
        alertDefinition = alertDefManager.createAlertDefinitionInNewTransaction(getOverlord(), alertDefinition,
            resourceId, true);
        assert alertDefinition != null && alertDefinition.getId() > 0 : "did not persist alert def properly: "
            + alertDefinition;

        // now that we created an alert def, we have to reload the alert condition cache
        reloadAllAlertConditionCaches();
View Full Code Here

        cond1.setOption(Double.valueOf(60.0).toString()); // option is a stringified double that is always the high value of the range
        cond1.setComparator(">"); // the value must be outside the range
        cond1.setMeasurementDefinition(metricDef);
        conditions.add(cond1);

        AlertDefinition alertDefinition = new AlertDefinition();
        alertDefinition.setName("one outside-range condition alert");
        alertDefinition.setEnabled(true);
        alertDefinition.setPriority(AlertPriority.HIGH);
        alertDefinition.setAlertDampening(new AlertDampening(Category.NONE));
        alertDefinition.setRecoveryId(0);
        alertDefinition.setConditionExpression(BooleanExpression.ALL);
        alertDefinition.setConditions(conditions);

        AlertDefinitionManagerLocal alertDefManager = LookupUtil.getAlertDefinitionManager();
        alertDefinition = alertDefManager.createAlertDefinitionInNewTransaction(getOverlord(), alertDefinition,
            resourceId, true);
        assert alertDefinition != null && alertDefinition.getId() > 0 : "did not persist alert def properly: "
            + alertDefinition;

        // now that we created an alert def, we have to reload the alert condition cache
        reloadAllAlertConditionCaches();
View Full Code Here

                    return ret;
                }
            });

        AlertDefinition alertDef = new AlertDefinition();

        AlertCondition cond = new AlertCondition(alertDef, AlertConditionCategory.AVAILABILITY);
        cond.setName(AlertConditionOperator.AVAIL_GOES_UP.name());
        alertDef.setName("liveAvailabilityTestAlert");
        alertDef.setResource(newResource);
        alertDef.setPriority(AlertPriority.MEDIUM);
        alertDef.setRecoveryId(0);
        alertDef.setAlertDampening(new AlertDampening(AlertDampening.Category.NONE));
        alertDef.setConditions(Collections.singleton(cond));
        alertDef.setEnabled(true);
        alertDef.setConditionExpression(BooleanExpression.ALL);

        AlertDefinitionManagerLocal alertDefinitionManager = LookupUtil.getAlertDefinitionManager();
        alertDefinitionManager.createAlertDefinitionInNewTransaction(getOverlord(), alertDef, newResource.getId(), true);

        //obvious, right? This needs to be done for the alert subsystem to become aware of the new def
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.