@Test public void testDispatch_successful_v3() throws Exception { SNMPDispatcher dispatcher = new SNMPDispatcher(DEFAULT_SNMP_PORT); Notification notification = new Notification(); notification.Callback = mock(DispatchCallback.class); notification.CallbackIds = new ArrayList<>(); notification.Body = "body"; notification.Subject = "subject"; Map<String, String> properties = new HashMap<String, String>(); properties.put(SNMPDispatcher.SUBJECT_OID_PROPERTY, "1"); properties.put(SNMPDispatcher.BODY_OID_PROPERTY, "2"); properties.put(SNMPDispatcher.PORT_PROPERTY, "162"); properties.put(SNMPDispatcher.COMMUNITY_PROPERTY, "public"); properties.put(SNMPDispatcher.SNMP_VERSION_PROPERTY, "SNMPv3"); properties.put(SNMPDispatcher.TRAP_OID_PROPERTY, "1.3.6.1.6.3.1.1.5.4"); properties.put(SNMPDispatcher.SECURITY_USERNAME_PROPERTY, "USER"); properties.put(SNMPDispatcher.SECURITY_AUTH_PASSPHRASE_PROPERTY, "PASSPHRASE1"); properties.put(SNMPDispatcher.SECURITY_PRIV_PASSPHRASE_PROPERTY, "PASSPHRASE2"); properties.put(SNMPDispatcher.SECURITY_LEVEL_PROPERTY, "AUTH_NOPRIV"); notification.DispatchProperties = properties; Recipient recipient = new Recipient(); recipient.Identifier = "192.168.0.2"; notification.Recipients = Arrays.asList(recipient); dispatcher.dispatch(notification); verify(notification.Callback, never()).onFailure(notification.CallbackIds); verify(notification.Callback).onSuccess(notification.CallbackIds); }
@Override public void dispatch(Notification notification) { LOG.info("Sending SNMP trap: {}", notification.Subject); try { createTransportMapping(); snmp = new Snmp(transportMapping); SnmpVersion snmpVersion = getSnmpVersion(notification.DispatchProperties); sendTraps(notification, snmpVersion); successCallback(notification); } catch (InvalidSnmpConfigurationException ex) { LOG.error("Unable to dispatch SNMP trap with invalid configuration. " + ex.getMessage()); failureCallback(notification); } catch (Exception ex) { LOG.error("Error occurred during SNMP trap dispatching.", ex); failureCallback(notification); transportMapping = null; } }
SNMPDispatcher implements NotificationDispatcher { @Override public void dispatch(Notification notification) { LOG.info("Sending SNMP trap: {}", notification.Subject); try { createTransportMapping(); snmp = new Snmp(transportMapping); SnmpVersion snmpVersion = getSnmpVersion(notification.DispatchProperties); sendTraps(notification, snmpVersion); successCallback(notification); } catch (InvalidSnmpConfigurationException ex) { LOG.error("Unable to dispatch SNMP trap with invalid configuration. " + ex.getMessage()); failureCallback(notification); } catch (Exception ex) { LOG.error("Error occurred during SNMP trap dispatching.", ex); failureCallback(notification); transportMapping = null; } } }
SNMPDispatcher implements NotificationDispatcher { @Override public void dispatch(Notification notification) { LOG.info("Sending SNMP trap: {}", notification.Subject); try { createTransportMapping(); snmp = new Snmp(transportMapping); SnmpVersion snmpVersion = getSnmpVersion(notification.DispatchProperties); sendTraps(notification, snmpVersion); successCallback(notification); } catch (InvalidSnmpConfigurationException ex) { LOG.error("Unable to dispatch SNMP trap with invalid configuration. " + ex.getMessage()); failureCallback(notification); } catch (Exception ex) { LOG.error("Error occurred during SNMP trap dispatching.", ex); failureCallback(notification); transportMapping = null; } } SNMPDispatcher(Snmp snmp);  SNMPDispatcher();  SNMPDispatcher(Integer port); }
SNMPDispatcher implements NotificationDispatcher { @Override public void dispatch(Notification notification) { LOG.info("Sending SNMP trap: {}", notification.Subject); try { createTransportMapping(); snmp = new Snmp(transportMapping); SnmpVersion snmpVersion = getSnmpVersion(notification.DispatchProperties); sendTraps(notification, snmpVersion); successCallback(notification); } catch (InvalidSnmpConfigurationException ex) { LOG.error("Unable to dispatch SNMP trap with invalid configuration. " + ex.getMessage()); failureCallback(notification); } catch (Exception ex) { LOG.error("Error occurred during SNMP trap dispatching.", ex); failureCallback(notification); transportMapping = null; } } SNMPDispatcher(Snmp snmp);  SNMPDispatcher();  SNMPDispatcher(Integer port); @Override String getType(); @Override boolean isNotificationContentGenerationRequired(); @Override void dispatch(Notification notification); @Override TargetConfigurationResult validateTargetConfig(Map<String, Object> properties); @Override boolean isDigestSupported(); Integer getPort(); }
SNMPDispatcher implements NotificationDispatcher { @Override public void dispatch(Notification notification) { LOG.info("Sending SNMP trap: {}", notification.Subject); try { createTransportMapping(); snmp = new Snmp(transportMapping); SnmpVersion snmpVersion = getSnmpVersion(notification.DispatchProperties); sendTraps(notification, snmpVersion); successCallback(notification); } catch (InvalidSnmpConfigurationException ex) { LOG.error("Unable to dispatch SNMP trap with invalid configuration. " + ex.getMessage()); failureCallback(notification); } catch (Exception ex) { LOG.error("Error occurred during SNMP trap dispatching.", ex); failureCallback(notification); transportMapping = null; } } SNMPDispatcher(Snmp snmp);  SNMPDispatcher();  SNMPDispatcher(Integer port); @Override String getType(); @Override boolean isNotificationContentGenerationRequired(); @Override void dispatch(Notification notification); @Override TargetConfigurationResult validateTargetConfig(Map<String, Object> properties); @Override boolean isDigestSupported(); Integer getPort(); static final String BODY_OID_PROPERTY; static final String SUBJECT_OID_PROPERTY; static final String TRAP_OID_PROPERTY; static final String PORT_PROPERTY; static final String SNMP_VERSION_PROPERTY; static final String COMMUNITY_PROPERTY; static final String SECURITY_USERNAME_PROPERTY; static final String SECURITY_AUTH_PASSPHRASE_PROPERTY; static final String SECURITY_PRIV_PASSPHRASE_PROPERTY; static final String SECURITY_LEVEL_PROPERTY; }