org.snmp4j.CommandResponderEvent Java Examples
The following examples show how to use
org.snmp4j.CommandResponderEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SnmpBinding.java From openhab1-addons with Eclipse Public License 2.0 | 8 votes |
/** * Will be called whenever a {@link PDU} is received on the given port * specified in the listen() method. It extracts a {@link Variable} * according to the configured OID prefix and sends its value to the event * bus. */ @Override public void processPdu(CommandResponderEvent event) { Address addr = event.getPeerAddress(); if (addr == null) { return; } String s = addr.toString().split("/")[0]; if (s == null) { logger.error("TRAP: failed to translate address {}", addr); dispatchPdu(addr, event.getPDU()); } else { // Need to change the port to 161, which is what the bindings are configured for since // at least some SNMP devices send traps from a random port number. Otherwise the trap // won't be found as the address check will fail. It feels like there should be a better // way to do this!!! Address address = GenericAddress.parse("udp:" + s + "/161"); dispatchPdu(address, event.getPDU()); } }
Example #2
Source File: PolatisAlarmConfig.java From onos with Apache License 2.0 | 5 votes |
@Override public <T> Set<Alarm> translateAlarms(List<T> unparsedAlarms) { deviceId = handler().data().deviceId(); Set<Alarm> alarms = new HashSet<>(); for (T alarm : unparsedAlarms) { if (alarm instanceof CommandResponderEvent) { CommandResponderEvent alarmEvent = (CommandResponderEvent) alarm; PDU pdu = alarmEvent.getPDU(); if (pdu != null) { String alarmType = pdu.getVariable(SNMP_TRAP_OID).toString(); if (alarmType.equals(OPM_ALARM_OID.toString())) { String label = pdu.getVariable(ALARM_PORT_LABEL_OID).toString(); int port = pdu.getVariable(ALARM_PORT_OID).toInt(); String uniqueIdentifier = "LOS" + port; String status = pdu.getVariable(ALARM_STATUS_OID).toString(); String alarmMessage = "Loss of Service alarm " + status + " for fibre " + port; SeverityLevel alarmLevel = SeverityLevel.MAJOR; long timeRaised = 0; DefaultAlarm.Builder alarmBuilder = new DefaultAlarm.Builder( AlarmId.alarmId(deviceId, uniqueIdentifier), deviceId, alarmMessage, alarmLevel, timeRaised); if (status.equals(CLEARED)) { long now = System.currentTimeMillis(); alarmBuilder.clear().withTimeUpdated(now).withTimeCleared(now); } alarms.add(alarmBuilder.build()); } } } } return alarms; }
Example #3
Source File: SnmpAlarmProvider.java From onos with Apache License 2.0 | 5 votes |
@Override public void processPdu(CommandResponderEvent event) { try { log.debug("received trap {}", event); String[] deviceInfo = event.getPeerAddress().toString().split("/"); //TODO This should be done via device service. //searching only for Ip since the port from which the trap is sent // could be different from the one used for SNMP SnmpDevice device = controller.getDevice(new URI(deviceInfo[0])); if (device != null) { DeviceId deviceId = DeviceId.deviceId(SCHEME + COLON + deviceInfo[0] + COLON + device.getSnmpPort()); DeviceAlarmConfig alarmTranslator = getAlarmTranslator(controller.getDevice(deviceId)); if (alarmTranslator != null) { Set<Alarm> alarms = alarmTranslator.translateAlarms(ImmutableList.of(event)); providerService.updateAlarmList(deviceId, alarms); } else { log.warn("Device {} does not support alarm", device.deviceId()); } } else { log.error("Device {} does not exist in ONOS SNMP subsystem", deviceInfo[0]); } //Catching generic exception due to otherwise hidden URISyntax } catch (Exception e) { log.error("Exception while processing PDU {}", e); } }