SNMPDispatcher implements NotificationDispatcher { @Override public TargetConfigurationResult validateTargetConfig(Map<String, Object> properties) { Map<String, String> stringValuesConfig = new HashMap<String, String>(properties.size()); for (Map.Entry<String, Object> propertyEntry : properties.entrySet()) { stringValuesConfig.put(propertyEntry.getKey(), propertyEntry.getValue().toString()); } try { for (String property : getSetOfDefaultNeededPropertyNames()) { getDispatchProperty(stringValuesConfig, property); } SnmpVersion snmpVersion = getSnmpVersion(stringValuesConfig); switch (snmpVersion) { case SNMPv3: getDispatchProperty(stringValuesConfig, SECURITY_USERNAME_PROPERTY); TrapSecurity securityLevel = getSecurityLevel(stringValuesConfig); switch (securityLevel) { case AUTH_PRIV: getDispatchProperty(stringValuesConfig, SECURITY_PRIV_PASSPHRASE_PROPERTY); getDispatchProperty(stringValuesConfig, SECURITY_AUTH_PASSPHRASE_PROPERTY); break; case AUTH_NOPRIV: getDispatchProperty(stringValuesConfig, SECURITY_AUTH_PASSPHRASE_PROPERTY); break; } break; case SNMPv2c: case SNMPv1: getDispatchProperty(stringValuesConfig, COMMUNITY_PROPERTY); break; } } catch (InvalidSnmpConfigurationException ex) { return TargetConfigurationResult.invalid(ex.getMessage()); } return TargetConfigurationResult.valid(); } 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; }
@Test public void testValidateAlertValidation_SNMPv1() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put(SNMPDispatcher.SUBJECT_OID_PROPERTY, "1"); properties.put(SNMPDispatcher.BODY_OID_PROPERTY, "2"); properties.put(SNMPDispatcher.PORT_PROPERTY, "162"); properties.put(SNMPDispatcher.SNMP_VERSION_PROPERTY, "SNMPv1"); properties.put(SNMPDispatcher.TRAP_OID_PROPERTY, "1.3.6.1.6.3.1.1.5.4"); properties.put(SNMPDispatcher.COMMUNITY_PROPERTY, "public"); NotificationDispatcher dispatcher = new SNMPDispatcher(DEFAULT_SNMP_PORT); TargetConfigurationResult configValidationResult = dispatcher.validateTargetConfig(properties); assertEquals(TargetConfigurationResult.Status.VALID, configValidationResult.getStatus()); }
@Test public void testValidateAlertValidation_incorrectSNMPversion() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put(SNMPDispatcher.SUBJECT_OID_PROPERTY, "1"); properties.put(SNMPDispatcher.BODY_OID_PROPERTY, "2"); properties.put(SNMPDispatcher.PORT_PROPERTY, "162"); properties.put(SNMPDispatcher.TRAP_OID_PROPERTY, "1.3.6.1.6.3.1.1.5.4"); properties.put(SNMPDispatcher.SNMP_VERSION_PROPERTY, "SNMPv4"); properties.put(SNMPDispatcher.COMMUNITY_PROPERTY, "public"); NotificationDispatcher dispatcher = new SNMPDispatcher(DEFAULT_SNMP_PORT); TargetConfigurationResult configValidationResult = dispatcher.validateTargetConfig(properties); assertEquals(TargetConfigurationResult.Status.INVALID, configValidationResult.getStatus()); }
@Test public void testValidateAlertValidation_SNMPv1_invalid() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put(SNMPDispatcher.SUBJECT_OID_PROPERTY, "1"); properties.put(SNMPDispatcher.BODY_OID_PROPERTY, "2"); properties.put(SNMPDispatcher.PORT_PROPERTY, "162"); properties.put(SNMPDispatcher.SNMP_VERSION_PROPERTY, "SNMPv1"); properties.put(SNMPDispatcher.COMMUNITY_PROPERTY, "public"); NotificationDispatcher dispatcher = new SNMPDispatcher(DEFAULT_SNMP_PORT); TargetConfigurationResult configValidationResult = dispatcher.validateTargetConfig(properties); assertEquals(TargetConfigurationResult.Status.INVALID, configValidationResult.getStatus()); }
@Test public void testValidateAlertValidation_SNMPv2c() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put(SNMPDispatcher.SUBJECT_OID_PROPERTY, "1"); properties.put(SNMPDispatcher.BODY_OID_PROPERTY, "2"); properties.put(SNMPDispatcher.PORT_PROPERTY, "162"); properties.put(SNMPDispatcher.SNMP_VERSION_PROPERTY, "SNMPv2c"); properties.put(SNMPDispatcher.TRAP_OID_PROPERTY, "1.3.6.1.6.3.1.1.5.4"); properties.put(SNMPDispatcher.COMMUNITY_PROPERTY, "public"); NotificationDispatcher dispatcher = new SNMPDispatcher(DEFAULT_SNMP_PORT); TargetConfigurationResult configValidationResult = dispatcher.validateTargetConfig(properties); assertEquals(TargetConfigurationResult.Status.VALID, configValidationResult.getStatus()); }
@Test public void testValidateAlertValidation_SNMPv2c_invalid() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put(SNMPDispatcher.SUBJECT_OID_PROPERTY, "1"); properties.put(SNMPDispatcher.BODY_OID_PROPERTY, "2"); properties.put(SNMPDispatcher.PORT_PROPERTY, "162"); properties.put(SNMPDispatcher.TRAP_OID_PROPERTY, "1.3.6.1.6.3.1.1.5.4"); properties.put(SNMPDispatcher.SNMP_VERSION_PROPERTY, "SNMPv2c"); NotificationDispatcher dispatcher = new SNMPDispatcher(DEFAULT_SNMP_PORT); TargetConfigurationResult configValidationResult = dispatcher.validateTargetConfig(properties); assertEquals(TargetConfigurationResult.Status.INVALID, configValidationResult.getStatus()); }
@Test public void testValidateAlertValidation_SNMPv3_incorrectSecurityLevel() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put(SNMPDispatcher.SUBJECT_OID_PROPERTY, "1"); properties.put(SNMPDispatcher.BODY_OID_PROPERTY, "2"); properties.put(SNMPDispatcher.PORT_PROPERTY, "162"); 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, "INCORRECT"); NotificationDispatcher dispatcher = new SNMPDispatcher(DEFAULT_SNMP_PORT); TargetConfigurationResult configValidationResult = dispatcher.validateTargetConfig(properties); assertEquals(TargetConfigurationResult.Status.INVALID, configValidationResult.getStatus()); }
@Test public void testValidateAlertValidation_SNMPv3_noAuthNoPriv() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put(SNMPDispatcher.SUBJECT_OID_PROPERTY, "1"); properties.put(SNMPDispatcher.BODY_OID_PROPERTY, "2"); properties.put(SNMPDispatcher.PORT_PROPERTY, "162"); 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_LEVEL_PROPERTY, "NOAUTH_NOPRIV"); NotificationDispatcher dispatcher = new SNMPDispatcher(DEFAULT_SNMP_PORT); TargetConfigurationResult configValidationResult = dispatcher.validateTargetConfig(properties); assertEquals(TargetConfigurationResult.Status.VALID, configValidationResult.getStatus()); }
@Test public void testValidateAlertValidation_SNMPv3_AuthNoPriv_valid() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put(SNMPDispatcher.SUBJECT_OID_PROPERTY, "1"); properties.put(SNMPDispatcher.BODY_OID_PROPERTY, "2"); properties.put(SNMPDispatcher.PORT_PROPERTY, "162"); 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_LEVEL_PROPERTY, "AUTH_NOPRIV"); NotificationDispatcher dispatcher = new SNMPDispatcher(DEFAULT_SNMP_PORT); TargetConfigurationResult configValidationResult = dispatcher.validateTargetConfig(properties); assertEquals(TargetConfigurationResult.Status.VALID, configValidationResult.getStatus()); }
@Test public void testValidateAlertValidation_SNMPv3_AuthNoPriv_invalid() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put(SNMPDispatcher.SUBJECT_OID_PROPERTY, "1"); properties.put(SNMPDispatcher.BODY_OID_PROPERTY, "2"); properties.put(SNMPDispatcher.PORT_PROPERTY, "162"); 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_LEVEL_PROPERTY, "AUTH_NOPRIV"); NotificationDispatcher dispatcher = new SNMPDispatcher(DEFAULT_SNMP_PORT); TargetConfigurationResult configValidationResult = dispatcher.validateTargetConfig(properties); assertEquals(TargetConfigurationResult.Status.INVALID, configValidationResult.getStatus()); }
@Test public void testValidateAlertValidation_SNMPv3_AuthPriv_valid() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put(SNMPDispatcher.SUBJECT_OID_PROPERTY, "1"); properties.put(SNMPDispatcher.BODY_OID_PROPERTY, "2"); properties.put(SNMPDispatcher.PORT_PROPERTY, "162"); 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_PRIV"); NotificationDispatcher dispatcher = new SNMPDispatcher(DEFAULT_SNMP_PORT); TargetConfigurationResult configValidationResult = dispatcher.validateTargetConfig(properties); assertEquals(TargetConfigurationResult.Status.VALID, configValidationResult.getStatus()); }
@Test public void testValidateAlertValidation_SNMPv3_AuthPriv_noPassphrases() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put(SNMPDispatcher.SUBJECT_OID_PROPERTY, "1"); properties.put(SNMPDispatcher.BODY_OID_PROPERTY, "2"); properties.put(SNMPDispatcher.PORT_PROPERTY, "162"); 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_LEVEL_PROPERTY, "AUTH_PRIV"); NotificationDispatcher dispatcher = new SNMPDispatcher(DEFAULT_SNMP_PORT); TargetConfigurationResult configValidationResult = dispatcher.validateTargetConfig(properties); assertEquals(TargetConfigurationResult.Status.INVALID, configValidationResult.getStatus()); }
@Test public void testValidateAlertValidation_SNMPv3_AuthPriv_onlyAuthPassphrase() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put(SNMPDispatcher.SUBJECT_OID_PROPERTY, "1"); properties.put(SNMPDispatcher.BODY_OID_PROPERTY, "2"); properties.put(SNMPDispatcher.PORT_PROPERTY, "162"); 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_LEVEL_PROPERTY, "AUTH_PRIV"); NotificationDispatcher dispatcher = new SNMPDispatcher(DEFAULT_SNMP_PORT); TargetConfigurationResult configValidationResult = dispatcher.validateTargetConfig(properties); assertEquals(TargetConfigurationResult.Status.INVALID, configValidationResult.getStatus()); }