Search in sources :

Example 21 with OnmsEventParameter

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

the class SnmpTrapNorthbounderTest method testNorthbounder.

/**
 * Tests the trap northbounder.
 *
 * @throws Exception the exception
 */
// FIXME Verify the content of the trap sent.
@Test
public void testNorthbounder() throws Exception {
    // Setup the configuration DAO
    FileSystemResource resource = new FileSystemResource(new File("src/test/resources/etc/snmptrap-northbounder-config.xml"));
    SnmpTrapNorthbounderConfigDao configDao = new SnmpTrapNorthbounderConfigDao();
    configDao.setConfigResource(resource);
    configDao.afterPropertiesSet();
    // Setup the trap northbounder (overriding the settings of the first sink to use the test trap receiver)
    SnmpTrapSink sink = configDao.getConfig().getSnmpTrapSink("localTest1");
    sink.setIpAddress(TRAP_DESTINATION.getHostAddress());
    sink.setPort(TRAP_PORT);
    SnmpTrapNorthbounder nbi = new SnmpTrapNorthbounder(configDao, sink.getName());
    nbi.afterPropertiesSet();
    // Setup test node
    OnmsNode node = new OnmsNode();
    node.setForeignSource("Server-MacOS");
    node.setForeignId("1");
    node.setId(1);
    node.setLabel("my-test-server");
    OnmsSnmpInterface snmpInterface = new OnmsSnmpInterface(node, 1);
    snmpInterface.setId(1);
    snmpInterface.setIfAlias("Connection to OpenNMS Wifi");
    snmpInterface.setIfDescr("en1");
    snmpInterface.setIfName("en1/0");
    snmpInterface.setPhysAddr("00:00:00:00:00:01");
    InetAddress address = InetAddress.getByName("10.0.1.1");
    OnmsIpInterface onmsIf = new OnmsIpInterface(address, node);
    onmsIf.setSnmpInterface(snmpInterface);
    onmsIf.setId(1);
    onmsIf.setIfIndex(1);
    onmsIf.setIpHostName("my-test-server");
    onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
    node.getIpInterfaces().add(onmsIf);
    // Setup test alarm
    OnmsAlarm onmsAlarm = new OnmsAlarm();
    onmsAlarm.setId(100);
    onmsAlarm.setNode(node);
    onmsAlarm.setIpAddr(address);
    onmsAlarm.setUei("uei.opennms.org/trap/myTrap1");
    onmsAlarm.setLastEvent(new OnmsEvent() {

        {
            this.setEventParameters(Lists.newArrayList(new OnmsEventParameter(this, "alarmId", "10", "Int32"), new OnmsEventParameter(this, "alarmMessage", "this is a test", "string")));
        }
    });
    NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
    Assert.assertEquals(2, alarm.getEventParametersCollection().size());
    // Verify the nortbound alarm and send it to the test receiver
    Assert.assertTrue(nbi.accepts(alarm));
    nbi.forwardAlarms(Collections.singletonList(alarm));
    // Introduce a delay to make sure the trap was sent and received.
    Thread.sleep(5000);
    Assert.assertEquals(1, getTrapsReceivedCount());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) FileSystemResource(org.springframework.core.io.FileSystemResource) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) File(java.io.File) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 22 with OnmsEventParameter

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

the class SyslogNorthBounderWithFiltersTest method testForwardAlarms.

/* (non-Javadoc)
     * @see org.opennms.netmgt.alarmd.northbounder.syslog.SyslogNorthBounderTest#testForwardAlarms()
     */
