/** * Ensures that the given Event has a node id * * @param e * the event * @throws org.opennms.netmgt.capsd.InsufficientInformationException * if a node id is not available */ static public void checkNodeId(Event e) throws InsufficientInformationException { if (e == null) { throw new NullPointerException("e is null"); } else if (!e.hasNodeid()) { throw new InsufficientInformationException("nodeid for event is unavailable"); } }
@Override public String getValue(String parm, String parsedParm, Event event, EventUtil eventUtil) { if (event.hasNodeid()) { try { String foreignSource = eventUtil.getForeignSource(event.getNodeid()); if (foreignSource != null) { return WebSecurityUtils.sanitizeString(foreignSource); } } catch (SQLException ex) { // do nothing LoggerFactory.getLogger(getClass()).info("ForeignSource unavailable for node with id:", event.getNodeid(), ex); } } return ""; }
@Override public String getValue(String parm, String parsedParm, Event event, EventUtil eventUtil) { String nodeLabel = null; if (event.hasNodeid()) { try { nodeLabel = eventUtil.getNodeLabel(event.getNodeid()); } catch (SQLException e) { // do nothing LoggerFactory.getLogger(getClass()).info("Node Label unavailable for node with id: {}", event.getNodeid(), e); } } if (nodeLabel != null) { return WebSecurityUtils.sanitizeString(nodeLabel); } else { return "Unknown"; } }
@Override public String getValue(String parm, String parsedParm, Event event, EventUtil eventUtil) { if (event.hasNodeid()) { try { String foreignId = eventUtil.getForeignId(event.getNodeid()); if (foreignId != null) { return WebSecurityUtils.sanitizeString(foreignId); } } catch (SQLException ex) { // do nothing LoggerFactory.getLogger(getClass()).info("ForeignId unavailable for node with id:", event.getNodeid(), ex); } } return ""; }
@Override public String getValue(String parm, String parsedParm, Event event, EventUtil eventUtil) { if (event.hasNodeid()) { try { String foreignSource = eventUtil.getForeignSource(event.getNodeid()); if (foreignSource != null) { return WebSecurityUtils.sanitizeString(foreignSource); } } catch (SQLException ex) { // do nothing LoggerFactory.getLogger(getClass()).info("ForeignSource unavailable for node with id:", event.getNodeid(), ex); } } return ""; }
/** * <p>handleRancidDownLoadSuccess</p> * * @param e a {@link org.opennms.netmgt.xml.event.Event} object. */ @EventHandler(uei = EventConstants.RANCID_DOWNLOAD_SUCCESS_UEI) public void handleRancidDownLoadSuccess(Event e) { LOG.debug("handleRancidDownLoadSuccess: get Event uei/id: {} / {}", e.getDbid(), e.getUei()); if (e.hasNodeid() ) { int nodeId = Long.valueOf(e.getNodeid()).intValue(); if (m_onmsNodeRancidNodeMap.containsKey(Integer.valueOf(nodeId))) { updateRancidNodeState(nodeId, false); } else { LOG.warn("node does not exist with nodeid: {}", e.getNodeid()); } } }
@Override public String getValue(String parm, String parsedParm, Event event, EventUtil eventUtil) { if (event.hasNodeid()) { try { String foreignId = eventUtil.getForeignId(event.getNodeid()); if (foreignId != null) { return WebSecurityUtils.sanitizeString(foreignId); } } catch (SQLException ex) { // do nothing LoggerFactory.getLogger(getClass()).info("ForeignId unavailable for node with id:", event.getNodeid(), ex); } } return ""; }
@Override public String getValue(String parm, String parsedParm, Event event, EventUtil eventUtil) { String nodeLabel = null; if (event.hasNodeid()) { try { nodeLabel = eventUtil.getNodeLabel(event.getNodeid()); } catch (SQLException e) { // do nothing LoggerFactory.getLogger(getClass()).info("Node Label unavailable for node with id: {}", event.getNodeid(), e); } } if (nodeLabel != null) { return WebSecurityUtils.sanitizeString(nodeLabel); } else { return "Unknown"; } }
@Override public String getValue(String parm, String parsedParm, Event event, EventUtil eventUtil) { String nodeLocation = null; if (event.hasNodeid()) { try { nodeLocation = eventUtil.getNodeLocation(event.getNodeid()); } catch (SQLException e) { // do nothing LoggerFactory.getLogger(getClass()).info("Node Location unavailable for node with id: {}", event.getNodeid(), e); } } if (nodeLocation != null) { return WebSecurityUtils.sanitizeString(nodeLocation); } else { return "Unknown"; } }
/** * <p>handleRancidDownLoadFailure</p> * * @param e a {@link org.opennms.netmgt.xml.event.Event} object. */ @EventHandler(uei = EventConstants.RANCID_DOWNLOAD_FAILURE_UEI) public void handleRancidDownLoadFailure(Event e) { LOG.debug("handleRancidDownLoadFailure: get Event uei/id: {} / {}", e.getDbid(), e.getUei()); if (e.hasNodeid()) { int nodeId = Long.valueOf(e.getNodeid()).intValue(); if (m_onmsNodeRancidNodeMap.containsKey(Integer.valueOf(nodeId))) { updateRancidNodeState(nodeId, false); } else { LOG.warn("node does not exist with nodeid: {}", e.getNodeid()); } } }
/** * <p>handleRancidDownLoadFailure</p> * * @param e a {@link org.opennms.netmgt.xml.event.Event} object. */ @EventHandler(uei = EventConstants.RANCID_DOWNLOAD_FAILURE_UEI) public void handleRancidDownLoadFailure(Event e) { LOG.debug("handleRancidDownLoadFailure: get Event uei/id: {} / {}", e.getDbid(), e.getUei()); if (e.hasNodeid()) { int nodeId = Long.valueOf(e.getNodeid()).intValue(); if (m_onmsNodeRancidNodeMap.containsKey(Integer.valueOf(nodeId))) { updateRancidNodeState(nodeId, false); } else { LOG.warn("node does not exist with nodeid: {}", e.getNodeid()); } } }
@Override public String getValue(String parm, String parsedParm, Event event, EventUtil eventUtil) { String nodeLocation = null; if (event.hasNodeid()) { try { nodeLocation = eventUtil.getNodeLocation(event.getNodeid()); } catch (SQLException e) { // do nothing LoggerFactory.getLogger(getClass()).info("Node Location unavailable for node with id: {}", event.getNodeid(), e); } } if (nodeLocation != null) { return WebSecurityUtils.sanitizeString(nodeLocation); } else { return "Unknown"; } }
/** * <p>handleRancidDownLoadSuccess</p> * * @param e a {@link org.opennms.netmgt.xml.event.Event} object. */ @EventHandler(uei = EventConstants.RANCID_DOWNLOAD_SUCCESS_UEI) public void handleRancidDownLoadSuccess(Event e) { LOG.debug("handleRancidDownLoadSuccess: get Event uei/id: {} / {}", e.getDbid(), e.getUei()); if (e.hasNodeid() ) { int nodeId = Long.valueOf(e.getNodeid()).intValue(); if (m_onmsNodeRancidNodeMap.containsKey(Integer.valueOf(nodeId))) { updateRancidNodeState(nodeId, false); } else { LOG.warn("node does not exist with nodeid: {}", e.getNodeid()); } } }
String nodeID = event.hasNodeid() ? String.valueOf(event.getNodeid()) : null; String ipAddr = event.getInterface(); String service = event.getService();
@Override public void handleMessage(TrapLogDTO messageLog) { try (Logging.MDCCloseable mdc = Logging.withPrefixCloseable(Trapd.LOG4J_CATEGORY)) { final Log eventLog = toLog(messageLog); eventForwarder.sendNowSync(eventLog); // If configured, also send events for new suspects if (config.getNewSuspectOnTrap()) { eventLog.getEvents().getEventCollection().stream() .filter(e -> !e.hasNodeid()) .forEach(e -> { sendNewSuspectEvent(e.getInterface(), e.getDistPoller()); LOG.debug("Sent newSuspectEvent for interface {}", e.getInterface()); }); } } }
@Override public void handleMessage(TrapLogDTO messageLog) { try (Logging.MDCCloseable mdc = Logging.withPrefixCloseable(Trapd.LOG4J_CATEGORY)) { final Log eventLog = toLog(messageLog); eventForwarder.sendNowSync(eventLog); // If configured, also send events for new suspects if (config.getNewSuspectOnTrap()) { eventLog.getEvents().getEventCollection().stream() .filter(e -> !e.hasNodeid()) .forEach(e -> { sendNewSuspectEvent(e.getInterface(), e.getDistPoller()); LOG.debug("Sent newSuspectEvent for interface {}", e.getInterface()); }); } } }
/** * <p>getEventHost</p> * * @param event a {@link org.opennms.netmgt.xml.event.Event} object. * @return a {@link java.lang.String} object. */ @Override public 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(); } }
/** * <p>getEventHost</p> * * @param event a {@link org.opennms.netmgt.xml.event.Event} object. * @return a {@link java.lang.String} object. */ @Override public 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(); } }
/** * */ protected Map<String, String> buildParameterMap(Notification notification, Event event, int noticeId) { Map<String, String> paramMap = new HashMap<String, String>(); NotificationManager.addNotificationParams(paramMap, notification); // expand the event parameters for the messages // call the notif expansion method before the event expansion because // event expansion will // throw away any expansion strings it doesn't recognize! paramMap.put("noticeid", Integer.toString(noticeId)); // Replace the %noticeid% param String textMessage = NotificationManager.expandNotifParms((nullSafeTextMsg(notification)), paramMap); String numericMessage = NotificationManager.expandNotifParms((nullSafeNumerMsg(notification, noticeId)), paramMap); String subjectLine = NotificationManager.expandNotifParms((nullSafeSubj(notification, noticeId)), paramMap); Map<String, Map<String, String>> decodeMap = getVarbindsDecodeMap(event.getUei()); nullSafeExpandedPut(NotificationManager.PARAM_TEXT_MSG, textMessage, event, paramMap, decodeMap); nullSafeExpandedPut(NotificationManager.PARAM_NUM_MSG, numericMessage, event, paramMap, decodeMap); nullSafeExpandedPut(NotificationManager.PARAM_SUBJECT, subjectLine, event, paramMap, decodeMap); paramMap.put(NotificationManager.PARAM_NODE, event.hasNodeid() ? String.valueOf(event.getNodeid()) : ""); paramMap.put(NotificationManager.PARAM_INTERFACE, event.getInterface()); paramMap.put(NotificationManager.PARAM_SERVICE, event.getService()); paramMap.put("eventID", String.valueOf(event.getDbid())); paramMap.put("eventUEI", event.getUei()); m_eventUtil.expandMapValues(paramMap, event); return Collections.unmodifiableMap(paramMap); }
.filter(e -> !e.hasNodeid()) .forEach(e -> { LOG.trace("Syslogd: Found a new suspect {}", e.getInterface());