OutageChecker(MockService svc, Event lostSvcEvent, Event regainedSvcEvent) { super(m_db, "select * from outages where nodeid = ? and ipAddr = ? and serviceId = ?"); m_svc = svc; m_lostSvcEvent = lostSvcEvent; m_lostSvcTime = m_db.convertEventTimeToTimeStamp(m_lostSvcEvent.getTime()); m_regainedSvcEvent = regainedSvcEvent; if (m_regainedSvcEvent != null) m_regainedSvcTime = m_db.convertEventTimeToTimeStamp(m_regainedSvcEvent.getTime()); }
/** * Process the received events. For each event, use the EventExpander to look up matching * eventconf entry and load info from that match, expand event parms, add event to database and * send event to appropriate listeners. */ @Override public void run() { Events events = m_eventLog.getEvents(); if (events == null || events.getEventCount() <= 0) { // no events to process return; } for (final Event event : events.getEventCollection()) { final ThreadCategory log = log(); if (log.isDebugEnabled()) { // Log the uei, source, and other important aspects final String uuid = event.getUuid(); log.debug("Event {"); log.debug(" uuid = " + (uuid != null && uuid.length() > 0 ? uuid : "<not-set>")); log.debug(" uei = " + event.getUei()); log.debug(" src = " + event.getSource()); log.debug(" iface = " + event.getInterface()); log.debug(" time = " + event.getTime()); if (event.getParmCollection().size() > 0) { log.debug(" parms {"); for (final Parm parm : event.getParmCollection()) { if ((parm.getParmName() != null) && (parm.getValue().getContent() != null)) { log.debug( " (" + parm.getParmName().trim() + ", " + parm.getValue().getContent().trim() + ")"); } } log.debug(" }"); } log.debug("}"); } for (final EventProcessor eventProcessor : m_eventProcessors) { try { eventProcessor.process(m_eventLog.getHeader(), event); } catch (SQLException e) { log.warn( "Unable to process event using processor " + eventProcessor + "; not processing with any later processors. Exception: " + e, e); break; } catch (Throwable t) { log.warn( "Unknown exception processing event with processor " + eventProcessor + "; not processing with any later processors. Exception: " + t, t); break; } } } }
/** * Create an SNMP trap, based on the content of an event derived from a TL1 autonomous message * received by Tl1d, and forward the trap to the specified address and port. The type of trap * created depends on the value of the "trapVersion" parameter. The "community" parameter * determines the SNMP community string of the resulting trap, defaulting to "public". * * @param event The event upon which the trap content should be based * @param destAddr The address to which the trap should be sent * @param destPort The port to which the trap should be sent * @param trapVersion The SNMP version ("v1" or "v2c") of the trap * @param community The SNMP community string for the trap (defaults to "public") * @throws org.opennms.netmgt.scriptd.helper.SnmpTrapHelperException if any. * @throws java.net.UnknownHostException if any. * @exception Throws SnmpTrapHelperException if the event is not of the appropriate type. * @exception Throws UnknownHostException if agent-addr resolution fails for the case of an SNMPv1 * trap * @exception Throws SnmpTrapHelperException if the event is not of the appropriate type. * @exception Throws UnknownHostException if agent-addr resolution fails for the case of an SNMPv1 * trap */ public void sendTL1AutonomousMsgTrap( Event event, String destAddr, int destPort, String trapVersion, String community) throws SnmpTrapHelperException, UnknownHostException { // Check first thing that the event is of the right type. if (!org.opennms.netmgt.EventConstants.TL1_AUTONOMOUS_MESSAGE_UEI.equals(event.getUei())) { throw new SnmpTrapHelperException( "The event must have a UEI of " + org.opennms.netmgt.EventConstants.TL1_AUTONOMOUS_MESSAGE_UEI); } // Create a TrapBuilder and bootstrap it according to trapVersion SnmpTrapBuilder trapBuilder = null; // What to do about timestamp? Hard-wiring to zero for now. long trapTimeStamp = 0; final String iface = event.getInterface(); if ("v1".equalsIgnoreCase(trapVersion)) { trapBuilder = createV1Trap( ".1.3.6.1.4.1.5813.1", // OPENNMS-MIB::openNMS-traps iface, ENTERPRISE_SPECIFIC, 2, // OPENNMS-MIB::openNMS-tl1AutonomousMessageTrap trapTimeStamp); } else if ("v2c".equalsIgnoreCase(trapVersion)) { trapBuilder = createV2Trap( ".1.3.6.1.4.1.5813.1.0.2", // OPENNMS-MIB::openNMS-tl1AutonomousMessageTrap Long.toString(trapTimeStamp)); } else { throw new SnmpTrapHelperException("The trap SNMP version must be either v1 or v2c"); } // Add all the MIB-specified varbinds addVarBinding( trapBuilder, ".1.3.6.1.4.1.5813.20.1.8.0", // OPENNMS-MIB::openNMS-event-nodeid EventConstants.TYPE_SNMP_OCTET_STRING, Long.toString(event.getNodeid())); addVarBinding( trapBuilder, ".1.3.6.1.4.1.5813.20.1.9.0", // OPENNMS-MIB::openNMS-event-time EventConstants.TYPE_SNMP_OCTET_STRING, event.getTime()); addVarBinding( trapBuilder, ".1.3.6.1.4.1.5813.20.1.10.0", // OPENNMS-MIB::openNMS-event-host EventConstants.TYPE_SNMP_OCTET_STRING, event.getHost()); addVarBinding( trapBuilder, ".1.3.6.1.4.1.5813.20.1.11.0", // OPENNMS-MIB::openNMS-event-interface EventConstants.TYPE_SNMP_OCTET_STRING, iface); addVarBinding( trapBuilder, ".1.3.6.1.4.1.5813.20.1.13.0", // OPENNMS-MIB::openNMS-event-service EventConstants.TYPE_SNMP_OCTET_STRING, event.getService()); addVarBinding( trapBuilder, ".1.3.6.1.4.1.5813.20.1.18.0", // OPENNMS-MIB::openNMS-event-severity EventConstants.TYPE_SNMP_OCTET_STRING, event.getSeverity()); addVarBinding( trapBuilder, ".1.3.6.1.4.1.5813.20.2.1.1.0", // OPENNMS-MIB::tl1amRawMessage EventConstants.TYPE_SNMP_OCTET_STRING, EventUtil.expandParms("%parm[raw-message]%", event)); addVarBinding( trapBuilder, ".1.3.6.1.4.1.5813.20.2.1.2.0", // OPENNMS-MIB::tl1amAlarmCode EventConstants.TYPE_SNMP_OCTET_STRING, EventUtil.expandParms("%parm[alarm-code]%", event)); addVarBinding( trapBuilder, ".1.3.6.1.4.1.5813.20.2.1.3.0", // OPENNMS-MIB::tl1amAutonomousTag EventConstants.TYPE_SNMP_OCTET_STRING, EventUtil.expandParms("%parm[atag]%", event)); addVarBinding( trapBuilder, ".1.3.6.1.4.1.5813.20.2.1.4.0", // OPENNMS-MIB::tl1amVerb EventConstants.TYPE_SNMP_OCTET_STRING, EventUtil.expandParms("%parm[verb]%", event)); addVarBinding( trapBuilder, ".1.3.6.1.4.1.5813.20.2.1.5.0", // OPENNMS-MIB::tl1amAutoBlock EventConstants.TYPE_SNMP_OCTET_STRING, EventUtil.expandParms("%parm[autoblock]%", event)); addVarBinding( trapBuilder, ".1.3.6.1.4.1.5813.20.2.1.6.0", // OPENNMS-MIB::tl1amAID EventConstants.TYPE_SNMP_OCTET_STRING, EventUtil.expandParms("%parm[aid]%", event)); addVarBinding( trapBuilder, ".1.3.6.1.4.1.5813.20.2.1.7.0", // OPENNMS-MIB::tl1amAdditionalParams EventConstants.TYPE_SNMP_OCTET_STRING, EventUtil.expandParms("%parm[additionalParams]%", event)); // Finally, send the trap! this.sendTrap(destAddr, destPort, community, trapBuilder); }
@Override public void process(final Header eventHeader, final Event event) throws EventProcessorException { LOG.debug("Writing event: {}", event); final OnmsEvent oe = new OnmsEvent(); oe.setEventAutoAction( (event.getAutoactionCount() > 0) ? AutoAction.format(event.getAutoaction(), EVENT_AUTOACTION_FIELD_SIZE) : null); oe.setEventCorrelation( (event.getCorrelation() != null) ? org.opennms.netmgt.dao.util.Correlation.format( event.getCorrelation(), EVENT_CORRELATION_FIELD_SIZE) : null); oe.setEventCreateTime(event.getCreationTime()); oe.setId(event.getDbid()); oe.setEventDescr(event.getDescr()); try { oe.setDistPoller(m_distPollerDao.get(event.getDistPoller())); } catch (final DataAccessException e) { throw new EventProcessorException(e); } oe.setEventHost(event.getHost()); oe.setEventForward( (event.getForwardCount() > 0) ? org.opennms.netmgt.dao.util.Forward.format( event.getForward(), EVENT_FORWARD_FIELD_SIZE) : null); oe.setIfIndex(event.getIfIndex()); oe.setIpAddr(event.getInterfaceAddress()); if (event.getLogmsg() != null) { // set log message oe.setEventLogMsg(EventDatabaseConstants.format(event.getLogmsg().getContent(), 0)); final String logdest = event.getLogmsg().getDest(); if (logdest.equals("logndisplay")) { // if 'logndisplay' set both log and display column to yes oe.setEventLog("Y"); oe.setEventDisplay("Y"); } else if (logdest.equals("logonly")) { // if 'logonly' set log column to true oe.setEventLog("Y"); oe.setEventDisplay("N"); } else if (logdest.equals("displayonly")) { // if 'displayonly' set display column to true oe.setEventLog("N"); oe.setEventDisplay("Y"); } else if (logdest.equals("suppress")) { // if 'suppress' set both log and display to false oe.setEventLog("N"); oe.setEventDisplay("N"); } } oe.setEventMouseOverText(event.getMouseovertext()); try { oe.setNode(m_nodeDao.get(event.getNodeid().intValue())); } catch (final DataAccessException e) { throw new EventProcessorException(e); } if (event.getOperactionCount() > 0) { final List<Operaction> a = new ArrayList<Operaction>(); final List<String> b = new ArrayList<String>(); for (final Operaction eoa : event.getOperactionCollection()) { a.add(eoa); b.add(eoa.getMenutext()); } oe.setEventOperAction(OperatorAction.format(a, EVENT_OPERACTION_FIELD_SIZE)); oe.setEventOperActionMenuText( EventDatabaseConstants.format(b, EVENT_OPERACTION_MENU_FIELD_SIZE)); } oe.setEventOperInstruct(event.getOperinstruct()); oe.setEventParms(EventParameterUtils.format(event)); oe.setEventPathOutage(event.getPathoutage()); try { oe.setServiceType(m_serviceTypeDao.findByName(event.getService())); } catch (final DataAccessException e) { throw new EventProcessorException(e); } oe.setSeverityLabel(event.getSeverity()); oe.setEventSnmp(SnmpInfo.format(event.getSnmp(), EVENT_SNMP_FIELD_SIZE)); oe.setEventSnmpHost( EventDatabaseConstants.format(event.getSnmphost(), EVENT_SNMPHOST_FIELD_SIZE)); oe.setEventSource(event.getSource()); oe.setEventTime(event.getTime()); if (event.getTticket() != null) { oe.setEventTTicket( EventDatabaseConstants.format(event.getTticket().getContent(), EVENT_TTICKET_FIELD_SIZE)); oe.setEventTTicketState(event.getTticket().getState().equals("on") ? 1 : 0); } oe.setEventUei(event.getUei()); m_eventDao.saveOrUpdate(oe); }
/** * {@inheritDoc} * * <p>The method that inserts the event into the database */ @Override public void process(final Header eventHeader, final Event event) throws EventProcessorException { if (!checkEventSanityAndDoWeProcess(event, "JdbcEventWriter")) { return; } LOG.debug( "JdbcEventWriter: processing {} nodeid: {} ipaddr: {} serviceid: {} time: {}", event.getUei(), event.getNodeid(), event.getInterface(), event.getService(), event.getTime()); Connection connection; try { connection = getDataSource().getConnection(); } catch (final SQLException e) { throw new EventProcessorException(e); } try { connection.setAutoCommit(false); try { insertEvent(eventHeader, event, connection); connection.commit(); } catch (final SQLException e) { LOG.warn("Error inserting event into the datastore.", e); try { connection.rollback(); } catch (final Throwable e2) { LOG.warn("Rollback of transaction failed.", e2); } throw e; } catch (final DataAccessException e) { LOG.warn("Error inserting event into the datastore.", e); try { connection.rollback(); } catch (final Throwable e2) { LOG.warn("Rollback of transaction failed.", e2); } throw e; } } catch (final DataAccessException e) { throw new EventProcessorException(e); } catch (SQLException e) { throw new EventProcessorException(e); } finally { try { connection.close(); } catch (final SQLException e) { LOG.warn("SQLException while closing database connection.", e); } } LOG.debug("EventWriter finished for : {}", event.getUei()); }
/** * {@inheritDoc} * * <p>The OpenNMS event listener runs this routine when a new event is detected. This can be run * on any event but only needs to run on uei.opennms.org/vacuumd/alarmListChanged */ @Override public void onEvent(Event event) { LOG.debug( "Qosd.onEvent: OpenNMS Event Detected by QosD. uei '{}' Dbid(): {} event.getTime(): {}", event.getUei(), event.getDbid(), event.getTime()); String s = event.getUei(); if (s == null) return; if (EventConstants.NODE_ADDED_EVENT_UEI.equals(s) || EventConstants.NODE_LABEL_CHANGED_EVENT_UEI.equals(s) || EventConstants.NODE_DELETED_EVENT_UEI.equals(s) || EventConstants.ASSET_INFO_CHANGED_EVENT_UEI.equals(s)) { try { LOG.debug("QosD.onEvent Event causing update to node list"); openNMSEventHandlerThread.updateNodeCache(); return; } catch (Exception ex) { LOG.error( "Qosd.onEvent. Problem calling openNMSEventHandlerThread.updateNodeCache(). Error:", ex); return; } } if (event.getUei().equals("uei.opennms.org/vacuumd/alarmListChanged")) { LOG.debug( "QosD.onEvent received 'uei.opennms.org/vacuumd/alarmListChanged' event; Updating alarm list"); } else { // used code from AlarmWriter.java Check value of <logmsg> attribute 'dest', if set to // "donotpersist" then simply return, the uei is not to be persisted to the database // The uei.opennms.org/vacuumd/alarmListChanged event must be set to be reised // as auto-action from vacumd-configuration.xml and is called // when vacumd updates the current ( alarm not acknowledgd and cleared ) alarm list // note alarmListChanged event may be marked as 'donotpersist' so checked first try { // this section prints out events received which are not // uei.opennms.org/vacuumd/alarmListChanged // return if a donotpersist event if (event.getLogmsg().getDest().equals("donotpersist")) { LOG.debug( "QosD.onEvent Ignoring event marked as 'doNotPersist'. Event Uei:{}", event.getUei()); return; } // AlarmData should not be null if QoSD-configuration.xml is set up only to receive raise // and not clearing alarms if (event.getAlarmData().getAlarmType() == 2) { LOG.debug( "Qosd.onEvent: uei '{}' Dbid(): {} alarm type = 2 (clearing alarm) so ignoring.", event.getUei(), event.getDbid()); return; } } catch (NullPointerException e) { LOG.error( "Qosd.onEvent: uei '{}' Dbid(): {}' problem dealing with event. Check QoSD-configuration.xml.", event.getUei(), event.getDbid()); return; } } // This forces the ossDao to update it's list on this event and call back to sendAlarms() to // send the // updated alarm list. try { LOG.debug("QosD.onEvent calling openNMSEventHandlerThread.sendAlarmList() to update list."); // ossDao.updateAlarmCacheAndSendAlarms(); openNMSEventHandlerThread.sendAlarmList(); } catch (Exception ex) { LOG.error( "Qosd.onEvent. Problem calling openNMSEventHandlerThread.sendAlarmList(). Error:", ex); } }