/** * getEventHost * * @param event a {@link org.opennms.netmgt.xml.event.Event} object. * @param connection a {@link java.sql.Connection} object. * @return a {@link java.lang.String} object. */ protected String getEventHost(final Event event) { if (event.getHost() == null) { return null; } // If the event doesn't have a node ID, we can't lookup the IP address and be sure we have the // right one since we don't know what node it is on if (!event.hasNodeid()) { return event.getHost(); } try { return getHostName(event.getNodeid().intValue(), event.getHost()); } catch (final Throwable t) { LOG.warn( "Error converting host IP \"{}\" to a hostname, storing the IP.", event.getHost(), t); return event.getHost(); } }
/** * 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); }