Search in sources :

Example 71 with OnmsAlarm

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

the class AlarmRepositoryFilterIT method testParmsLikeFilter.

@Test
@Transactional
@JUnitTemporaryDatabase
public void testParmsLikeFilter() {
    OnmsDistPoller poller = m_dbPopulator.getDistPollerDao().whoami();
    assertNotNull(poller);
    final OnmsEvent event1 = new OnmsEvent();
    event1.setDistPoller(poller);
    event1.setEventCreateTime(new Date(1436881548292L));
    event1.setEventTime(new Date(1436881548292L));
    event1.setEventCreateTime(new Date(1437061537126L));
    event1.setEventDescr("This is the description of a test event.");
    event1.setEventDisplay("Y");
    event1.setEventHost("127.0.0.1");
    event1.setEventLog("Y");
    event1.setEventLogMsg("Test Event Log Message");
    event1.setEventSeverity(1);
    event1.setEventSource("test");
    event1.setEventTime(new Date(1437061537105L));
    event1.setEventUei("uei.opennms.org/test");
    event1.setIpAddr(InetAddressUtils.getInetAddress("192.168.1.1"));
    event1.setNode(m_dbPopulator.getNode1());
    event1.setServiceType(m_dbPopulator.getServiceTypeDao().findByName("ICMP"));
    event1.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event1, "url", "http://localhost:8980/opennms/rtc/post/Network+Interfaces", "string"), new OnmsEventParameter(event1, "user", "rtc", "string"), new OnmsEventParameter(event1, "passwd", "rtc", "string"), new OnmsEventParameter(event1, "catlabel", "Network Interfaces", "string")));
    m_dbPopulator.getEventDao().saveOrUpdate(event1);
    m_dbPopulator.getEventDao().flush();
    final OnmsEvent event2 = new OnmsEvent();
    event2.setDistPoller(poller);
    event2.setEventCreateTime(new Date(1436881548292L));
    event2.setEventTime(new Date(1436881548292L));
    event2.setEventCreateTime(new Date(1437061537126L));
    event2.setEventDescr("This is the description of a test event.");
    event2.setEventDisplay("Y");
    event2.setEventHost("127.0.0.1");
    event2.setEventLog("Y");
    event2.setEventLogMsg("Test Event Log Message");
    event2.setEventSeverity(1);
    event2.setEventSource("test");
    event2.setEventTime(new Date(1437061537105L));
    event2.setEventUei("uei.opennms.org/test");
    event2.setIpAddr(InetAddressUtils.getInetAddress("192.168.1.1"));
    event2.setNode(m_dbPopulator.getNode1());
    event2.setServiceType(m_dbPopulator.getServiceTypeDao().findByName("ICMP"));
    event2.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event2, "componentType", "serviceElement", "string"), new OnmsEventParameter(event2, "url", "http://localhost:8980/opennms/rtc/post/Network+Interfaces", "string"), new OnmsEventParameter(event2, "user", "rtcbomb", "string"), new OnmsEventParameter(event2, "passwd", "rtc", "string"), new OnmsEventParameter(event2, "catlabel", "Network Interfaces", "string")));
    m_dbPopulator.getEventDao().saveOrUpdate(event2);
    m_dbPopulator.getEventDao().flush();
    OnmsAlarm alarm = new OnmsAlarm();
    alarm.setUei("uei.opennms.org/vendor/Juniper/traps/jnxVpnIfUp");
    alarm.setLastEvent(event1);
    alarm.setSeverityId(3);
    alarm.setDistPoller(poller);
    alarm.setCounter(100);
    alarm.setLastEvent(event1);
    AlarmDao alarmDao = m_dbPopulator.getAlarmDao();
    alarmDao.save(alarm);
    alarmDao.flush();
    OnmsAlarm alarm2 = new OnmsAlarm();
    alarm2.setUei("uei.opennms.org/vendor/Juniper/traps/jnxVpnIfUp");
    alarm2.setLastEvent(event2);
    alarm2.setSeverityId(3);
    alarm2.setDistPoller(poller);
    alarm2.setCounter(100);
    alarm2.setLastEvent(event2);
    alarmDao.save(alarm2);
    alarmDao.flush();
    EventParmLikeFilter eventParmFilter = new EventParmLikeFilter("user=rtc");
    assertEquals("user=\"rtc\"", eventParmFilter.getTextDescription());
    AlarmCriteria criteria = new AlarmCriteria(eventParmFilter);
    OnmsAlarm[] alarms = m_daoAlarmRepo.getMatchingAlarms(AlarmUtil.getOnmsCriteria(criteria));
    assertEquals(1, alarms.length);
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) OnmsDistPoller(org.opennms.netmgt.model.OnmsDistPoller) AlarmDao(org.opennms.netmgt.dao.api.AlarmDao) Date(java.util.Date) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) Transactional(org.springframework.transaction.annotation.Transactional)

