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());
}
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();
}
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;
}
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());
}
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));
}
Aggregations