Search in sources :

Example 86 with EventBuilder

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

the class HibernateEventWriterIT method testWriteEventDescrWithNull.

/**
 * Tests writing nulls to postgres db and the db encoding.
 * @throws SQLException
 */
@Test
public void testWriteEventDescrWithNull() throws Exception {
    EventBuilder bldr = new EventBuilder("testUei", "testSource");
    bldr.setLogDest(HibernateEventWriter.LOG_MSG_DEST_LOG_AND_DISPLAY);
    bldr.setDescription("abc\u0000def");
    Event event = bldr.getEvent();
    assertEquals(new Integer(0), event.getDbid());
    m_eventWriter.process(bldr.getLog());
    assertTrue(event.getDbid() > 0);
    final String descr = jdbcTemplate.queryForObject("SELECT eventDescr FROM events LIMIT 1", String.class);
    assertEquals("abc%0def", descr);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Event(org.opennms.netmgt.xml.event.Event) Test(org.junit.Test)

Example 87 with EventBuilder

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

the class AlarmChangeNotificationClient method sendDbNotification.

@Override
public void sendDbNotification(DbNotification dbNotification) {
    try {
        String payload = dbNotification.getPayload();
        JSONObject newJsonObject = null;
        JSONObject oldJsonObject = null;
        try {
            JSONParser parser = new JSONParser();
            Object obj;
            obj = parser.parse(payload);
            JSONArray jsonArray = (JSONArray) obj;
            LOG.debug("payload jsonArray.toString():" + jsonArray.toString());
            newJsonObject = (JSONObject) jsonArray.get(0);
            oldJsonObject = (JSONObject) jsonArray.get(1);
            newJsonObject = jsonAlarmTimeNormaliser(newJsonObject);
            oldJsonObject = jsonAlarmTimeNormaliser(oldJsonObject);
        } catch (ParseException e1) {
            throw new RuntimeException("cannot parse notification payload to json object. payload=" + payload, e1);
        }
        if (newJsonObject.isEmpty() && (!oldJsonObject.isEmpty())) {
            // ignore alarm type 2
            if (!"2".equals(oldJsonObject.get("alarmtype").toString())) {
                if (LOG.isDebugEnabled())
                    LOG.debug("alarm deleted alarmid=" + oldJsonObject.get("alarmid"));
                EventBuilder eb = jsonAlarmToEventBuilder(oldJsonObject, new EventBuilder(AlarmChangeEventConstants.ALARM_DELETED_EVENT, EVENT_SOURCE_NAME));
                // copy in all values as json in params
                eb.addParam(AlarmChangeEventConstants.OLD_ALARM_VALUES_PARAM, oldJsonObject.toString());
                eb.addParam(AlarmChangeEventConstants.NEW_ALARM_VALUES_PARAM, newJsonObject.toString());
                sendEvent(eb.getEvent());
            }
        } else if ((!newJsonObject.isEmpty()) && oldJsonObject.isEmpty()) {
            // ignore alarm type 2
            if (!"2".equals(newJsonObject.get("alarmtype").toString())) {
                if (LOG.isDebugEnabled())
                    LOG.debug("alarm created alarmid=" + newJsonObject.get("alarmid"));
                EventBuilder eb = jsonAlarmToEventBuilder(newJsonObject, new EventBuilder(AlarmChangeEventConstants.ALARM_CREATED_EVENT, EVENT_SOURCE_NAME));
                // copy in all values as json in params
                eb.addParam(AlarmChangeEventConstants.OLD_ALARM_VALUES_PARAM, oldJsonObject.toString());
                eb.addParam(AlarmChangeEventConstants.NEW_ALARM_VALUES_PARAM, newJsonObject.toString());
                // set initial severity to new alarm severity
                if (newJsonObject.get("severity") != null) {
                    try {
                        String newseverity = newJsonObject.get("severity").toString();
                        Integer newsvty = Integer.valueOf(newseverity);
                        eb.addParam(AlarmChangeEventConstants.INITIAL_SEVERITY_PARAM, newsvty.toString());
                    } catch (Exception e) {
                        LOG.error("problem parsing initial severity for new alarm event newJsonObject=" + newJsonObject, e);
                    }
                }
                sendEvent(eb.getEvent());
            }
        } else {
            // ignore alarm type 2
            if (!"2".equals(newJsonObject.get("alarmtype").toString())) {
                // ignore event count and automation changes if these are only change in alarm
                // TODO need database trigger to also ignore these changes
                JSONObject newobj = new JSONObject(newJsonObject);
                JSONObject oldobj = new JSONObject(oldJsonObject);
                newobj.remove("lasteventtime");
                oldobj.remove("lasteventtime");
                newobj.remove("lasteventid");
                oldobj.remove("lasteventid");
                newobj.remove("counter");
                oldobj.remove("counter");
                newobj.remove("firstautomationtime");
                oldobj.remove("firstautomationtime");
                newobj.remove("lastautomationtime");
                oldobj.remove("lastautomationtime");
                if (!newobj.toString().equals(oldobj.toString())) {
                    // changes other than event count
                    // severity changed notification
                    String oldseverity = (oldJsonObject.get("severity") == null) ? null : oldJsonObject.get("severity").toString();
                    String newseverity = (newJsonObject.get("severity") == null) ? null : newJsonObject.get("severity").toString();
                    if (newseverity != null && !newseverity.equals(oldseverity)) {
                        // check if alarm cleared
                        EventBuilder eb = null;
                        if ("2".equals(newseverity)) {
                            if (LOG.isDebugEnabled())
                                LOG.debug("alarm cleared alarmid=" + oldJsonObject.get("alarmid") + " old severity=" + oldseverity + " new severity=" + newseverity);
                            eb = jsonAlarmToEventBuilder(newJsonObject, new EventBuilder(AlarmChangeEventConstants.ALARM_CLEARED_EVENT, EVENT_SOURCE_NAME));
                        } else {
                            // if just severity changed
                            if (LOG.isDebugEnabled())
                                LOG.debug("alarm severity changed alarmid=" + oldJsonObject.get("alarmid") + " old severity=" + oldseverity + " new severity=" + newseverity);
                            eb = jsonAlarmToEventBuilder(newJsonObject, new EventBuilder(AlarmChangeEventConstants.ALARM_SEVERITY_CHANGED_EVENT, EVENT_SOURCE_NAME));
                        }
                        eb.addParam(AlarmChangeEventConstants.OLDSEVERITY_PARAM, oldseverity);
                        // copy in all values as json in params
                        eb.addParam(AlarmChangeEventConstants.OLD_ALARM_VALUES_PARAM, oldJsonObject.toString());
                        eb.addParam(AlarmChangeEventConstants.NEW_ALARM_VALUES_PARAM, newJsonObject.toString());
                        sendEvent(eb.getEvent());
                    }
                    // alarm acknowledged / unacknowledged notifications
                    String oldalarmacktime = (oldJsonObject.get("alarmacktime") == null) ? null : oldJsonObject.get("alarmacktime").toString();
                    String newalarmacktime = (newJsonObject.get("alarmacktime") == null) ? null : newJsonObject.get("alarmacktime").toString();
                    if (oldalarmacktime == null && newalarmacktime != null) {
                        // alarm acknowledged notification
                        if (LOG.isDebugEnabled())
                            LOG.debug("alarm acknowleged alarmid=" + newJsonObject.get("alarmid"));
                        EventBuilder eb = jsonAlarmToEventBuilder(newJsonObject, new EventBuilder(AlarmChangeEventConstants.ALARM_ACKNOWLEDGED_EVENT, EVENT_SOURCE_NAME));
                        // copy in all values as json in params
                        eb.addParam(AlarmChangeEventConstants.OLD_ALARM_VALUES_PARAM, oldJsonObject.toString());
                        eb.addParam(AlarmChangeEventConstants.NEW_ALARM_VALUES_PARAM, newJsonObject.toString());
                        sendEvent(eb.getEvent());
                    } else {
                        if (oldalarmacktime != null && newalarmacktime == null) {
                            // alarm unacknowledged notification
                            if (LOG.isDebugEnabled())
                                LOG.debug("alarm unacknowleged alarmid=" + newJsonObject.get("alarmid"));
                            // TODO issue unacknowledged doesn't have a user because only user and time in alarm field
                            EventBuilder eb = jsonAlarmToEventBuilder(newJsonObject, new EventBuilder(AlarmChangeEventConstants.ALARM_UNACKNOWLEDGED_EVENT, EVENT_SOURCE_NAME));
                            // copy in all values as json in params
                            eb.addParam(AlarmChangeEventConstants.OLD_ALARM_VALUES_PARAM, oldJsonObject.toString());
                            eb.addParam(AlarmChangeEventConstants.NEW_ALARM_VALUES_PARAM, newJsonObject.toString());
                            sendEvent(eb.getEvent());
                        }
                    }
                    // alarm suppressed / unsuppressed notifications
                    String newsuppresseduntil = (newJsonObject.get("suppresseduntil") == null) ? null : newJsonObject.get("suppresseduntil").toString();
                    String oldsuppresseduntil = (oldJsonObject.get("suppresseduntil") == null) ? null : oldJsonObject.get("suppresseduntil").toString();
                    if (newsuppresseduntil != null && !newsuppresseduntil.equals(oldsuppresseduntil)) {
                        // alarm suppressed notification
                        if (LOG.isDebugEnabled())
                            LOG.debug("alarm suppressed alarmid=" + newJsonObject.get("alarmid"));
                        EventBuilder eb = jsonAlarmToEventBuilder(newJsonObject, new EventBuilder(AlarmChangeEventConstants.ALARM_SUPPRESSED_EVENT, EVENT_SOURCE_NAME));
                        // copy in all values as json in params
                        eb.addParam(AlarmChangeEventConstants.OLD_ALARM_VALUES_PARAM, oldJsonObject.toString());
                        eb.addParam(AlarmChangeEventConstants.NEW_ALARM_VALUES_PARAM, newJsonObject.toString());
                        sendEvent(eb.getEvent());
                    } else {
                        if (oldsuppresseduntil != null && newsuppresseduntil == null) {
                            // alarm unsuppressed notification
                            if (LOG.isDebugEnabled())
                                LOG.debug("alarm unsuppressed alarmid=" + newJsonObject.get("alarmid"));
                            // TODO issue unsuppress doesn't have a user because only user and time in alarm field
                            EventBuilder eb = jsonAlarmToEventBuilder(newJsonObject, new EventBuilder(AlarmChangeEventConstants.ALARM_UNSUPPRESSED_EVENT, EVENT_SOURCE_NAME));
                            // copy in all values as json in params
                            eb.addParam(AlarmChangeEventConstants.OLD_ALARM_VALUES_PARAM, oldJsonObject.toString());
                            eb.addParam(AlarmChangeEventConstants.NEW_ALARM_VALUES_PARAM, newJsonObject.toString());
                            sendEvent(eb.getEvent());
                        }
                    }
                    // trouble ticket state changed notification
                    String oldtticketid = (oldJsonObject.get("tticketid") == null) ? null : oldJsonObject.get("tticketid").toString();
                    String newtticketid = (newJsonObject.get("tticketid") == null) ? null : newJsonObject.get("tticketid").toString();
                    String oldtticketstate = (oldJsonObject.get("tticketstate") == null) ? null : oldJsonObject.get("tticketstate").toString();
                    String newtticketstate = (newJsonObject.get("tticketstate") == null) ? null : newJsonObject.get("tticketstate").toString();
                    if ((oldtticketid == null && newtticketid != null) || (oldtticketid != null && !newtticketid.equals(oldtticketid)) || (oldtticketstate == null && newtticketstate != null) || (oldtticketstate != null && !newtticketstate.equals(oldtticketstate))) {
                        if (LOG.isDebugEnabled())
                            LOG.debug("trouble ticket state changed for alarmid=" + oldJsonObject.get("alarmid") + " oldtticketid=" + oldtticketid + " newtticketid=" + newtticketid + " oldtticketstate=" + oldtticketstate + " newtticketstate=" + newtticketstate);
                        EventBuilder eb = jsonAlarmToEventBuilder(newJsonObject, new EventBuilder(AlarmChangeEventConstants.ALARM_TROUBLETICKET_STATE_CHANGE_EVENT, EVENT_SOURCE_NAME));
                        eb.addParam(AlarmChangeEventConstants.OLDTICKETID_PARAM, oldtticketid);
                        eb.addParam(AlarmChangeEventConstants.TTICKETID_PARAM, newtticketid);
                        eb.addParam(AlarmChangeEventConstants.OLDTTICKETSTATE_PARAM, oldtticketstate);
                        eb.addParam(AlarmChangeEventConstants.TTICKETSTATE_PARAM, newtticketstate);
                        // copy in all values as json in params
                        eb.addParam(AlarmChangeEventConstants.OLD_ALARM_VALUES_PARAM, oldJsonObject.toString());
                        eb.addParam(AlarmChangeEventConstants.NEW_ALARM_VALUES_PARAM, newJsonObject.toString());
                        sendEvent(eb.getEvent());
                    }
                    // alarm sticky note changed notification
                    String oldstickymemo = (oldJsonObject.get("stickymemo") == null) ? null : oldJsonObject.get("stickymemo").toString();
                    String newstickymemo = (newJsonObject.get("stickymemo") == null) ? null : newJsonObject.get("stickymemo").toString();
                    if ((newstickymemo != null && !newstickymemo.equals(oldstickymemo))) {
                        if (LOG.isDebugEnabled())
                            LOG.debug("Sticky memo added for alarmid=" + oldJsonObject.get("alarmid") + " newstickymemo=" + newstickymemo);
                        EventBuilder eb = jsonAlarmToEventBuilder(newJsonObject, new EventBuilder(AlarmChangeEventConstants.ALARM_STICKYMEMO_ADD_EVENT, EVENT_SOURCE_NAME));
                        eb.addParam(AlarmChangeEventConstants.STICKYMEMO_PARAM, newstickymemo);
                        // copy in all values as json in params
                        eb.addParam(AlarmChangeEventConstants.OLD_ALARM_VALUES_PARAM, oldJsonObject.toString());
                        eb.addParam(AlarmChangeEventConstants.NEW_ALARM_VALUES_PARAM, newJsonObject.toString());
                        sendEvent(eb.getEvent());
                    }
                    // send alarm changed event for any other changes not captured above
                    newobj.remove("severity");
                    oldobj.remove("severity");
                    newobj.remove("alarmacktime");
                    oldobj.remove("alarmacktime");
                    newobj.remove("alarmackuser");
                    oldobj.remove("alarmackuser");
                    newobj.remove("suppresseduntil");
                    oldobj.remove("suppresseduntil");
                    newobj.remove("suppresseduser");
                    oldobj.remove("suppresseduser");
                    newobj.remove("tticketid");
                    oldobj.remove("tticketid");
                    newobj.remove("tticketstate");
                    oldobj.remove("tticketstate");
                    newobj.remove("stickymemo");
                    oldobj.remove("stickymemo");
                    if (!newobj.toString().equals(oldobj.toString())) {
                        EventBuilder eb = jsonAlarmToEventBuilder(oldJsonObject, new EventBuilder(AlarmChangeEventConstants.ALARM_CHANGED_EVENT, EVENT_SOURCE_NAME));
                        // copy in all values as json in params
                        eb.addParam(AlarmChangeEventConstants.OLD_ALARM_VALUES_PARAM, oldJsonObject.toString());
                        eb.addParam(AlarmChangeEventConstants.NEW_ALARM_VALUES_PARAM, newJsonObject.toString());
                        sendEvent(eb.getEvent());
                    }
                }
            }
        }
    } catch (Exception e) {
        LOG.error("problem creating opennms alarm change event from database notification", e);
    }
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) ParseException(org.json.simple.parser.ParseException) ParseException(org.json.simple.parser.ParseException) EventProxyException(org.opennms.netmgt.events.api.EventProxyException)

Example 88 with EventBuilder

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

the class MemosChangeNotificationClient method sendDbNotification.

@Override
public void sendDbNotification(DbNotification dbNotification) {
    try {
        String payload = dbNotification.getPayload();
        JSONObject memoJsonObject = null;
        JSONObject alarmIdJsonObject = null;
        String alarmId = null;
        String body = null;
        String author = null;
        String reductionkey = null;
        try {
            JSONParser parser = new JSONParser();
            Object obj;
            obj = parser.parse(payload);
            JSONArray jsonArray = (JSONArray) obj;
            if (LOG.isDebugEnabled())
                LOG.debug("payload memo jsonArray.toString():" + jsonArray.toString());
            memoJsonObject = (JSONObject) jsonArray.get(0);
            memoJsonObject = jsonMemoTimeNormaliser(memoJsonObject);
            alarmIdJsonObject = (JSONObject) jsonArray.get(1);
            alarmId = (alarmIdJsonObject.get("alarmid") == null) ? null : alarmIdJsonObject.get("alarmid").toString();
            body = (memoJsonObject.get("body") == null) ? null : memoJsonObject.get("body").toString();
            author = (memoJsonObject.get("author") == null) ? null : memoJsonObject.get("author").toString();
            reductionkey = (memoJsonObject.get("reductionkey") == null) ? null : memoJsonObject.get("reductionkey").toString();
        } catch (ParseException e1) {
            throw new RuntimeException("cannot parse notification payload to json object. payload=" + payload, e1);
        }
        if (!memoJsonObject.isEmpty()) {
            // sticky note event
            if ("Memo".equals(memoJsonObject.get("type").toString())) {
                if (LOG.isDebugEnabled())
                    LOG.debug("sticky memo updated=" + memoJsonObject.get("id"));
                EventBuilder eb = new EventBuilder(AlarmChangeEventConstants.STICKY_MEMO_EVENT, EVENT_SOURCE_NAME);
                // copy in all values as json in params
                eb.addParam(AlarmChangeEventConstants.MEMO_VALUES_PARAM, memoJsonObject.toString());
                eb.addParam(AlarmChangeEventConstants.MEMO_ALARMID_PARAM, alarmId);
                eb.addParam(AlarmChangeEventConstants.MEMO_BODY_PARAM, body);
                eb.addParam(AlarmChangeEventConstants.MEMO_AUTHOR_PARAM, author);
                sendEvent(eb.getEvent());
            } else if ("ReductionKeyMemo".equals(memoJsonObject.get("type").toString())) {
                if (LOG.isDebugEnabled())
                    LOG.debug("reduction key memo updated=" + memoJsonObject.get("id"));
                EventBuilder eb = new EventBuilder(AlarmChangeEventConstants.JOURNAL_MEMO_EVENT, EVENT_SOURCE_NAME);
                // copy in all values as json in params
                eb.addParam(AlarmChangeEventConstants.MEMO_VALUES_PARAM, memoJsonObject.toString());
                eb.addParam(AlarmChangeEventConstants.MEMO_ALARMID_PARAM, alarmId);
                eb.addParam(AlarmChangeEventConstants.MEMO_BODY_PARAM, body);
                eb.addParam(AlarmChangeEventConstants.MEMO_AUTHOR_PARAM, author);
                eb.addParam(AlarmChangeEventConstants.MEMO_REDUCTIONKEY_PARAM, reductionkey);
                sendEvent(eb.getEvent());
            }
        }
    } catch (Exception e) {
        LOG.error("problem creating opennms alarm change event from database notification", e);
    }
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) ParseException(org.json.simple.parser.ParseException) ParseException(org.json.simple.parser.ParseException) EventProxyException(org.opennms.netmgt.events.api.EventProxyException)

Example 89 with EventBuilder

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

the class BsmdIT method canSendEventsOnOperationalStatusChanged.

/**
 * Verifies that the daemon generates events when the operational status
 * of a Business Service is changed.
 *
 * Also verifies that the generate events include parameters which map
 * to the business services attributes.
 *
 * @throws Exception
 */
@Test
@Transactional
public void canSendEventsOnOperationalStatusChanged() throws Exception {
    // Create a business service
    BusinessServiceEntity simpleBs = createSimpleBusinessService();
    // Start the daemon
    m_bsmd.start();
    // Expect a statusChanged event
    EventBuilder ebldr = new EventBuilder(EventConstants.BUSINESS_SERVICE_OPERATIONAL_STATUS_CHANGED_UEI, "test");
    m_eventMgr.getEventAnticipator().anticipateEvent(ebldr.getEvent());
    // Expect a serviceProblem event
    ebldr = new EventBuilder(EventConstants.BUSINESS_SERVICE_PROBLEM_UEI, "test");
    m_eventMgr.getEventAnticipator().anticipateEvent(ebldr.getEvent());
    // Create the alarm
    OnmsAlarm alarm = createAlarm();
    m_alarmDao.save(alarm);
    // Send alarm created event
    ebldr = new EventBuilder(EventConstants.ALARM_CREATED_UEI, "test");
    ebldr.addParam(EventConstants.PARM_ALARM_ID, alarm.getId());
    m_bsmd.handleAlarmLifecycleEvents(ebldr.getEvent());
    // Verify expectations
    Collection<Event> stillWaitingFor = m_eventMgr.getEventAnticipator().waitForAnticipated(5000);
    assertTrue("Expected events not forthcoming " + stillWaitingFor, stillWaitingFor.isEmpty());
    verifyParametersOnAnticipatedEventsReceived(m_eventMgr.getEventAnticipator(), simpleBs.getId());
    // Expect a statusChanged event
    ebldr = new EventBuilder(EventConstants.BUSINESS_SERVICE_OPERATIONAL_STATUS_CHANGED_UEI, "test");
    m_eventMgr.getEventAnticipator().anticipateEvent(ebldr.getEvent());
    // Expect a serviceProblemResolved event
    ebldr = new EventBuilder(EventConstants.BUSINESS_SERVICE_PROBLEM_RESOLVED_UEI, "test");
    m_eventMgr.getEventAnticipator().anticipateEvent(ebldr.getEvent());
    // Clear the alarm
    alarm.setSeverity(OnmsSeverity.CLEARED);
    // Send an alarm cleared event
    ebldr = new EventBuilder(EventConstants.ALARM_CLEARED_UEI, "test");
    ebldr.addParam(EventConstants.PARM_ALARM_ID, alarm.getId());
    m_bsmd.handleAlarmLifecycleEvents(ebldr.getEvent());
    // Verify expectations
    stillWaitingFor = m_eventMgr.getEventAnticipator().waitForAnticipated(5000);
    assertTrue("Expected events not forthcoming " + stillWaitingFor, stillWaitingFor.isEmpty());
    verifyParametersOnAnticipatedEventsReceived(m_eventMgr.getEventAnticipator(), simpleBs.getId());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Event(org.opennms.netmgt.xml.event.Event) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 90 with EventBuilder

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

the class TrapdIT method testSnmpV2cTrapWithAddressFromVarbind.

/**
 * Verifies that we can pull the agent address from the snmpTrapAddress
 * varbind in a SNMPv2 trap.
 */
@Test
public void testSnmpV2cTrapWithAddressFromVarbind() throws Exception {
    // Enable the feature (disabled by default)
    m_trapdConfig.getConfig().setUseAddressFromVarbind(true);
    String localhost = "127.0.0.1";
    InetAddress remoteAddr = InetAddress.getByName("10.255.1.1");
    SnmpObjId enterpriseId = SnmpObjId.get(".1.3.6.1.4.1.5813");
    SnmpObjId trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(1));
    SnmpTrapBuilder pdu = SnmpUtils.getV2TrapBuilder();
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), SnmpUtils.getValueFactory().getTimeTicks(0));
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), SnmpUtils.getValueFactory().getObjectId(trapOID));
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), SnmpUtils.getValueFactory().getObjectId(enterpriseId));
    // The varbind with the address
    pdu.addVarBind(TrapUtils.SNMP_TRAP_ADDRESS_OID, SnmpUtils.getValueFactory().getIpAddress(InetAddress.getByName("10.255.1.1")));
    EventBuilder defaultTrapBuilder = new EventBuilder("uei.opennms.org/default/trap", "trapd");
    defaultTrapBuilder.setInterface(remoteAddr);
    defaultTrapBuilder.setSnmpVersion("v2c");
    m_mockEventIpcManager.getEventAnticipator().anticipateEvent(defaultTrapBuilder.getEvent());
    EventBuilder newSuspectBuilder = new EventBuilder(EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI, "trapd");
    // The address in the newSuspect event should match the one specified in the varbind
    newSuspectBuilder.setInterface(remoteAddr);
    m_mockEventIpcManager.getEventAnticipator().anticipateEvent(newSuspectBuilder.getEvent());
    pdu.send(localhost, m_trapdConfig.getSnmpTrapPort(), "public");
    // Allow time for Trapd and Eventd to do their magic
    Thread.sleep(5000);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) InetAddress(java.net.InetAddress) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder) Test(org.junit.Test)

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