@Override public SnmpAgentConfig call() throws Exception { return SnmpPeerFactory.getInstance().getAgentConfig(addr, location); } });
@Override public Map<String, Object> getRuntimeAttributes(MonitoredService svc, Map<String, Object> parameters) { try { SnmpPeerFactory.init(); } catch (IOException e) { LOG.error("SnmpPeerFactory initialization failed.", e); } return ImmutableMap.of("agent", SnmpPeerFactory.getInstance().getAgentConfig(svc.getAddress(), svc.getNodeLocation())); }
public static synchronized void init() throws IOException { if (!s_loaded.get()) { final File cfgFile = getFile(); LOG.debug("init: config file path: {}", cfgFile.getPath()); final FileSystemResource resource = new FileSystemResource(cfgFile); s_singleton = new SnmpPeerFactory(resource); s_loaded.set(true); } }
@Override public void run() { SnmpPeerFactory.getInstance().define(eventInfo); m_dirty = true; } });
@Override public Void call() throws Exception { if (m_dirty) { LOG.debug("SnmpPeerFactory has been updated. Persisting to disk."); SnmpPeerFactory.getInstance().saveCurrent(); m_dirty = false; } return null; } }
/** {@inheritDoc} */ public SnmpAgentConfig getAgentConfig(final InetAddress agentAddress) { return getAgentConfig(agentAddress, null, VERSION_UNSPECIFIED); }
iface = ifaces.iterator().next(); SnmpPeerFactory.setInstance(m_snmpPeerFactory); m_agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.getLocalHostAddress());
/** * Verifies that the SNMP agent configuration is retrieved using * the location name that is associated with the interface/node. */ @Test public void canGetLocationAwareAgentConfig() { // Mock the peer factory SnmpPeerFactory snmpPeerFactory = mock(SnmpPeerFactory.class); SnmpPeerFactory.setInstance(snmpPeerFactory); // Mock the other arguments required to create a DefaultCollectionAgent Integer ifaceId = 1; IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class); PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class); OnmsIpInterface ipIface = mock(OnmsIpInterface.class, RETURNS_DEEP_STUBS); when(ifaceDao.load(ifaceId)).thenReturn(ipIface); when(ipIface.getNode().getLocation().getLocationName()).thenReturn("Ocracoke"); // Retrieve the agent configuration SnmpCollectionAgent agent = DefaultSnmpCollectionAgent.create(ifaceId, ifaceDao, transMgr); agent.getAgentConfig(); // Verify verify(snmpPeerFactory, times(1)).getAgentConfig(any(), eq("Ocracoke")); }
/** * This method is responsible for handling configureSNMP events. * * @param event * The event to process. */ private void handleConfigureSNMP(final Event event) { LOG.debug("configureSNMPHandler: processing configure SNMP event...", event); SnmpEventInfo info = null; try { info = new SnmpEventInfo(event); if (StringUtils.isBlank(info.getFirstIPAddress())) { LOG.error("configureSNMPHandler: event contained invalid firstIpAddress. {}", event); return; } LOG.debug("configureSNMPHandler: processing configure SNMP event: {}", info); SnmpPeerFactory.getInstance().define(info); SnmpPeerFactory.getInstance().saveCurrent(); LOG.debug("configureSNMPHandler: process complete. {}", info); } catch (Throwable e) { LOG.error("configureSNMPHandler: ",e); } }
private void initSnmpPeerFactory() { try { SnmpPeerFactory.init(); } catch (IOException e) { LOG.error("initSnmpPeerFactory: Failed to load SNMP configuration", e); throw new UndeclaredThrowableException(e); } }
private void initialize() throws IOException, Exception { System.setProperty("opennms.home", ConfigurationTestUtils.getDaemonEtcDirectory().getParentFile().getAbsolutePath()); DatabaseSchemaConfigFactory.init(); InputStream stream = null; stream = getInputStreamForFile("/org/opennms/netmgt/config/snmp-config.xml"); SnmpPeerFactory.setInstance(new SnmpPeerFactory(new InputStreamResource(stream))); stream.close(); stream = getInputStreamForFile("/org/opennms/netmgt/config/datacollection-config.xml"); DefaultDataCollectionConfigDao dataCollectionDao = new DefaultDataCollectionConfigDao(); dataCollectionDao.setConfigResource(new InputStreamResource(stream)); dataCollectionDao.afterPropertiesSet(); DataCollectionConfigFactory.setInstance(dataCollectionDao); stream.close(); stream = getInputStreamForFile("/org/opennms/netmgt/config/collectd-testdata.xml"); try { new CollectdConfigFactory(stream); } finally { stream.close(); } } }
public SnmpAgentConfig getAgentConfig(final InetAddress agentInetAddress, final int requestedSnmpVersion) { return getAgentConfig(agentInetAddress, null, requestedSnmpVersion); }
SnmpPeerFactory.setInstance(m_snmpPeerFactory); m_agentConfig = m_snmpPeerFactory.getAgentConfig(InetAddressUtils.addr(TEST_HOST_ADDRESS));
/** * Load the config from the default config file and create the singleton instance of this factory. * * @exception java.io.IOException Thrown if the specified config file cannot be read */ public static synchronized SnmpPeerFactory getInstance() { if (!s_loaded.get()) { try { init(); } catch (final IOException e) { LOG.error("Failed to initialize SnmpPeerFactory instance!", e); } } return s_singleton; }
SnmpPeerFactory.setInstance(new SnmpPeerFactory(new ByteArrayResource(getSnmpConfig().getBytes())));
/** * <p>getAgentConfig</p> * * @return a {@link org.opennms.netmgt.snmp.SnmpAgentConfig} object. */ @Override public SnmpAgentConfig getAgentConfig() { return SnmpPeerFactory.getInstance().getAgentConfig(getInetAddress(), getLocationName()); }
public SnmpAgentConfig getAgentConfig(final InetAddress agentAddress, String location) { return getAgentConfig(agentAddress, location, VERSION_UNSPECIFIED); }
/** * <P> * Initialize the service monitor. * </P> * * @exception RuntimeException * Thrown if an unrecoverable error occurs that prevents the * plug-in from functioning. */ protected void initialize() { // Initialize the SnmpPeerFactory // try { SnmpPeerFactory.init(); } catch (UnknownHostException ex) { throw new UndeclaredThrowableException(ex); } catch (IOException ex) { throw new UndeclaredThrowableException(ex); } }
@Override public SnmpAgentConfig getAgentConfig() { return SnmpPeerFactory.getInstance().getAgentConfig(getAddress(), getLocationName()); }
@Override public SnmpAgentConfig getAgentConfig(final InetAddress address, String location) { final SnmpAgentConfigProxyMapper mapper = SnmpAgentConfigProxyMapper.getInstance(); final SnmpAgentAddress agentAddress = mapper.getAddress(address); final String addressString = str(address); if (agentAddress == null) { LOG.debug( "No agent address mapping found for {}! Try adding a @JUnitSnmpAgent(host=\"{}\", resource=\"...\" entry...", addressString, addressString); return super.getAgentConfig(address, location); } final SnmpAgentConfig config = new SnmpAgentConfig(agentAddress.getAddress()); config.setProxyFor(address); config.setPort(agentAddress.getPort()); LOG.debug("proxying {} -> {}", addressString, agentAddress); return config; }