Search in sources :

Example 56 with OnmsEvent

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;
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Date(java.util.Date)

Example 57 with OnmsEvent

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();
}
Also used : Date(java.util.Date) Notification(org.opennms.netmgt.config.notifications.Notification) ImmutableMap(com.google.common.collect.ImmutableMap) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) Event(org.opennms.netmgt.xml.event.Event) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 58 with OnmsEvent

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());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Date(java.util.Date) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 59 with OnmsEvent

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());
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Date(java.util.Date) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 60 with OnmsEvent

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());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) Criteria(org.opennms.core.criteria.Criteria) Date(java.util.Date) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OnmsEvent (org.opennms.netmgt.model.OnmsEvent)94 Date (java.util.Date)49 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)41 OnmsNode (org.opennms.netmgt.model.OnmsNode)37 Test (org.junit.Test)36 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)22 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)21 Transactional (org.springframework.transaction.annotation.Transactional)19 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)16 InetAddress (java.net.InetAddress)13 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)13 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)13 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)9 ArrayList (java.util.ArrayList)7 Before (org.junit.Before)6 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)6 Event (org.opennms.netmgt.xml.event.Event)6 LinkedList (java.util.LinkedList)5 List (java.util.List)5 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)5