@Before public void setup() throws Exception { SnmpPeerFactory.setInstance(m_snmpPeerFactory); localhost = InetAddress.getByName("127.0.0.1"); snmpAgentConfig = SnmpPeerFactory.getInstance().getAgentConfig(localhost); collectionJob = new DefaultCollectionJob(); collectionJob.setProtocolConfiguration(snmpAgentConfig.toProtocolConfigString()); destinations = new HashSet<String>(); destinations.add("test"); }
/* (non-Javadoc) * @see org.opennms.netmgt.collectd.ServiceCollector#initialize(java.util.Map) */ @Override public void initialize(Map<String, String> parameters) throws CollectionInitializationException { LOG.debug("initialize: initializing TCA collector"); // Initialize SNMP Factory try { SnmpPeerFactory.init(); } catch (IOException e) { LOG.error("initSnmpPeerFactory: Failed to load SNMP configuration: {}", e, e); throw new UndeclaredThrowableException(e); } // Retrieve the DAO for our configuration file. if (m_configDao == null) m_configDao = BeanUtils.getBean( "daoContext", "tcaDataCollectionConfigDao", TcaDataCollectionConfigDao.class); // If the RRD file repository directory does NOT already exist, create it. LOG.debug("initialize: Initializing RRD repo from XmlCollector..."); File f = new File(m_configDao.getConfig().getRrdRepository()); if (!f.isDirectory()) { if (!f.mkdirs()) { throw new CollectionInitializationException( "Unable to create RRD file repository. Path doesn't already exist and could not make directory: " + m_configDao.getConfig().getRrdRepository()); } } }
@Before public void setUp() throws InterruptedException, UnknownHostException { SnmpPeerFactory.setInstance(m_snmpPeerFactory); final DefaultEndPointConfigurationDao dao = new DefaultEndPointConfigurationDao(); dao.setConfigResource(new ClassPathResource("/testDWO-configuration.xml")); dao.afterPropertiesSet(); m_configDao = dao; }
/** * {@inheritDoc} * * <p>Returns true if the protocol defined by this plugin is supported. If the protocol is not * supported then a false value is returned to the caller. */ @Override public boolean isProtocolSupported(InetAddress address) { try { SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(address); return (getValue(agentConfig, DEFAULT_OID) != null); } catch (Throwable t) { throw new UndeclaredThrowableException(t); } }
public SnmpCollection createCollection(int nodeid, final InetAddress ipaddr) { SnmpCollection coll = null; try { coll = new SnmpCollection(this, nodeid, SnmpPeerFactory.getInstance().getAgentConfig(ipaddr)); } catch (final Throwable t) { LogUtils.errorf( this, t, "getSnmpCollection: Failed to load snmpcollection parameter from SNMP configuration file"); } return coll; }
private SnmpAgentConfig getAgentConfig(InetAddress ipaddr) { // Retrieve this interface's SNMP peer object SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(ipaddr); if (agentConfig == null) { throw new IllegalStateException( "SnmpAgentConfig object not available for interface " + ipaddr); } agentConfig.hashCode(); // Set timeout and retries on SNMP peer object agentConfig.setTimeout( ParameterMap.getKeyedInteger(m_parameters, "timeout", agentConfig.getTimeout())); agentConfig.setRetries( ParameterMap.getKeyedInteger( m_parameters, "retry", ParameterMap.getKeyedInteger(m_parameters, "retries", agentConfig.getRetries()))); agentConfig.setPort(ParameterMap.getKeyedInteger(m_parameters, "port", agentConfig.getPort())); return agentConfig; }
protected void setUp() throws Exception { super.setUp(); MockUtil.println("------------ Begin Test " + this + " --------------------------"); MockLogAppender.setupLogging(); if (m_runSupers) { createMockNetwork(); populateDatabase(); DataSourceFactory.setInstance(m_db); SnmpPeerFactory.setInstance( new SnmpPeerFactory(new ByteArrayResource(getSnmpConfig().getBytes()))); if (isStartEventd()) { m_eventdIpcMgr = new EventIpcManagerDefaultImpl(); JdbcEventdServiceManager eventdServiceManager = new JdbcEventdServiceManager(); eventdServiceManager.setDataSource(m_db); eventdServiceManager.afterPropertiesSet(); /* * Make sure we specify a full resource path since "this" is * the unit test class, which is most likely in another package. */ File configFile = ConfigurationTestUtils.getFileForResource( this, "/org/opennms/netmgt/mock/eventconf.xml"); DefaultEventConfDao eventConfDao = new DefaultEventConfDao(); eventConfDao.setConfigResource(new FileSystemResource(configFile)); eventConfDao.afterPropertiesSet(); EventconfFactory.setInstance(eventConfDao); EventExpander eventExpander = new EventExpander(); eventExpander.setEventConfDao(eventConfDao); eventExpander.afterPropertiesSet(); JdbcEventWriter jdbcEventWriter = new JdbcEventWriter(); jdbcEventWriter.setEventdServiceManager(eventdServiceManager); jdbcEventWriter.setDataSource(m_db); jdbcEventWriter.setGetNextIdString( "select nextVal('eventsNxtId')"); // for HSQL: "SELECT max(eventId)+1 from events" jdbcEventWriter.afterPropertiesSet(); EventIpcBroadcastProcessor eventIpcBroadcastProcessor = new EventIpcBroadcastProcessor(); eventIpcBroadcastProcessor.setEventIpcBroadcaster(m_eventdIpcMgr); eventIpcBroadcastProcessor.afterPropertiesSet(); List<EventProcessor> eventProcessors = new ArrayList<EventProcessor>(3); eventProcessors.add(eventExpander); eventProcessors.add(jdbcEventWriter); eventProcessors.add(eventIpcBroadcastProcessor); DefaultEventHandlerImpl eventHandler = new DefaultEventHandlerImpl(); eventHandler.setEventProcessors(eventProcessors); eventHandler.afterPropertiesSet(); m_eventdIpcMgr.setHandlerPoolSize(5); m_eventdIpcMgr.setEventHandler(eventHandler); m_eventdIpcMgr.afterPropertiesSet(); m_eventProxy = m_eventdIpcMgr; EventIpcManagerFactory.setIpcManager(m_eventdIpcMgr); EventIpcManagerEventHandlerProxy proxy = new EventIpcManagerEventHandlerProxy(); proxy.setEventIpcManager(m_eventdIpcMgr); proxy.afterPropertiesSet(); List<EventHandler> eventHandlers = new ArrayList<EventHandler>(1); eventHandlers.add(proxy); TcpEventReceiver tcpEventReceiver = new TcpEventReceiver(); tcpEventReceiver.setPort(5837); tcpEventReceiver.setEventHandlers(eventHandlers); UdpEventReceiver udpEventReceiver = new UdpEventReceiver(); udpEventReceiver.setPort(5837); tcpEventReceiver.setEventHandlers(eventHandlers); List<EventReceiver> eventReceivers = new ArrayList<EventReceiver>(2); eventReceivers.add(tcpEventReceiver); eventReceivers.add(udpEventReceiver); m_eventd = new Eventd(); m_eventd.setEventdServiceManager(eventdServiceManager); m_eventd.setEventReceivers(eventReceivers); m_eventd.setReceiver(new BroadcastEventProcessor(m_eventdIpcMgr, eventConfDao)); m_eventd.init(); m_eventd.start(); } } m_transMgr = new DataSourceTransactionManager(DataSourceFactory.getInstance()); }
/** * {@inheritDoc} * * <p>Returns true if the protocol defined by this plugin is supported. If the protocol is not * supported then a false value is returned to the caller. The qualifier map passed to the method * is used by the plugin to return additional information by key-name. These key-value pairs can * be added to service events if needed. */ @Override public boolean isProtocolSupported(InetAddress address, Map<String, Object> qualifiers) { try { String oid = ParameterMap.getKeyedString(qualifiers, "vbname", DEFAULT_OID); SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(address); String expectedValue = null; String isTable = null; if (qualifiers != null) { // "port" parm // if (qualifiers.get("port") != null) { int port = ParameterMap.getKeyedInteger(qualifiers, "port", agentConfig.getPort()); agentConfig.setPort(port); } // "timeout" parm // if (qualifiers.get("timeout") != null) { int timeout = ParameterMap.getKeyedInteger(qualifiers, "timeout", agentConfig.getTimeout()); agentConfig.setTimeout(timeout); } // "retry" parm // if (qualifiers.get("retry") != null) { int retry = ParameterMap.getKeyedInteger(qualifiers, "retry", agentConfig.getRetries()); agentConfig.setRetries(retry); } // "force version" parm // if (qualifiers.get("force version") != null) { String version = (String) qualifiers.get("force version"); if (version.equalsIgnoreCase("snmpv1")) agentConfig.setVersion(SnmpAgentConfig.VERSION1); else if (version.equalsIgnoreCase("snmpv2") || version.equalsIgnoreCase("snmpv2c")) agentConfig.setVersion(SnmpAgentConfig.VERSION2C); // TODO: make sure JoeSnmpStrategy correctly handles this. else if (version.equalsIgnoreCase("snmpv3")) agentConfig.setVersion(SnmpAgentConfig.VERSION3); } // "vbvalue" parm // if (qualifiers.get("vbvalue") != null) { expectedValue = (String) qualifiers.get("vbvalue"); } if (qualifiers.get("table") != null) { isTable = (String) qualifiers.get("table"); } } if (isTable != null && isTable.equalsIgnoreCase("true")) { SnmpObjId snmpObjId = SnmpObjId.get(oid); Map<SnmpInstId, SnmpValue> table = SnmpUtils.getOidValues(agentConfig, "SnmpPlugin", snmpObjId); for (Map.Entry<SnmpInstId, SnmpValue> e : table.entrySet()) { if (e.getValue().toString().equals(expectedValue)) { return true; } } } else { String retrievedValue = getValue(agentConfig, oid); if (retrievedValue != null && expectedValue != null) { return (Pattern.compile(expectedValue).matcher(retrievedValue).find()); } else { return (retrievedValue != null); // return (expectedValue == null ? true : retrievedValue.equals(expectedValue)); } } } catch (Throwable t) { throw new UndeclaredThrowableException(t); } // should never get here. return false; }
public OnmsAccessPointCollection call() throws IOException { OnmsAccessPointCollection apsUp = new OnmsAccessPointCollection(); InetAddress ipaddr = m_iface.getIpAddress(); // Retrieve this interface's SNMP peer object SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(ipaddr); if (agentConfig == null) { throw new IllegalStateException( "SnmpAgentConfig object not available for interface " + ipaddr); } final String hostAddress = InetAddressUtils.str(ipaddr); log().debug("poll: setting SNMP peer attribute for interface " + hostAddress); // Get configuration parameters String oid = ParameterMap.getKeyedString(m_parameters, "oid", null); if (oid == null) { throw new IllegalStateException("oid parameter is not set."); } agentConfig.hashCode(); // Set timeout and retries on SNMP peer object agentConfig.setTimeout( ParameterMap.getKeyedInteger(m_parameters, "timeout", agentConfig.getTimeout())); agentConfig.setRetries( ParameterMap.getKeyedInteger( m_parameters, "retry", ParameterMap.getKeyedInteger(m_parameters, "retries", agentConfig.getRetries()))); agentConfig.setPort(ParameterMap.getKeyedInteger(m_parameters, "port", agentConfig.getPort())); if (log().isDebugEnabled()) { log().debug("TableStrategy.poll: SnmpAgentConfig address= " + agentConfig); } // Establish SNMP session with interface try { SnmpObjId snmpObjectId = SnmpObjId.get(oid); Map<SnmpInstId, SnmpValue> map = SnmpUtils.getOidValues(agentConfig, "AccessPointMonitor::TableStrategy", snmpObjectId); if (map.size() <= 0) { throw new IOException("No entries found in table (possible timeout)."); } for (Map.Entry<SnmpInstId, SnmpValue> entry : map.entrySet()) { SnmpValue value = entry.getValue(); String physAddr = getPhysAddrFromValue(value); log() .debug( "AP at value '" + value.toHexString() + "' with MAC '" + physAddr + "' is considered to be ONLINE on controller '" + m_iface.getIpAddress() + "'"); OnmsAccessPoint ap = m_accessPointDao.findByPhysAddr(physAddr); if (ap != null) { if (ap.getPollingPackage().compareToIgnoreCase(getPackage().getName()) == 0) { // Save the controller's IP address ap.setControllerIpAddress(ipaddr); apsUp.add(ap); } else { log().info("AP with MAC '" + physAddr + "' is in a different package."); } } else { log().info("No matching AP in database for value '" + value.toHexString() + "'."); } } } catch (InterruptedException e) { log().error("Interrupted while polling " + hostAddress, e); } return apsUp; }
private SnmpAgentConfig getAgentConfig(final String address) { return m_snmpPeerFactory.getAgentConfig(addr(address)); }