@Test
@Override
public void testForwardAlarms() throws Exception {
    // Initialize the configuration
    File configFile = new File("target/syslog-northbounder-config.xml");
    FileUtils.copyFile(new File("src/test/resources/syslog-northbounder-config1.xml"), configFile);
    // Initialize the configuration DAO
    SyslogNorthbounderConfigDao dao = new SyslogNorthbounderConfigDao();
    dao.setConfigResource(new FileSystemResource(configFile));
    dao.afterPropertiesSet();
    // Initialize the Syslog northbound interfaces
    List<SyslogNorthbounder> nbis = new LinkedList<>();
    for (SyslogDestination syslogDestination : dao.getConfig().getDestinations()) {
        SyslogNorthbounder nbi = new SyslogNorthbounder(dao, syslogDestination.getName());
        nbi.afterPropertiesSet();
        nbis.add(nbi);
    }
    // Add a sample node to the database
    OnmsNode node = new OnmsNode();
    node.setForeignSource("TestGroup");
    node.setForeignId("1");
    node.setId(m_nodeDao.getNextNodeId());
    node.setLabel("agalue");
    OnmsSnmpInterface snmpInterface = new OnmsSnmpInterface(node, 1);
    snmpInterface.setId(1);
    snmpInterface.setIfAlias("Connection to OpenNMS Wifi");
    snmpInterface.setIfDescr("en1");
    snmpInterface.setIfName("en1/0");
    snmpInterface.setPhysAddr("00:00:00:00:00:01");
    Set<OnmsIpInterface> ipInterfaces = new LinkedHashSet<>();
    InetAddress address = InetAddress.getByName("10.0.1.1");
    OnmsIpInterface onmsIf = new OnmsIpInterface(address, node);
    onmsIf.setSnmpInterface(snmpInterface);
    onmsIf.setId(1);
    onmsIf.setIfIndex(1);
    onmsIf.setIpHostName("agalue");
    onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
    ipInterfaces.add(onmsIf);
    node.setIpInterfaces(ipInterfaces);
    m_nodeDao.save(node);
    m_nodeDao.flush();
    // Create a sample Alarm
    OnmsAlarm onmsAlarm = new OnmsAlarm();
    onmsAlarm.setId(10);
    onmsAlarm.setUei("uei.opennms.org/nodes/interfaceDown");
    onmsAlarm.setNode(node);
    onmsAlarm.setSeverityId(6);
    onmsAlarm.setIpAddr(address);
    onmsAlarm.setCounter(1);
    onmsAlarm.setLogMsg("Interface Down");
    onmsAlarm.setLastEvent(new OnmsEvent() {

        {
            this.setEventParameters(Lists.newArrayList(new OnmsEventParameter(this, "owner", "agalue", "String")));
        }
    });
    NorthboundAlarm nbAlarm = new NorthboundAlarm(onmsAlarm);
    List<NorthboundAlarm> alarms = new LinkedList<>();
    alarms.add(nbAlarm);
    // Verify filters and send alarms to the northbound interfaces
    for (SyslogNorthbounder nbi : nbis) {
        Assert.assertTrue(nbi.accepts(nbAlarm));
        nbi.forwardAlarms(alarms);
    }
    // Induce a delay (based on the parent code)
    Thread.sleep(100);
    // Extract the log messages and verify the content
    BufferedReader reader = new BufferedReader(new StringReader(m_logStream.readStream()));
    List<String> messages = getMessagesFromBuffer(reader);
    Assert.assertTrue("Log messages sent: 2, Log messages received: " + messages.size(), 2 == messages.size());
    Assert.assertTrue(messages.get(0).contains("ALARM 10 FROM NODE agalue@TestGroup"));
    Assert.assertTrue(messages.get(1).contains("ALARM 10 FROM INTERFACE 10.0.1.1"));
    reader.close();
    // Remove the temporary configuration file
    configFile.delete();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) FileSystemResource(org.springframework.core.io.FileSystemResource) LinkedList(java.util.LinkedList) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) File(java.io.File) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 23 with OnmsEventParameter

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

the class AlarmStatsRestServiceIT method createEvent.

protected OnmsEvent createEvent() {
    final Calendar c = new GregorianCalendar();
    c.set(2010, Calendar.JANUARY, 1, 0, 0, 0);
    // test data assumes hours starting at midnight EST (not GMT)
    c.setTimeZone(TimeZone.getTimeZone("EST"));
    c.set(Calendar.MILLISECOND, 0);
    // no matter how big m_eventCount gets, this will still work
    c.add(Calendar.HOUR_OF_DAY, m_eventCount);
    final Date date = c.getTime();
    final OnmsEvent event = new OnmsEvent();
    event.setDistPoller(m_distPollerDao.whoami());
    event.setEventUei("uei.opennms.org/test/" + m_eventCount);
    event.setEventCreateTime(date);
    event.setEventTime(date);
    event.setEventDescr("Test event " + m_eventCount);
    event.setEventDisplay("Y");
    event.setEventLog("Y");
    event.setEventHost("es-with-the-most-es");
    event.setEventLogMsg("Test event " + m_eventCount + " (log)");
    event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "test", "parm", "string")));
    event.setEventSeverity(OnmsSeverity.MAJOR.getId());
    event.setEventSource("AlarmStatsRestServiceTest");
    event.setIpAddr(InetAddressUtils.UNPINGABLE_ADDRESS);
    event.setNode(m_databasePopulator.getNode1());
    event.setServiceType(m_databasePopulator.getServiceTypeDao().findByName("ICMP"));
    m_eventDao.save(event);
    m_eventDao.flush();
    m_eventCount++;
    return event;
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) Date(java.util.Date)

