Search in sources :

Example 51 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class PendingPollEventTest method testPollEventTimeout.

@Test
public void testPollEventTimeout() throws Exception {
    final Date d = new Date();
    final EventBuilder eb = new EventBuilder("foo", "bar", d);
    final PendingPollEvent ppe = new PendingPollEvent(eb.getEvent());
    ppe.setExpirationTimeInMillis(Long.MAX_VALUE);
    assertFalse("timedOut should be false: " + ppe.isTimedOut(), ppe.isTimedOut());
    assertTrue("pending should be true: " + ppe.isPending(), ppe.isPending());
    ppe.setExpirationTimeInMillis(Long.MIN_VALUE);
    assertTrue("timedOut should be true: " + ppe.isTimedOut(), ppe.isTimedOut());
    assertFalse("pending should be false: " + ppe.isPending(), ppe.isPending());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Date(java.util.Date) Test(org.junit.Test)

Example 52 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class EventconfFactoryIT method testFindByEventUeiKnown1000Times.

@Test
public void testFindByEventUeiKnown1000Times() throws Exception {
    final int ATTEMPTS = 10000;
    // knownUEI1 is currently set to 'uei.opennms.org/internal/capsd/snmpConflictsWithDb'
    // and is defined in the root of the eventconf that is loaded bellow.
    // Prior to this commit, this test would produce very different results
    // when running against another UEI i.e. 'uei.opennms.org/default/event'
    // that happens to be the last event defined in the last included file
    EventBuilder bldr = new EventBuilder(knownUEI1, "testFindByEventUeiKnown");
    DefaultEventConfDao eventConfDao = loadConfiguration("eventconf-speedtest/eventconf.xml");
    Event eventConf = null;
    org.opennms.netmgt.xml.event.Event event = bldr.getEvent();
    long start = System.currentTimeMillis();
    for (int i = 0; i < ATTEMPTS; i++) {
        eventConf = eventConfDao.findByEvent(event);
    }
    long end = System.currentTimeMillis();
    long elapsed = end - start;
    System.err.printf("%d Attempts: Elapsed: %d ms: events per second %f.%n", ATTEMPTS, elapsed, ATTEMPTS * 1000.0 / elapsed);
    assertNotNull("returned event configuration for event with known UEI '" + knownUEI1 + "' should not be null", eventConf);
    assertEquals("UEI", bldr.getEvent().getUei(), eventConf.getUei());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) SyntaxToEvent(org.opennms.netmgt.model.events.snmp.SyntaxToEvent) Event(org.opennms.netmgt.xml.eventconf.Event) Test(org.junit.Test)

Example 53 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class EventconfFactoryIT method testFindByTrapWithWildcard.

@Test
public void testFindByTrapWithWildcard() throws Exception {
    String enterpriseId = ".1.3.6.1.4.1.253.1.2.3";
    int generic = 6;
    int specific = 1;
    String ip = "127.0.0.1";
    EventBuilder bldr = new EventBuilder(null, "trapd");
    bldr.setSnmpVersion("v2");
    bldr.setCommunity("public");
    bldr.setHost(ip);
    bldr.setSnmpHost(ip);
    bldr.setInterface(InetAddress.getByName("127.0.0.1"));
    // time-stamp (units is hundreths of a second
    bldr.setSnmpTimeStamp(System.currentTimeMillis() / 10);
    bldr.setGeneric(generic);
    bldr.setSpecific(specific);
    bldr.setEnterpriseId(enterpriseId);
    for (int i = 0; i < 19; i++) {
        bldr.addParam(".1.3.6." + (i + 1), "parm" + (i + 1));
    }
    DefaultEventConfDao eventConfDao = loadConfiguration("eventconf-wildcard/eventconf.xml");
    org.opennms.netmgt.xml.event.Event event = bldr.getEvent();
    Event eventConf = eventConfDao.findByEvent(event);
    assertNotNull("returned event configuration for eclipsed trap '" + enterpriseId + "' should not be null", eventConf);
    assertEquals("uei.opennms.org/vendor/Xerox/traps/EnterpriseDefault", eventConf.getUei());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) SyntaxToEvent(org.opennms.netmgt.model.events.snmp.SyntaxToEvent) Event(org.opennms.netmgt.xml.eventconf.Event) Test(org.junit.Test)

Example 54 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class EventconfFactoryIT method testFindByEventUeiKnown.

@Test
public void testFindByEventUeiKnown() {
    EventBuilder bldr = new EventBuilder(knownUEI1, "testFindByEventUeiKnown");
    Event eventConf = m_eventConfDao.findByEvent(bldr.getEvent());
    assertNotNull("returned event configuration for event with known UEI '" + knownUEI1 + "' should not be null", eventConf);
    assertEquals("UEI", bldr.getEvent().getUei(), eventConf.getUei());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) SyntaxToEvent(org.opennms.netmgt.model.events.snmp.SyntaxToEvent) Event(org.opennms.netmgt.xml.eventconf.Event) Test(org.junit.Test)

Example 55 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class DefaultProvisionService method updateMonitoredServiceState.

@Transactional
@Override
public OnmsMonitoredService updateMonitoredServiceState(final Integer nodeId, final String ipAddress, final String svcName) {
    final OnmsIpInterface iface = m_ipInterfaceDao.findByNodeIdAndIpAddress(nodeId, ipAddress);
    assertNotNull(iface, "could not find interface with nodeid %d and ipAddr %s", nodeId, ipAddress);
    return new UpsertTemplate<OnmsMonitoredService, MonitoredServiceDao>(m_transactionManager, m_monitoredServiceDao) {

        @Override
        protected OnmsMonitoredService query() {
            return iface.getMonitoredServiceByServiceType(svcName);
        }

        @Override
        protected OnmsMonitoredService doUpdate(OnmsMonitoredService dbObj) {
            // NMS-3906
            LOG.debug("current status of service {} on node with IP {} is {} ", dbObj.getServiceName(), dbObj.getIpAddress().getHostAddress(), dbObj.getStatus());
            switch(dbObj.getStatus()) {
                case "S":
                    LOG.debug("suspending polling for service {} on node with IP {}", dbObj.getServiceName(), dbObj.getIpAddress().getHostAddress());
                    dbObj.setStatus("F");
                    m_monitoredServiceDao.update(dbObj);
                    sendEvent(EventConstants.SUSPEND_POLLING_SERVICE_EVENT_UEI, dbObj);
                    break;
                case "R":
                    LOG.debug("resume polling for service {} on node with IP {}", dbObj.getServiceName(), dbObj.getIpAddress().getHostAddress());
                    dbObj.setStatus("A");
                    m_monitoredServiceDao.update(dbObj);
                    sendEvent(EventConstants.RESUME_POLLING_SERVICE_EVENT_UEI, dbObj);
                    break;
                case "A":
                    // we can ignore active statuses
                    break;
                default:
                    LOG.warn("Unhandled state: {}", dbObj.getStatus());
                    break;
            }
            return dbObj;
        }

        @Override
        protected OnmsMonitoredService doInsert() {
            return null;
        }

        private void sendEvent(String eventUEI, OnmsMonitoredService dbObj) {
            final EventBuilder bldr = new EventBuilder(eventUEI, "ProvisionService");
            bldr.setNodeid(dbObj.getNodeId());
            bldr.setInterface(dbObj.getIpAddress());
            bldr.setService(dbObj.getServiceName());
            m_eventForwarder.sendNow(bldr.getEvent());
        }
    }.execute();
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) MonitoredServiceDao(org.opennms.netmgt.dao.api.MonitoredServiceDao) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

EventBuilder (org.opennms.netmgt.model.events.EventBuilder)305 Test (org.junit.Test)88 Event (org.opennms.netmgt.xml.event.Event)84 Date (java.util.Date)22 OnmsNode (org.opennms.netmgt.model.OnmsNode)17 InetAddress (java.net.InetAddress)16 EventProxyException (org.opennms.netmgt.events.api.EventProxyException)15 AlarmData (org.opennms.netmgt.xml.event.AlarmData)14 EventAnticipator (org.opennms.netmgt.dao.mock.EventAnticipator)12 ServletException (javax.servlet.ServletException)9 EventHandler (org.opennms.netmgt.events.api.annotations.EventHandler)9 Parm (org.opennms.netmgt.xml.event.Parm)9 Event (org.opennms.netmgt.xml.eventconf.Event)9 File (java.io.File)8 ArrayList (java.util.ArrayList)8 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)7 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)7 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 SyntaxToEvent (org.opennms.netmgt.model.events.snmp.SyntaxToEvent)7 Transactional (org.springframework.transaction.annotation.Transactional)6