use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class ScanManager method updateSnmpData.
void updateSnmpData(final OnmsNode node) {
try {
m_systemGroup = new SystemGroup(m_address);
final Set<SnmpInstId> ipAddrs = new TreeSet<SnmpInstId>();
final Set<InetAddress> ipAddresses = new HashSet<InetAddress>();
for (final OnmsIpInterface iface : node.getIpInterfaces()) {
final InetAddress addr = iface.getIpAddress();
if (addr != null && addr instanceof Inet4Address) {
ipAddrs.add(new SnmpInstId(InetAddressUtils.toOid(addr)));
}
ipAddresses.add(addr);
}
m_ipAddrTable = new IpAddrTable(m_address, ipAddrs);
m_ipAddressTable = IpAddressTable.createTable(m_address, ipAddresses);
AggregateTracker tracker = new AggregateTracker(Lists.newArrayList(m_systemGroup, m_ipAddrTable, m_ipAddressTable));
final SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(m_address, MonitoringLocationUtils.getLocationNameOrNullIfDefault(node));
try {
m_locationAwareSnmpClient.walk(agentConfig, tracker).withDescription("system/ipAddrTable/ipAddressTable").withLocation(node.getLocation() == null ? null : node.getLocation().getLocationName()).execute().get();
} catch (ExecutionException e) {
// pass
}
final Set<SnmpInstId> ifIndices = new TreeSet<SnmpInstId>();
for (final Integer ifIndex : m_ipAddrTable.getIfIndices()) {
ifIndices.add(new SnmpInstId(ifIndex));
}
m_ifTable = new IfTable(m_address, ifIndices);
m_ifXTable = new IfXTable(m_address, ifIndices);
tracker = new AggregateTracker(Lists.newArrayList(m_systemGroup, m_ifTable, m_ifXTable));
try {
m_locationAwareSnmpClient.walk(agentConfig, tracker).withDescription("ifTable/ifXTable").withLocation(node.getLocation() == null ? null : node.getLocation().getLocationName()).execute().get();
} catch (ExecutionException e) {
// pass
}
m_systemGroup.updateSnmpDataForNode(node);
for (final SnmpInstId ifIndex : ifIndices) {
m_ifTable.updateSnmpInterfaceData(node, ifIndex.toInt());
}
for (final SnmpInstId ifIndex : ifIndices) {
m_ifXTable.updateSnmpInterfaceData(node, ifIndex.toInt());
}
for (final SnmpInstId ipAddr : ipAddrs) {
m_ipAddrTable.updateIpInterfaceData(node, ipAddr.toString());
}
for (final InetAddress addr : ipAddresses) {
m_ipAddressTable.updateIpInterfaceData(node, InetAddressUtils.str(addr));
}
} catch (final InterruptedException e) {
LOG.info("thread interrupted while updating SNMP data", e);
Thread.currentThread().interrupt();
}
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class TableStrategy method call.
@Override
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()));
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 '{}' with MAC '{}' is considered to be ONLINE on controller '{}'", value.toHexString(), physAddr, m_iface.getIpAddress());
OnmsAccessPoint ap = m_accessPointDao.get(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 '{}' is in a different package.", physAddr);
}
} else {
LOG.info("No matching AP in database for value '{}'.", value.toHexString());
}
}
} catch (InterruptedException e) {
LOG.error("Interrupted while polling {}", hostAddress, e);
}
return apsUp;
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class InstanceStrategy method getAgentConfig.
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;
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class SnmpAssetProvisioningAdapter method doAddNode.
/**
* <p>doAdd</p>
*
* @param nodeId a int.
* @param retry a boolean.
* @throws org.opennms.netmgt.provision.ProvisioningAdapterException if any.
*/
@Override
public void doAddNode(final int nodeId) throws ProvisioningAdapterException {
LOG.debug("doAdd: adding nodeid: {}", nodeId);
final OnmsNode node = m_nodeDao.get(nodeId);
Assert.notNull(node, "doAdd: failed to return node for given nodeId:" + nodeId);
InetAddress ipaddress = m_template.execute(new TransactionCallback<InetAddress>() {
@Override
public InetAddress doInTransaction(TransactionStatus arg0) {
return getIpForNode(node);
}
});
SnmpAgentConfig agentConfig = null;
String locationName = node.getLocation() != null ? node.getLocation().getLocationName() : null;
agentConfig = m_snmpConfigDao.getAgentConfig(ipaddress, locationName);
final OnmsAssetRecord asset = node.getAssetRecord();
m_config.getReadLock().lock();
try {
for (final AssetField field : m_config.getAssetFieldsForAddress(ipaddress, node.getSysObjectId())) {
try {
final String value = fetchSnmpAssetString(m_locationAwareSnmpClient, agentConfig, locationName, field.getMibObjs(), field.getFormatString());
LOG.debug("doAdd: Setting asset field \" {} \" to value: {}", field.getName(), value);
// Use Spring bean-accessor classes to set the field value
final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(asset);
try {
wrapper.setPropertyValue(field.getName(), value);
} catch (final BeansException e) {
LOG.warn("doAdd: Could not set property \" {} \" on asset object {}", field.getName(), e.getMessage(), e);
}
} catch (final Throwable t) {
// This exception is thrown if the SNMP operation fails or an incorrect number of
// parameters is returned by the agent or because of a misconfiguration.
LOG.warn("doAdd: Could not set value for asset field \" {} \": {}", field.getName(), t.getMessage(), t);
}
}
} finally {
m_config.getReadLock().unlock();
}
node.setAssetRecord(asset);
m_nodeDao.saveOrUpdate(node);
m_nodeDao.flush();
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class SnmpCollectionSet method getAgentConfig.
/**
* <p>getAgentConfig</p>
*
* @return a {@link org.opennms.netmgt.snmp.SnmpAgentConfig} object.
*/
public SnmpAgentConfig getAgentConfig() {
SnmpAgentConfig agentConfig = getCollectionAgent().getAgentConfig();
agentConfig.setPort(m_snmpCollection.getSnmpPort(agentConfig.getPort()));
agentConfig.setRetries(m_snmpCollection.getSnmpRetries(agentConfig.getRetries()));
agentConfig.setTimeout(m_snmpCollection.getSnmpTimeout(agentConfig.getTimeout()));
agentConfig.setReadCommunity(m_snmpCollection.getSnmpReadCommunity(agentConfig.getReadCommunity()));
agentConfig.setWriteCommunity(m_snmpCollection.getSnmpWriteCommunity(agentConfig.getWriteCommunity()));
agentConfig.setProxyFor(m_snmpCollection.getSnmpProxyFor(agentConfig.getProxyFor()));
agentConfig.setVersion(m_snmpCollection.getSnmpVersion(agentConfig.getVersion()));
agentConfig.setMaxVarsPerPdu(m_snmpCollection.getSnmpMaxVarsPerPdu(agentConfig.getMaxVarsPerPdu()));
agentConfig.setMaxRepetitions(m_snmpCollection.getSnmpMaxRepetitions(agentConfig.getMaxRepetitions()));
agentConfig.setMaxRequestSize(m_snmpCollection.getSnmpMaxRequestSize(agentConfig.getMaxRequestSize()));
agentConfig.setSecurityName(m_snmpCollection.getSnmpSecurityName(agentConfig.getSecurityName()));
agentConfig.setAuthPassPhrase(m_snmpCollection.getSnmpAuthPassPhrase(agentConfig.getAuthPassPhrase()));
agentConfig.setAuthProtocol(m_snmpCollection.getSnmpAuthProtocol(agentConfig.getAuthProtocol()));
agentConfig.setPrivPassPhrase(m_snmpCollection.getSnmpPrivPassPhrase(agentConfig.getPrivPassPhrase()));
agentConfig.setPrivProtocol(m_snmpCollection.getSnmpPrivProtocol(agentConfig.getPrivProtocol()));
return agentConfig;
}
Aggregations