public void testSnmpv3WithNoAuthNoPriv() throws Exception { SnmpPeerFactory.setInstance( new SnmpPeerFactory(new ByteArrayResource(getSnmpConfig().getBytes()))); SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("10.11.12.13")); assertEquals("opennmsuser1", agentConfig.getSecurityName()); assertEquals("VF:2", agentConfig.getContextName()); assertNull(agentConfig.getAuthProtocol()); assertNull(agentConfig.getPrivProtocol()); assertNull(agentConfig.getAuthPassPhrase()); assertNull(agentConfig.getPrivPassPhrase()); assertEquals(1, agentConfig.getSecurityLevel()); agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("10.11.12.14")); assertEquals("opennmsuser2", agentConfig.getSecurityName()); assertEquals("VF:3", agentConfig.getContextName()); assertEquals("", agentConfig.getAuthProtocol()); assertEquals("", agentConfig.getPrivProtocol()); assertEquals("", agentConfig.getAuthPassPhrase()); assertEquals("", agentConfig.getPrivPassPhrase()); assertEquals(1, agentConfig.getSecurityLevel()); agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(myLocalHost())); assertEquals(3, agentConfig.getSecurityLevel()); }
public void testDefaultMaxRequestSize() throws UnknownHostException { SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("10.0.0.1")); assertEquals(SnmpAgentConfig.DEFAULT_MAX_REQUEST_SIZE, agentConfig.getMaxRequestSize()); agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("10.0.0.2")); assertEquals(484, agentConfig.getMaxRequestSize()); }
public void testGetMaxRepetitions() throws UnknownHostException { SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("77.5.5.255")); assertEquals("ipmatch", agentConfig.getReadCommunity()); assertEquals(7, agentConfig.getMaxRepetitions()); agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("10.0.0.1")); assertEquals("specificv1", agentConfig.getReadCommunity()); assertEquals(2, agentConfig.getMaxRepetitions()); }
/** * This tests for ranges configured for a v2 node and community string * * @throws UnknownHostException */ public void testReversedRange() throws UnknownHostException { SnmpPeerFactory.setInstance( new SnmpPeerFactory(new ByteArrayResource(getBadRangeSnmpConfig().getBytes()))); SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("10.7.23.100")); assertNotNull(agentConfig); assertEquals(SnmpAgentConfig.VERSION2C, agentConfig.getVersion()); assertEquals("rangev2c", agentConfig.getReadCommunity()); }
/** * Tests getting the correct SNMP Peer after a configureSNMP event and merge to the running * config. * * @throws UnknownHostException */ public void testSnmpEventInfoClassWithSpecific() throws UnknownHostException { final String addr = "192.168.0.5"; EventBuilder bldr = createConfigureSnmpEventBuilder(addr, null); addCommunityStringToEvent(bldr, "abc"); SnmpEventInfo info = new SnmpEventInfo(bldr.getEvent()); SnmpPeerFactory.getInstance().define(info); SnmpAgentConfig agent = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(addr)); assertEquals(InetAddressUtils.str(agent.getAddress()), addr); assertEquals("abc", agent.getReadCommunity()); }
/** * This tests for ranges configured for v3 node and security name * * @throws UnknownHostException */ public void testGetv3ConfigInRange() throws UnknownHostException { SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("1.1.1.50")); assertNotNull(agentConfig); assertEquals(SnmpAgentConfig.VERSION3, agentConfig.getVersion()); assertEquals("opennmsRangeUser", agentConfig.getSecurityName()); }
/** * This tests getting a v1 config * * @throws UnknownHostException */ public void testGetV1Config() throws UnknownHostException { SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("10.0.0.1")); assertNotNull(agentConfig); assertTrue(agentConfig.getVersion() == SnmpAgentConfig.VERSION1); assertEquals("specificv1", agentConfig.getReadCommunity()); }
/** * This tests for a specifically defined v2c agentConfig * * @throws UnknownHostException */ public void testGetV2cConfig() throws UnknownHostException { SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("192.168.0.50")); assertNotNull(agentConfig); assertEquals(agentConfig.getVersion(), SnmpAgentConfig.VERSION2C); assertEquals("specificv2c", agentConfig.getReadCommunity()); }
public void testProxiedAgent() throws UnknownHostException { SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("10.0.0.3")); assertEquals("10.0.0.3", InetAddressUtils.str(agentConfig.getProxyFor())); assertEquals("127.0.0.1", InetAddressUtils.str(agentConfig.getAddress())); agentConfig.toString(); }
/** * This tests for ranges configured for a v2 node and community string * * @throws UnknownHostException */ public void testGetv2cInRange() throws UnknownHostException { SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("10.7.23.100")); assertNotNull(agentConfig); assertEquals(SnmpAgentConfig.VERSION2C, agentConfig.getVersion()); assertEquals("rangev2c", agentConfig.getReadCommunity()); }
@Override protected void setUp() throws Exception { setVersion(SnmpAgentConfig.VERSION2C); SnmpPeerFactory.setInstance( new SnmpPeerFactory(new ByteArrayResource(getSnmpConfig().getBytes()))); MockLogAppender.setupLogging(true); }
/* (non-Javadoc) * @see junit.framework.TestCase#setUp() */ @Override protected void setUp() throws Exception { super.setUp(); Resource rsrc = ConfigurationTestUtils.getSpringResourceForResource( this, "snmp-config-configureSnmpTest.xml"); SnmpPeerFactory.setInstance(new SnmpPeerFactory(rsrc)); }
/** * Tests getting the correct SNMP Peer after merging a new range that super sets a current range. * * @throws UnknownHostException */ public void testSnmpEventInfoClassWithRangeSuperSettingDefRanges() throws UnknownHostException { final String addr1 = "192.168.99.1"; final String addr2 = "192.168.108.254"; SnmpAgentConfig agent = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(addr1)); assertEquals(SnmpAgentConfig.VERSION1, agent.getVersion()); EventBuilder bldr = createConfigureSnmpEventBuilder(addr1, addr2); SnmpEventInfo info = new SnmpEventInfo(bldr.getEvent()); info.setCommunityString("opennmsrules"); SnmpPeerFactory.getInstance().define(info); agent = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(addr1)); assertEquals(InetAddressUtils.str(agent.getAddress()), addr1); assertEquals(SnmpAgentConfig.VERSION1, agent.getVersion()); assertEquals(m_startingDefCount, SnmpPeerFactory.getSnmpConfig().getDefinitionCount()); }
public void testGetTargetFromPatterns() throws UnknownHostException { SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("77.5.5.255")); assertEquals("ipmatch", agentConfig.getReadCommunity()); assertEquals(128, agentConfig.getMaxVarsPerPdu()); agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("77.15.80.255")); assertEquals("ipmatch", agentConfig.getReadCommunity()); assertEquals(7, agentConfig.getMaxRepetitions()); // should be default community "public" because of 4 agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("77.4.5.255")); assertEquals("public", agentConfig.getReadCommunity()); // should be default community because of 0 agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("77.6.0.255")); assertEquals("public", agentConfig.getReadCommunity()); }
/** * This test should remove the specific 192.168.0.5 from the first definition and replace it with * a range 192.168.0.5 - 192.168.0.7. * * @throws UnknownHostException */ public void testSnmpEventInfoClassWithRangeReplacingSpecific() throws UnknownHostException { final String addr1 = "192.168.0.5"; final String addr2 = "192.168.0.7"; SnmpAgentConfig agent = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(addr1)); assertEquals(SnmpAgentConfig.VERSION2C, agent.getVersion()); EventBuilder bldr = createConfigureSnmpEventBuilder(addr1, addr2); SnmpEventInfo info = new SnmpEventInfo(bldr.getEvent()); info.setVersion("v2c"); SnmpPeerFactory.getInstance().define(info); agent = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(addr1)); assertEquals(InetAddressUtils.str(agent.getAddress()), addr1); assertEquals(SnmpAgentConfig.VERSION2C, agent.getVersion()); assertEquals(m_startingDefCount, SnmpPeerFactory.getSnmpConfig().getDefinitionCount()); }
/** * This tests for context-name configured for v3 node * * @throws UnknownHostException */ public void testGetv3ConfigWithContextNameAndMore() throws UnknownHostException { SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("1.1.1.101")); assertNotNull(agentConfig); assertEquals(SnmpAgentConfig.VERSION3, agentConfig.getVersion()); assertEquals("opennmsContextUser", agentConfig.getSecurityName()); assertEquals("testContext", agentConfig.getContextName()); assertEquals("testEngineId", agentConfig.getEngineId()); assertEquals("testContextEngineId", agentConfig.getContextEngineId()); }
/** * This test should show that a specific is added to the definition and the current single * definition should become the beginning address in the adjacent range. * * @throws UnknownHostException */ public void testSplice2() throws UnknownHostException { assertEquals(3, SnmpPeerFactory.getSnmpConfig().getDefinition(3).getRangeCount()); assertEquals(1, SnmpPeerFactory.getSnmpConfig().getDefinition(3).getSpecificCount()); assertEquals("10.1.1.10", SnmpPeerFactory.getSnmpConfig().getDefinition(3).getSpecific(0)); assertEquals( "10.1.1.11", SnmpPeerFactory.getSnmpConfig().getDefinition(3).getRange(0).getBegin()); final String specificAddr = "10.1.1.7"; final EventBuilder bldr = createConfigureSnmpEventBuilder(specificAddr, null); final SnmpEventInfo info = new SnmpEventInfo(bldr.getEvent()); info.setCommunityString("splice2-test"); SnmpPeerFactory.getInstance().define(info); assertEquals(3, SnmpPeerFactory.getSnmpConfig().getDefinition(3).getRangeCount()); assertEquals(1, SnmpPeerFactory.getSnmpConfig().getDefinition(3).getSpecificCount()); assertEquals("10.1.1.7", SnmpPeerFactory.getSnmpConfig().getDefinition(3).getSpecific(0)); assertEquals( "10.1.1.10", SnmpPeerFactory.getSnmpConfig().getDefinition(3).getRange(0).getBegin()); String marshalledConfig = SnmpPeerFactory.marshallConfig(); assertNotNull(marshalledConfig); }
/** * Tests getting the correct SNMP Peer after receiving a configureSNMP event that moves a specific * from one definition into another. * * @throws UnknownHostException */ public void testSplicingSpecificsIntoRanges() throws UnknownHostException { assertEquals(3, SnmpPeerFactory.getSnmpConfig().getDefinition(2).getRangeCount()); assertEquals(6, SnmpPeerFactory.getSnmpConfig().getDefinition(2).getSpecificCount()); final String specificAddr = "10.1.1.7"; final EventBuilder bldr = createConfigureSnmpEventBuilder(specificAddr, null); final SnmpEventInfo info = new SnmpEventInfo(bldr.getEvent()); info.setCommunityString("splice-test"); info.setVersion("v2c"); SnmpPeerFactory.getInstance().define(info); assertEquals(5, SnmpPeerFactory.getSnmpConfig().getDefinition(2).getRangeCount()); assertEquals("10.1.1.10", SnmpPeerFactory.getSnmpConfig().getDefinition(2).getSpecific(0)); assertEquals(1, SnmpPeerFactory.getSnmpConfig().getDefinition(2).getSpecificCount()); assertEquals(m_startingDefCount, SnmpPeerFactory.getSnmpConfig().getDefinitionCount()); }
public void testDefaultMaxVarsPerPdu() throws UnknownHostException { SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(myLocalHost())); assertEquals(23, agentConfig.getMaxVarsPerPdu()); }
public void testConfigureDefaultMaxVarsPerPdu() throws UnknownHostException { SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("10.0.0.150")); assertEquals(55, agentConfig.getMaxVarsPerPdu()); }
public void testGetSnmpAgentConfig() throws UnknownHostException { SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(myLocalHost())); assertEquals(SnmpAgentConfig.VERSION2C, agentConfig.getVersion()); }
/** * This tests getting an SnmpAgentConfig * * @throws UnknownHostException */ public void testGetConfig() throws UnknownHostException { assertNotNull(SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getLocalHost())); }