Example 24 with OnmsEventParameter

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

the class AlarmRestServiceIT method createAlarm.

private void createAlarm(final OnmsNode node, final String eventUei, final OnmsSeverity severity, final long epoch) {
    final OnmsIpInterface alarmNode = node.getIpInterfaces().iterator().next();
    final OnmsEvent event = new OnmsEvent();
    event.setDistPoller(m_databasePopulator.getDistPollerDao().whoami());
    event.setEventCreateTime(new Date(epoch));
    event.setEventDisplay("Y");
    event.setEventHost("127.0.0.1");
    event.setEventLog("Y");
    event.setEventSeverity(OnmsSeverity.INDETERMINATE.getId());
    event.setEventSource("JUnit");
    event.setEventTime(new Date(epoch));
    event.setEventUei(eventUei);
    if (ALARM_COUNTER.getAndIncrement() % 2 == 0) {
        event.addEventParameter(new OnmsEventParameter(event, "testParm1", "This is an awesome parm!", "string"));
    } else {
        event.addEventParameter(new OnmsEventParameter(event, "testParm2", "This is a weird parm", "string"));
    }
    event.addEventParameter(new OnmsEventParameter(event, "testParm3", "Here's another parm", "string"));
    event.setIpAddr(alarmNode.getIpAddress());
    event.setNode(node);
    event.setServiceType(m_databasePopulator.getServiceTypeDao().findByName("ICMP"));
    event.setEventSeverity(severity.getId());
    event.setIfIndex(alarmNode.getIfIndex());
    m_databasePopulator.getEventDao().save(event);
    m_databasePopulator.getEventDao().flush();
    final OnmsAlarm alarm = new OnmsAlarm();
    alarm.setDistPoller(m_databasePopulator.getDistPollerDao().whoami());
    alarm.setUei(event.getEventUei());
    alarm.setAlarmType(OnmsAlarm.PROBLEM_TYPE);
    alarm.setNode(node);
    alarm.setDescription("This is a test alarm");
    alarm.setLogMsg("this is a test alarm log message");
    alarm.setCounter(1);
    alarm.setIpAddr(alarmNode.getIpAddress());
    alarm.setSeverity(severity);
    alarm.setFirstEventTime(event.getEventTime());
    alarm.setLastEventTime(event.getEventTime());
    alarm.setLastEvent(event);
    alarm.setServiceType(m_databasePopulator.getServiceTypeDao().findByName("ICMP"));
    alarm.setIfIndex(alarmNode.getIfIndex());
    m_databasePopulator.getAlarmDao().save(alarm);
    m_databasePopulator.getAlarmDao().flush();
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) Date(java.util.Date)

Example 25 with OnmsEventParameter

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

the class AlarmRepositoryFilterIT method testParmsNotLikeFilter.

@Test
@Transactional
@JUnitTemporaryDatabase
public void testParmsNotLikeFilter() {
    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();
    NegativeEventParmLikeFilter parmFilter = new NegativeEventParmLikeFilter("user=rtc");
    assertEquals("user is not \"rtc\"", parmFilter.getTextDescription());
    AlarmCriteria criteria = new AlarmCriteria(parmFilter);
    OnmsAlarm[] alarms = m_daoAlarmRepo.getMatchingAlarms(AlarmUtil.getOnmsCriteria(criteria));
    // alarm2 and the alarm from DatabasePopulator match this criteria
    assertEquals(2, 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)

Aggregations

OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)25 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)22 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)19 Test (org.junit.Test)16 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)12 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)12 OnmsNode (org.opennms.netmgt.model.OnmsNode)12 InetAddress (java.net.InetAddress)10 Date (java.util.Date)10 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)8 LinkedList (java.util.LinkedList)4 Message (javax.jms.Message)3 ObjectMessage (javax.jms.ObjectMessage)3 TextMessage (javax.jms.TextMessage)3 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)3 JmsDestination (org.opennms.netmgt.alarmd.northbounder.jms.JmsDestination)3 JmsNorthbounder (org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounder)3 JmsNorthbounderConfig (org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfig)3 JmsNorthbounderConfigDao (org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfigDao)3 File (java.io.File)2