/** {@inheritDoc} */ @Override public InetAddress unmarshal(String ipAddr) throws Exception { return InetAddrUtils.addr(ipAddr); }
public static InetAddress getLocalHostAddress() { return addr("127.0.0.1"); }
@Override public InetAddress toInetAddress() { try { return InetAddrUtils.addr(toString()); } catch (Exception e) { return super.toInetAddress(); } }
public static SnmpAgentConfig fromMap(Map<String, String> map) { SnmpAgentConfig config = new SnmpAgentConfig(); if (map.get("address") != null) config.setAddress(InetAddrUtils.addr(map.get("address"))); if (map.get("proxyFor") != null) config.setProxyFor(InetAddrUtils.addr(map.get("proxyFor"))); if (map.get("port") != null) config.setPort(Integer.parseInt(map.get("port"))); if (map.get("timeout") != null) config.setTimeout(Integer.parseInt(map.get("timeout"))); if (map.get("retries") != null) config.setRetries(Integer.parseInt(map.get("retries"))); if (map.get("max-vars-per-pdu") != null) config.setMaxVarsPerPdu(Integer.parseInt(map.get("max-vars-per-pdu"))); if (map.get("max-repetitions") != null) config.setMaxRepetitions(Integer.parseInt(map.get("max-repetitions"))); if (map.get("max-request-size") != null) config.setMaxRequestSize(Integer.parseInt(map.get("max-request-size"))); if (map.get("version") != null) config.setVersion(Integer.parseInt(map.get("version"))); if (map.get("security-level") != null) config.setSecurityLevel(Integer.parseInt(map.get("security-level"))); if (map.get("security-name") != null) config.setSecurityName(map.get("security-name")); if (map.get("auth-passphrase") != null) config.setAuthPassPhrase(map.get("auth-passphrase")); if (map.get("auth-protocol") != null) config.setAuthProtocol(map.get("auth-protocol")); if (map.get("priv-passphrase") != null) config.setPrivPassPhrase(map.get("priv-passphrase")); if (map.get("priv-protocol") != null) config.setPrivProtocol(map.get("priv-protocol")); if (map.get("context-name") != null) config.setContextName(map.get("context-name")); if (map.get("engine-id") != null) config.setEngineId(map.get("engine-id")); if (map.get("context-engine-id") != null) config.setContextEngineId(map.get("context-engine-id")); if (map.get("enterprise-id") != null) config.setEnterpriseId(map.get("enterprise-id")); if (map.get("read-community") != null) config.setReadCommunity(map.get("read-community")); if (map.get("write-community") != null) config.setWriteCommunity(map.get("write-community")); return config; } }
return getCounter64(BigInteger.valueOf(Long.valueOf(mibVal.substring("Counter64:".length()).trim()))); } else if (mibVal.startsWith("IpAddress:")) { return getIpAddress(InetAddrUtils.addr(mibVal.substring("IpAddress:".length()).trim())); } else if (mibVal.startsWith("Hex-STRING:")) { final String trimmed = mibVal.substring("Hex-STRING:".length()).trim();
public static void sendTest(String destAddr, int destPort, String community, SnmpPduTrap pdu) throws UnknownHostException { final InetAddress agentAddress = InetAddrUtils.addr(destAddr); for (final RegistrationInfo info : s_registrations.values()) { if (destPort == info.getPort()) { info.getHandler().snmpReceivedTrap(info.getSession(), agentAddress, destPort, new SnmpOctetString(community.getBytes()), pdu); } } }
public static void sendTest(final String destAddr, final int destPort, final String community, final SnmpPduRequest pdu) throws UnknownHostException { final InetAddress agentAddress = InetAddrUtils.addr(destAddr); for (final RegistrationInfo info : s_registrations.values()) { if (destPort == info.getPort()) { info.getHandler().snmpReceivedTrap(info.getSession(), agentAddress, destPort, new SnmpOctetString(community.getBytes()), pdu); } } }
public static void sendTest(final String destAddr, final int destPort, final String community, final SnmpPduRequest pdu) throws UnknownHostException { final InetAddress agentAddress = InetAddrUtils.addr(destAddr); for (final RegistrationInfo info : s_registrations.values()) { if (destPort == info.getPort()) { info.getHandler().snmpReceivedTrap(info.getSession(), agentAddress, destPort, new SnmpOctetString(community.getBytes()), pdu); } } }
public static void sendTest(String destAddr, int destPort, String community, SnmpPduTrap pdu) throws UnknownHostException { final InetAddress agentAddress = InetAddrUtils.addr(destAddr); for (final RegistrationInfo info : s_registrations.values()) { if (destPort == info.getPort()) { info.getHandler().snmpReceivedTrap(info.getSession(), agentAddress, destPort, new SnmpOctetString(community.getBytes()), pdu); } } }
private CollectionAgent getCollectionAgent() { final InetAddress hostAddr = InetAddrUtils.addr(host); if (nodeCriteria != null) { return collectionAgentFactory.createCollectionAgentAndOverrideLocation(nodeCriteria, hostAddr, location); } else { System.out.println("NOTE: Some collectors require a database node and IP interface.\n"); final CollectionAgentDTO agent = new CollectionAgentDTO(); agent.setLocationName(location); agent.setAddress(hostAddr); agent.setStorageResourcePath(ResourcePath.fromString("")); return agent; } }
/** * Executes collector test. * * @param nodeId the node id * @param ipAddress the IP address * @param xmlSampleFileName the XML sample file name * @param parameters the parameters * @param expectedFiles the expected amount of JRB files * @throws Exception the exception */ public void executeCollectorTest(int nodeId, String ipAddress, String xmlSampleFileName, Map<String, Object> parameters, int expectedFiles) throws Exception { MockDocumentBuilder.setXmlFileName(xmlSampleFileName); CollectionAgent collectionAgent = new MockCollectionAgent(nodeId, "mynode", InetAddrUtils.addr(ipAddress)); CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(m_collector, collectionAgent, parameters); Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus()); ServiceParameters serviceParams = new ServiceParameters(new HashMap<String,Object>()); CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, createRrdRepository((String)parameters.get("collection")), false, false); collectionSet.visit(persister); Assert.assertEquals(expectedFiles, FileUtils.listFiles(new File(getSnmpRoot(), Integer.toString(nodeId)), new String[] { getRrdExtension() }, true).size()); }
/** * Sets the up. * * @throws Exception the exception */ @Before public void setUp() throws Exception { MockLogAppender.setupLogging(); initializeRrdStrategy(); initializeDocumentBuilder(); m_collectionAgent = new MockCollectionAgent(1, "mynode.local", InetAddrUtils.addr("127.0.0.1")); m_eventProxy = EasyMock.createMock(EventProxy.class); m_xmlCollectionDao = new XmlDataCollectionConfigDaoJaxb(); Resource resource = new FileSystemResource(getConfigFileName()); m_xmlCollectionDao.setConfigResource(resource); m_xmlCollectionDao.afterPropertiesSet(); EasyMock.replay(m_eventProxy); }
/** * Sets the up. * * @throws Exception the exception */ @Before public void setUp() throws Exception { MockLogAppender.setupLogging(); DefaultDataCollectionConfigDao dao = new DefaultDataCollectionConfigDao(); dao.setConfigDirectory("src/test/resources/etc/datacollection"); dao.setConfigResource(new FileSystemResource("src/test/resources/etc/datacollection-config.xml")); dao.afterPropertiesSet(); DataCollectionConfigFactory.setInstance(dao); m_rrdStrategy = new JRobinRrdStrategy(); m_resourceStorageDao = new FilesystemResourceStorageDao(); m_resourceStorageDao.setRrdDirectory(m_temporaryFolder.getRoot()); m_temporaryFolder.newFolder("snmp"); m_persisterFactory = new RrdPersisterFactory(); m_persisterFactory.setResourceStorageDao(m_resourceStorageDao); m_persisterFactory.setRrdStrategy(m_rrdStrategy); m_collectionAgent = new MockCollectionAgent(1, "mynode.local", InetAddrUtils.addr("127.0.0.1")); m_nodeDao = EasyMock.createMock(NodeDao.class); OnmsNode node = new OnmsNode(); node.setId(1); node.setLabel("mynode.local"); node.setAssetRecord(new OnmsAssetRecord()); EasyMock.expect(m_nodeDao.get(1)).andReturn(node).anyTimes(); EasyMock.replay(m_nodeDao); }
/** * Sets the up. * * @throws Exception the exception */ @Before public void setUp() throws Exception { MockLogAppender.setupLogging(); DefaultDataCollectionConfigDao dao = new DefaultDataCollectionConfigDao(); dao.setConfigDirectory("src/test/resources/etc/datacollection"); dao.setConfigResource(new FileSystemResource("src/test/resources/etc/datacollection-config.xml")); dao.afterPropertiesSet(); DataCollectionConfigFactory.setInstance(dao); m_rrdStrategy = new JRobinRrdStrategy(); m_resourceStorageDao = new FilesystemResourceStorageDao(); m_resourceStorageDao.setRrdDirectory(m_temporaryFolder.getRoot()); m_temporaryFolder.newFolder("snmp"); m_persisterFactory = new RrdPersisterFactory(); m_persisterFactory.setResourceStorageDao(m_resourceStorageDao); m_persisterFactory.setRrdStrategy(m_rrdStrategy); m_collectionAgent = new MockCollectionAgent(1, "mynode.local", InetAddrUtils.addr("127.0.0.1")); m_nodeDao = EasyMock.createMock(NodeDao.class); OnmsNode node = new OnmsNode(); node.setId(1); node.setLabel("mynode.local"); node.setAssetRecord(new OnmsAssetRecord()); EasyMock.expect(m_nodeDao.get(1)).andReturn(node).anyTimes(); EasyMock.replay(m_nodeDao); }
@Test public void testPathOutages() throws Exception { Assert.assertNotNull(m_nodeDao); Assert.assertNotNull(m_pathOutageDao); Assert.assertNotNull(m_pathOutageManager); OnmsNode node = m_nodeDao.get(1); Assert.assertNotNull(node); OnmsPathOutage pathOutage = new OnmsPathOutage(node, InetAddressUtils.addr("169.254.0.1"), "ICMP"); m_pathOutageDao.save(pathOutage); m_pathOutageDao.flush(); m_pollerConfig.setPathOutageEnabled(true); CriticalPath path = m_pathOutageManager.getCriticalPath(1); Assert.assertEquals(InetAddrUtils.addr("169.254.0.1"), path.getIpAddress()); Event nodeEvent = m_pollContext.createEvent(EventConstants.NODE_DOWN_EVENT_UEI, 1, null, null, new Date(), String.valueOf(PollStatus.SERVICE_UNAVAILABLE)); Assert.assertNotNull(nodeEvent); Assert.assertEquals("169.254.0.1", nodeEvent.getParm(EventConstants.PARM_CRITICAL_PATH_IP).getValue().getContent()); Assert.assertEquals(EventConstants.PARM_VALUE_PATHOUTAGE, nodeEvent.getParm(EventConstants.PARM_LOSTSERVICE_REASON).getValue().getContent()); } }