Package org.rhq.core.domain.alert

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


                    EntityContext.forResource(testData.getResource().getId()));
                assertEquals(1, count);

                PageList<Alert> foundAlerts = findAlertsByDefinitionIds(resourceAlertDefinitionId);
                assertEquals(1, foundAlerts.size());
                Alert alert = foundAlerts.iterator().next();
                em.refresh(alert);

                assertNotNull(alert.getAcknowledgingSubject());
                assertNotNull(alert.getAcknowledgeTime());
                assertEquals(testData.getSubject().getName(), alert.getAcknowledgingSubject());
                assertTrue("Alert should just have been acknowledged", alert.getAcknowledgeTime() >= testStartTimeStamp);
            }
        });
    }
View Full Code Here


                    EntityContext.forGroup(testData.getResourceGroup().getId()));
                assertEquals(1, count);

                PageList<Alert> foundAlerts = findAlertsByDefinitionIds(resourceAlertDefinitionId);
                assertEquals(1, foundAlerts.size());
                Alert alert = foundAlerts.iterator().next();
                em.refresh(alert);

                assertNotNull(alert.getAcknowledgingSubject());
                assertNotNull(alert.getAcknowledgeTime());
                assertEquals(testData.getSubject().getName(), alert.getAcknowledgingSubject());
                assertTrue("Alert should just have been acknowledged", alert.getAcknowledgeTime() >= testStartTimeStamp);
            }
        });
    }
View Full Code Here

                    EntityContext.forSubsystemView());
                assertEquals(1, count);

                PageList<Alert> foundAlerts = findAlertsByDefinitionIds(resourceAlertDefinitionId);
                assertEquals(1, foundAlerts.size());
                Alert alert = foundAlerts.iterator().next();
                em.refresh(alert);

                assertNotNull(alert.getAcknowledgingSubject());
                assertNotNull(alert.getAcknowledgeTime());
                assertEquals(testData.getSubject().getName(), alert.getAcknowledgingSubject());
                assertTrue("Alert should just have been acknowledged", alert.getAcknowledgeTime() >= testStartTimeStamp);
            }
        });
    }
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);
        }

        // enablement
        AlertDefUtil.setAlertDampeningRequestAttributes(request, adv);
        request.setAttribute("cTime", parseDate(av.getCtime()));
        return null;
    }
View Full Code Here

        List<Alert> results = alertManager.findAlertsByCriteria(subject, criteria);

        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

            assert entityManager.find(Resource.class, platform.getId()) != null : "Did not setup platform - cannot test";

            assertResults(entityManager, fiveMinutesAgo, 0);
            assertCount(entityManager, fiveMinutesAgo, 0);

            Alert alert = new Alert(alertDef, now - 10000);
            entityManager.persist(alert);

            //commitAndBegin();
            results = assertResults(entityManager, fiveMinutesAgo, 1);
            assertCount(entityManager, fiveMinutesAgo, 1);
            assertComposite(results.get(0), platform, 1);

            Alert alert2 = new Alert(alertDef2, now - 5000);
            entityManager.persist(alert2);

            //commitAndBegin();
            results = assertResults(entityManager, fiveMinutesAgo, 2);
            assertCount(entityManager, fiveMinutesAgo, 2);
            int platform1Index = (results.get(0).getResourceId() == platform.getId()) ? 0 : 1;
            int platform2Index = 1 - platform1Index;
            assertComposite(results.get(platform1Index), platform, 1);
            assertComposite(results.get(platform2Index), platform2, 1);

            Alert alert3 = new Alert(alertDef2, now);
            entityManager.persist(alert3);

            //commitAndBegin();
            results = assertResults(entityManager, fiveMinutesAgo, 2);
            assertCount(entityManager, fiveMinutesAgo, 2);
View Full Code Here

        try {
            try {
                // add alerts
                AlertDefinition ad = newResource.getAlertDefinitions().iterator().next();
                for (long timestamp = 0L; timestamp < 200L; timestamp++) {
                    Alert newAlert = createNewAlert(ad, timestamp);
                    assertEquals("bad alert persisted:" + newAlert, timestamp, newAlert.getCtime());
                    assertTrue("alert not persisted:" + newAlert, newAlert.getId() > 0);
                    if (timestamp % 50L == 0) {
                        em.flush();
                        em.clear();
                    }
                }
View Full Code Here

        em.persist(a);
        return a;
    }

    private Alert createNewAlert(AlertDefinition ad, long timestamp) {
        Alert a = new Alert(ad, timestamp);
        em.persist(a);

        AlertNotificationLog anl = new AlertNotificationLog(a, "dummy", ResultState.SUCCESS, "message");
        em.persist(anl);
View Full Code Here

        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);

        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");
    }
View Full Code Here

                }
                return false;
            }
        }, "1 alert should have fired", 10, SECONDS, 1, SECONDS);

        Alert alert = alertHolder[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");
    }
View Full Code Here

TOP

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

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.