Example 72 with OnmsAlarm

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

the class AlarmStatsRestServiceIT method afterServletStart.

@Override
protected void afterServletStart() throws Exception {
    m_eventCount = 0;
    MockLogAppender.setupLogging(true, "DEBUG");
    m_databasePopulator.populateDatabase();
    for (final OnmsEvent event : m_eventDao.findAll()) {
        m_eventDao.delete(event);
    }
    m_eventDao.flush();
    for (final OnmsAlarm alarm : m_alarmDao.findAll()) {
        m_alarmDao.delete(alarm);
    }
    m_alarmDao.flush();
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm)

Example 73 with OnmsAlarm

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

the class AlarmRestServiceIT method testAlarmClearAsReadOnly.

@Test
@JUnitTemporaryDatabase
public void testAlarmClearAsReadOnly() throws Exception {
    setUser("ranger", new String[] { "ROLE_MOBILE", "ROLE_READONLY" });
    final OnmsAlarm alarm = createAlarm(OnmsSeverity.MAJOR);
    sendRequest(PUT, "/alarms/" + alarm.getId(), parseParamData("clear=true"), 403);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 74 with OnmsAlarm

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

the class AlarmRestServiceIT method testAlarmClearAsAdmin.

@Test
@JUnitTemporaryDatabase
public void testAlarmClearAsAdmin() throws Exception {
    setUser("admin", new String[] { "ROLE_ADMIN" });
    final OnmsAlarm alarm = createAlarm(OnmsSeverity.MAJOR);
    sendRequest(PUT, "/alarms/" + alarm.getId(), parseParamData("clear=true"), 204);
    final String xml = sendRequest(GET, "/alarms/" + alarm.getId(), 200);
    final OnmsAlarm fromRest = JaxbUtils.unmarshal(OnmsAlarm.class, xml);
    assertEquals(fromRest.getSeverity(), OnmsSeverity.CLEARED);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 75 with OnmsAlarm

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

the class AlarmRestServiceIT method testComplexQuery.

@Test
@JUnitTemporaryDatabase
@Transactional
public void testComplexQuery() throws Exception {
    String xml = null;
    final Map<String, String> parameters = new HashMap<String, String>();
    createAlarm(OnmsSeverity.CRITICAL);
    for (final OnmsAlarm alarm : getAlarmDao().findAll()) {
        System.err.println("alarm = " + alarm);
    }
    parameters.put("offset", "00");
    parameters.put("limit", "10");
    parameters.put("orderBy", "lastEventTime");
    parameters.put("order", "desc");
    // original requirements:
    // http://localhost:8980/opennms/rest/alarms?offset=00&limit=10&orderBy=lastEventTime&order=desc&lastEventTime=2011-08-19T11:11:11.000-07:00&comparator=gt&severity=MAJOR&comparator=eq
    // modified version:
    // http://localhost:8980/opennms/rest/alarms?offset=00&limit=10&orderBy=lastEventTime&order=desc&query=lastEventTime%20%3E%20'2011-08-19T11%3A11%3A11.000-07%3A00'%20AND%20severity%20%3D%20MAJOR
    parameters.put("query", "lastEventTime > '2011-08-19T11:11:11.000-07:00' AND severity = 3");
    xml = sendRequest(GET, "/alarms", parameters, 200);
    // assertTrue(xml.contains("<alarm severity=\"NORMAL\" id=\"1\""));
    assertXpathMatches(xml, "//alarm[@severity='NORMAL' and @id='1']");
    // assertFalse(xml.contains("<alarm severity=\"CRITICAL\" id=\"2\""));
    assertXpathDoesNotMatch(xml, "//alarm[@severity='CRITICAL' and @id='2']");
    parameters.put("query", "lastEventTime > '2011-08-19T11:11:11.000-07:00' AND severity >= 3");
    xml = sendRequest(GET, "/alarms", parameters, 200);
    // assertTrue(xml.contains("<alarm severity=\"NORMAL\" id=\"1\""));
    assertXpathMatches(xml, "//alarm[@severity='NORMAL' and @id='1']");
    // assertTrue(xml.contains("<alarm severity=\"CRITICAL\" id=\"2\""));
    assertXpathMatches(xml, "//alarm[@severity='CRITICAL' and @id='2']");
    parameters.put("query", "lastEventTime > '2011-08-19T11:11:11.000-07:00' AND severity >= NORMAL");
    xml = sendRequest(GET, "/alarms", parameters, 200);
    // assertTrue(xml.contains("<alarm severity=\"NORMAL\" id=\"1\""));
    assertXpathMatches(xml, "//alarm[@severity='NORMAL' and @id='1']");
    // assertTrue(xml.contains("<alarm severity=\"CRITICAL\" id=\"2\""));
    assertXpathMatches(xml, "//alarm[@severity='CRITICAL' and @id='2']");
    parameters.put("query", "lastEventTime > '2011-08-19T11:11:11.000-07:00' AND severity < NORMAL");
    xml = sendRequest(GET, "/alarms", parameters, 200);
    // assertFalse(xml.contains("<alarm severity=\"NORMAL\" id=\"1\""));
    assertXpathDoesNotMatch(xml, "//alarm[@severity='NORMAL' and @id='1']");
    // assertFalse(xml.contains("<alarm severity=\"CRITICAL\" id=\"2\""));
    assertXpathDoesNotMatch(xml, "//alarm[@severity='CRITICAL' and @id='2']");
    // assertTrue(xml.contains("count=\"0\""));
    assertXpathMatches(xml, "//alarms[@totalCount='0']");
    // original requirements:
    // http://localhost:8980/opennms/rest/alarms?offset=00&limit=10&orderBy=lastEventTime&order=desc&lastEventTime=2011-08-19T11:11:11.000-07:00&comparator=gt&severity=MAJOR&comparator=eq&ackUser=myuser&comparator=eq
    // acked - modified version:
    // http://localhost:8980/opennms/rest/alarms?offset=00&limit=10&orderBy=lastEventTime&order=desc&query=lastEventTime%20%3E%20'2011-08-19T11%3A11%3A11.000-07%3A00'%20AND%20severity%20%3E%20MAJOR%20AND%20alarmAckUser%20%3D%20'admin'
    parameters.put("query", "lastEventTime > '2011-08-19T11:11:11.000-07:00' AND severity > MAJOR AND alarmAckUser = 'admin'");
    xml = sendRequest(GET, "/alarms", parameters, 200);
    // assertFalse(xml.contains("<alarm severity=\"NORMAL\" id=\"1\""));
    assertXpathDoesNotMatch(xml, "//alarm[@severity='NORMAL' and @id='1']");
    // assertTrue(xml.contains("<alarm severity=\"CRITICAL\" id=\"2\""));
    assertXpathMatches(xml, "//alarm[@severity='CRITICAL' and @id='2']");
    // unacked - modified version:
    // http://localhost:8980/opennms/rest/alarms?offset=00&limit=10&orderBy=lastEventTime&order=desc&query=lastEventTime%20%3E%20'2011-08-19T11%3A11%3A11.000-07%3A00'%20AND%20severity%20%3E%20MAJOR%20AND%20alarmAckUser%20IS%20NULL
    parameters.put("query", "lastEventTime > '2011-08-19T11:11:11.000-07:00' AND severity > MAJOR AND alarmAckUser IS NULL");
    xml = sendRequest(GET, "/alarms", parameters, 200);
    // assertTrue(xml.contains("count=\"0\""));
    assertXpathMatches(xml, "//alarms[@totalCount='0']");
    // unacked - modified version:
    // http://localhost:8980/opennms/rest/alarms?offset=00&limit=10&orderBy=lastEventTime&order=desc&query=lastEventTime%20%3E%20'2011-08-19T11%3A11%3A11.000-07%3A00'%20AND%20severity%20%3C%20MAJOR%20AND%20alarmAckUser%20IS%20NULL
    parameters.put("query", "lastEventTime > '2011-08-19T11:11:11.000-07:00' AND severity < MAJOR AND alarmAckUser IS NULL");
    xml = sendRequest(GET, "/alarms", parameters, 200);
    // assertTrue(xml.contains("<alarm severity=\"NORMAL\" id=\"1\""));
    assertXpathMatches(xml, "//alarm[@severity='NORMAL' and @id='1']");
    // assertFalse(xml.contains("<alarm severity=\"CRITICAL\" id=\"2\""));
    assertXpathDoesNotMatch(xml, "//alarm[@severity='CRITICAL' and @id='2']");
}
Also used : HashMap(java.util.HashMap) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) Transactional(org.springframework.transaction.annotation.Transactional)

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