use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class TestUtils method createEvent.
static OnmsEvent createEvent(OnmsNode node, OnmsSeverity severity, OnmsDistPoller distPoller) {
OnmsEvent event = new OnmsEvent();
event.setEventUei(EventConstants.NODE_DOWN_EVENT_UEI);
event.setEventTime(new Date());
event.setEventCreateTime(new Date());
event.setEventSource(TestUtils.class.getName());
event.setDistPoller(distPoller);
event.setEventSeverity(severity.getId());
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setEventLogMsg("Dummy Log Message");
event.setNode(node);
return event;
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class NotificationManagerIT method canMatchEventParametersWhenAcknowledgingNotices.
@Test
@JUnitTemporaryDatabase
public void canMatchEventParametersWhenAcknowledgingNotices() throws IOException, SQLException {
// Insert some event in the database with a few event parameters
OnmsEvent dbEvent = new OnmsEvent();
dbEvent.setDistPoller(m_distPollerDao.whoami());
dbEvent.setEventUei(EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI);
dbEvent.setEventCreateTime(new Date());
dbEvent.setEventLog("Y");
dbEvent.setEventDisplay("Y");
dbEvent.setEventSeverity(OnmsSeverity.CRITICAL.getId());
dbEvent.setEventSource("test");
dbEvent.setEventTime(new Date());
dbEvent.setNode(node1);
dbEvent.setEventParameters(Arrays.asList(new OnmsEventParameter(dbEvent, "some-parameter", "some-specific-value", "string"), new OnmsEventParameter(dbEvent, "some-other-parameter", "some-other-specific-value", "string")));
m_eventDao.save(dbEvent);
m_eventDao.flush();
// Create some notification referencing the event we just created
Notification notification = new Notification();
Map<String, String> params = new ImmutableMap.Builder<String, String>().put(NotificationManager.PARAM_TEXT_MSG, "some text message").put(NotificationManager.PARAM_NODE, node1.getNodeId()).put(NotificationManager.PARAM_INTERFACE, InetAddressUtils.toIpAddrString(ipInterfaceOnNode1.getIpAddress())).put(NotificationManager.PARAM_SERVICE, "ICMP").put("eventUEI", dbEvent.getEventUei()).put("eventID", Integer.toString(dbEvent.getId())).build();
m_notificationManager.insertNotice(1, params, "q1", notification);
final String[] parmMatchList = new String[] { "parm[some-parameter]", "parm[#2]" };
// Verify that we're able to match the the notice when we have the same parameters set
Event e = new EventBuilder(EventConstants.SERVICE_RESPONSIVE_EVENT_UEI, "test").addParam("some-parameter", "some-specific-value").addParam("some-other-parameter", "some-other-specific-value").getEvent();
Collection<Integer> eventIds = m_notificationManager.acknowledgeNotice(e, EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI, parmMatchList);
assertEquals(1, eventIds.size());
assertEquals(dbEvent.getId(), eventIds.iterator().next());
unacknowledgeAllNotices();
// It should not match when either of the event parameters are different
e = new EventBuilder(EventConstants.SERVICE_RESPONSIVE_EVENT_UEI, "test").addParam("some-parameter", "!some-specific-value").addParam("some-other-parameter", "some-other-specific-value").getEvent();
eventIds = m_notificationManager.acknowledgeNotice(e, EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI, parmMatchList);
assertEquals(0, eventIds.size());
unacknowledgeAllNotices();
e = new EventBuilder(EventConstants.SERVICE_RESPONSIVE_EVENT_UEI, "test").addParam("some-parameter", "some-specific-value").addParam("some-other-parameter", "!some-other-specific-value").getEvent();
eventIds = m_notificationManager.acknowledgeNotice(e, EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI, parmMatchList);
assertEquals(0, eventIds.size());
unacknowledgeAllNotices();
// It should not match when either of the event parameters are missing
e = new EventBuilder(EventConstants.SERVICE_RESPONSIVE_EVENT_UEI, "test").addParam("some-other-parameter", "some-other-specific-value").getEvent();
eventIds = m_notificationManager.acknowledgeNotice(e, EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI, parmMatchList);
assertEquals(0, eventIds.size());
unacknowledgeAllNotices();
e = new EventBuilder(EventConstants.SERVICE_RESPONSIVE_EVENT_UEI, "test").addParam("some-parameter", "some-specific-value").getEvent();
eventIds = m_notificationManager.acknowledgeNotice(e, EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI, parmMatchList);
assertEquals(0, eventIds.size());
unacknowledgeAllNotices();
// Now try matching on other fields without any event parameters
final String[] fieldMatchList = new String[] { "nodeid", "interfaceid", "serviceid" };
e = new EventBuilder(EventConstants.SERVICE_RESPONSIVE_EVENT_UEI, "test").setNodeid(node1.getId()).setInterface(ipInterfaceOnNode1.getIpAddress()).setService("ICMP").getEvent();
eventIds = m_notificationManager.acknowledgeNotice(e, EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI, fieldMatchList);
assertEquals(1, eventIds.size());
unacknowledgeAllNotices();
// Expect no match if we set different values responsive event
e = new EventBuilder(EventConstants.SERVICE_RESPONSIVE_EVENT_UEI, "test").setNodeid(node1.getId() + 1).setInterface(InetAddressUtils.UNPINGABLE_ADDRESS).setService("HTTP").getEvent();
eventIds = m_notificationManager.acknowledgeNotice(e, EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI, fieldMatchList);
assertEquals(0, eventIds.size());
unacknowledgeAllNotices();
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class AcknowledgmentDaoIT method testSaveWithAlarm.
@Test
@Transactional
public void testSaveWithAlarm() {
OnmsEvent event = new OnmsEvent();
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setEventCreateTime(new Date());
event.setDistPoller(m_distPollerDao.whoami());
event.setEventTime(new Date());
event.setEventSeverity(OnmsSeverity.CRITICAL.getId());
event.setEventUei("uei://org/opennms/test/EventDaoTest");
event.setEventSource("test");
m_eventDao.save(event);
OnmsNode node = m_nodeDao.findAll().iterator().next();
OnmsAlarm alarm = new OnmsAlarm();
alarm.setNode(node);
alarm.setUei(event.getEventUei());
alarm.setSeverityId(event.getEventSeverity());
alarm.setFirstEventTime(event.getEventTime());
alarm.setLastEvent(event);
alarm.setCounter(new Integer(1));
alarm.setDistPoller(m_distPollerDao.whoami());
alarm.setAlarmAckTime(new Date());
alarm.setAlarmAckUser("not-admin");
m_alarmDao.save(alarm);
m_alarmDao.flush();
OnmsAcknowledgment ack = new OnmsAcknowledgment(alarm);
getAcknowledgmentDao().save(ack);
Integer ackId = new Integer(ack.getId());
ack = null;
OnmsAcknowledgment ack2 = getAcknowledgmentDao().get(ackId);
OnmsAlarm alarm2 = m_alarmDao.get(ack2.getRefId());
assertEquals(ack2.getAckUser(), alarm2.getAlarmAckUser());
assertEquals(ack2.getAckTime(), alarm2.getAlarmAckTime());
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class AlarmDaoIT method testParameterizedSql.
/**
* @see https://issues.opennms.org/browse/NMS-9480
*/
@Test
@Transactional
public void testParameterizedSql() {
OnmsEvent event = new OnmsEvent();
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setEventCreateTime(new Date());
event.setDistPoller(m_distPollerDao.whoami());
event.setEventTime(new Date());
event.setEventSeverity(OnmsSeverity.CRITICAL.getId());
event.setEventUei("uei://org/opennms/test/EventDaoTest");
event.setEventSource("test");
m_eventDao.save(event);
OnmsNode node = m_nodeDao.findAll().iterator().next();
OnmsAlarm alarm = new OnmsAlarm();
alarm.setNode(node);
alarm.setUei(event.getEventUei());
alarm.setSeverityId(event.getEventSeverity());
alarm.setFirstEventTime(event.getEventTime());
alarm.setLastEvent(event);
alarm.setCounter(1);
alarm.setDistPoller(m_distPollerDao.whoami());
m_alarmDao.save(alarm);
CriteriaBuilder cb = new CriteriaBuilder(OnmsAlarm.class);
cb.sql("{alias}.alarmid in (?)", alarm.getId(), Type.INTEGER);
List<OnmsAlarm> alarms = m_alarmDao.findMatching(cb.toCriteria());
assertEquals(alarm.getId(), alarms.get(0).getId());
assertEquals(event.getEventTime(), alarms.get(0).getFirstEventTime());
assertEquals(event.getEventUei(), alarms.get(0).getUei());
cb = new CriteriaBuilder(OnmsAlarm.class);
cb.sql("{alias}.firsteventtime = ?", event.getEventTime(), Type.TIMESTAMP);
m_alarmDao.findMatching(cb.toCriteria());
assertEquals(alarm.getId(), alarms.get(0).getId());
assertEquals(event.getEventTime(), alarms.get(0).getFirstEventTime());
assertEquals(event.getEventUei(), alarms.get(0).getUei());
cb = new CriteriaBuilder(OnmsAlarm.class);
cb.sql("{alias}.eventuei = ?", event.getEventUei(), Type.STRING);
m_alarmDao.findMatching(cb.toCriteria());
assertEquals(alarm.getId(), alarms.get(0).getId());
assertEquals(event.getEventTime(), alarms.get(0).getFirstEventTime());
assertEquals(event.getEventUei(), alarms.get(0).getUei());
cb = new CriteriaBuilder(OnmsAlarm.class);
cb.sql("{alias}.alarmid = ? and {alias}.eventuei like ?", new Object[] { alarm.getId(), "%uei.opennms.org%" }, new Type[] { Type.INTEGER, Type.STRING });
m_alarmDao.findMatching(cb.toCriteria());
assertEquals(alarm.getId(), alarms.get(0).getId());
assertEquals(event.getEventTime(), alarms.get(0).getFirstEventTime());
assertEquals(event.getEventUei(), alarms.get(0).getUei());
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class AlarmDaoIT method testSave.
@Test
@Transactional
public void testSave() {
OnmsEvent event = new OnmsEvent();
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setEventCreateTime(new Date());
event.setDistPoller(m_distPollerDao.whoami());
event.setEventTime(new Date());
event.setEventSeverity(OnmsSeverity.CRITICAL.getId());
event.setEventUei("uei://org/opennms/test/EventDaoTest");
event.setEventSource("test");
m_eventDao.save(event);
OnmsNode node = m_nodeDao.findAll().iterator().next();
OnmsAlarm alarm = new OnmsAlarm();
alarm.setNode(node);
alarm.setUei(event.getEventUei());
alarm.setSeverityId(event.getEventSeverity());
alarm.setFirstEventTime(event.getEventTime());
alarm.setLastEvent(event);
alarm.setCounter(1);
alarm.setDistPoller(m_distPollerDao.whoami());
m_alarmDao.save(alarm);
// It works we're so smart! hehe
OnmsAlarm newAlarm = m_alarmDao.load(alarm.getId());
assertEquals("uei://org/opennms/test/EventDaoTest", newAlarm.getUei());
assertEquals(alarm.getLastEvent().getId(), newAlarm.getLastEvent().getId());
Collection<OnmsAlarm> alarms;
Criteria criteria = new Criteria(OnmsAlarm.class);
criteria.addRestriction(new EqRestriction("node.id", node.getId()));
alarms = m_alarmDao.findMatching(criteria);
assertEquals(1, alarms.size());
newAlarm = alarms.iterator().next();
assertEquals("uei://org/opennms/test/EventDaoTest", newAlarm.getUei());
assertEquals(alarm.getLastEvent().getId(), newAlarm.getLastEvent().getId());
}
Aggregations