Search in sources :

Example 21 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class AlarmDaoIT method testAlarmSummary_AlarmWithNoEvent.

@Test
@Transactional
public void testAlarmSummary_AlarmWithNoEvent() {
    OnmsNode node = m_nodeDao.findAll().iterator().next();
    OnmsAlarm alarm = new OnmsAlarm();
    alarm.setNode(node);
    alarm.setUei("uei://org/opennms/test/badAlarmTest");
    alarm.setSeverityId(new Integer(7));
    alarm.setCounter(1);
    alarm.setDistPoller(m_distPollerDao.whoami());
    m_alarmDao.save(alarm);
    List<AlarmSummary> summary = m_alarmDao.getNodeAlarmSummaries();
    Assert.assertNotNull(summary);
    Assert.assertEquals(1, summary.size());
    AlarmSummary sum = summary.get(0);
    Assert.assertEquals(node.getLabel(), sum.getNodeLabel());
    Assert.assertEquals(alarm.getSeverity().getId(), sum.getMaxSeverity().getId());
    Assert.assertEquals("N/A", sum.getFuzzyTimeDown());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class AMQPAlarmNorthbounderBlueprintTest method canForwardAlarm.

@Test
public void canForwardAlarm() throws Exception {
    getMockEndpoint("mock:destination").expectedMessageCount(1);
    // Forward a single alarm
    OnmsAlarm alarm = new OnmsAlarm();
    NorthboundAlarm northboundAlarm = new NorthboundAlarm(alarm);
    List<NorthboundAlarm> northboundAlarms = Lists.newArrayList(northboundAlarm);
    alarmNorthbounder.forwardAlarms(northboundAlarms);
    assertMockEndpointsSatisfied();
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) Test(org.junit.Test) CamelBlueprintTest(org.opennms.core.test.camel.CamelBlueprintTest)

Example 23 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class BsmTestUtils method createAlarm.

private static OnmsAlarm createAlarm(String uei, OnmsSeverity severity, String reductionKey) {
    OnmsAlarm customAlarm = new OnmsAlarm();
    customAlarm.setUei(Objects.requireNonNull(uei));
    customAlarm.setSeverity(Objects.requireNonNull(severity));
    customAlarm.setReductionKey(Objects.requireNonNull(reductionKey));
    return customAlarm;
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm)

Example 24 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class BsmdIT method canSendEventsOnOperationalStatusChanged.

/**
 * Verifies that the daemon generates events when the operational status
 * of a Business Service is changed.
 *
 * Also verifies that the generate events include parameters which map
 * to the business services attributes.
 *
 * @throws Exception
 */
@Test
@Transactional
public void canSendEventsOnOperationalStatusChanged() throws Exception {
    // Create a business service
    BusinessServiceEntity simpleBs = createSimpleBusinessService();
    // Start the daemon
    m_bsmd.start();
    // Expect a statusChanged event
    EventBuilder ebldr = new EventBuilder(EventConstants.BUSINESS_SERVICE_OPERATIONAL_STATUS_CHANGED_UEI, "test");
    m_eventMgr.getEventAnticipator().anticipateEvent(ebldr.getEvent());
    // Expect a serviceProblem event
    ebldr = new EventBuilder(EventConstants.BUSINESS_SERVICE_PROBLEM_UEI, "test");
    m_eventMgr.getEventAnticipator().anticipateEvent(ebldr.getEvent());
    // Create the alarm
    OnmsAlarm alarm = createAlarm();
    m_alarmDao.save(alarm);
    // Send alarm created event
    ebldr = new EventBuilder(EventConstants.ALARM_CREATED_UEI, "test");
    ebldr.addParam(EventConstants.PARM_ALARM_ID, alarm.getId());
    m_bsmd.handleAlarmLifecycleEvents(ebldr.getEvent());
    // Verify expectations
    Collection<Event> stillWaitingFor = m_eventMgr.getEventAnticipator().waitForAnticipated(5000);
    assertTrue("Expected events not forthcoming " + stillWaitingFor, stillWaitingFor.isEmpty());
    verifyParametersOnAnticipatedEventsReceived(m_eventMgr.getEventAnticipator(), simpleBs.getId());
    // Expect a statusChanged event
    ebldr = new EventBuilder(EventConstants.BUSINESS_SERVICE_OPERATIONAL_STATUS_CHANGED_UEI, "test");
    m_eventMgr.getEventAnticipator().anticipateEvent(ebldr.getEvent());
    // Expect a serviceProblemResolved event
    ebldr = new EventBuilder(EventConstants.BUSINESS_SERVICE_PROBLEM_RESOLVED_UEI, "test");
    m_eventMgr.getEventAnticipator().anticipateEvent(ebldr.getEvent());
    // Clear the alarm
    alarm.setSeverity(OnmsSeverity.CLEARED);
    // Send an alarm cleared event
    ebldr = new EventBuilder(EventConstants.ALARM_CLEARED_UEI, "test");
    ebldr.addParam(EventConstants.PARM_ALARM_ID, alarm.getId());
    m_bsmd.handleAlarmLifecycleEvents(ebldr.getEvent());
    // Verify expectations
    stillWaitingFor = m_eventMgr.getEventAnticipator().waitForAnticipated(5000);
    assertTrue("Expected events not forthcoming " + stillWaitingFor, stillWaitingFor.isEmpty());
    verifyParametersOnAnticipatedEventsReceived(m_eventMgr.getEventAnticipator(), simpleBs.getId());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Event(org.opennms.netmgt.xml.event.Event) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class BsmdIT method verifyAlarmPollingIsEnabled.

/**
 * Verifies that the daemon polls the alarm table on a regular basis. This is done to ensure that all alarms are
 * considered, because the appropriate alarm created/changed/deleted/updated event may not have been sent.
 */
@Test
public void verifyAlarmPollingIsEnabled() throws Exception {
    System.setProperty(Bsmd.POLL_INTERVAL_KEY, "10");
    BusinessServiceEntity simpleBs = createSimpleBusinessService();
    m_bsmd.start();
    // Create an alarm, but do NOT send any lifecyle events
    final AtomicReference<OnmsAlarm> alarmRef = new AtomicReference<>();
    template.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
            Assert.assertEquals(Status.NORMAL, m_bsmd.getBusinessServiceStateMachine().getOperationalStatus(wrap(simpleBs)));
            OnmsAlarm alarm = createAlarm();
            m_alarmDao.save(alarm);
            alarmRef.set(alarm);
            m_alarmDao.flush();
            Assert.assertEquals(Status.NORMAL, m_bsmd.getBusinessServiceStateMachine().getOperationalStatus(wrap(simpleBs)));
        }
    });
    // Wait for the business service status to be updated
    await().atMost(20, SECONDS).until(() -> m_bsmd.getBusinessServiceStateMachine().getOperationalStatus(wrap(simpleBs)), equalTo(Status.CRITICAL));
    // Now delete alarm, and again, do NOT send any lifecyle events
    template.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
            m_alarmDao.delete(alarmRef.get());
            m_alarmDao.flush();
        }
    });
    // Wait for the business service status to be updated
    await().atMost(20, SECONDS).until(() -> m_bsmd.getBusinessServiceStateMachine().getOperationalStatus(wrap(simpleBs)), equalTo(Status.NORMAL));
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) TransactionStatus(org.springframework.transaction.TransactionStatus) AtomicReference(java.util.concurrent.atomic.AtomicReference) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.Test)

Aggregations

OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)143 Test (org.junit.Test)58 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)41 Date (java.util.Date)36 OnmsNode (org.opennms.netmgt.model.OnmsNode)36 Transactional (org.springframework.transaction.annotation.Transactional)35 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)19 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)18 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)18 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)17 ArrayList (java.util.ArrayList)14 OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)14 InetAddress (java.net.InetAddress)13 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)11 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)10 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)9 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)9 AlarmDao (org.opennms.netmgt.dao.api.AlarmDao)8 AlarmCriteria (org.opennms.web.alarm.filter.AlarmCriteria)8 LinkedList (java.util.LinkedList)7