use of org.opennms.netmgt.model.OnmsAccessPoint in project opennms by OpenNMS.
the class AccessPointMonitordTest method testDynamicPackages.
@Test
public void testDynamicPackages() throws Exception {
// A package name that matches the mask
addNewAccessPoint("ap1", AP1_MAC, "dynamic-pkg-1");
initApmdWithConfig(getDynamicPackageConfig());
m_apm.start();
sleep(PACKAGE_WAIT_INTERVAL);
assertEquals(1, m_apm.getActivePackageNames().size());
// Another package name that matches the mask
addNewAccessPoint("ap2", AP2_MAC, "dynamic-pkg-2");
// A package name that does not match the mask
addNewAccessPoint("ap3", AP3_MAC, "default");
awaitPackageSize(2);
// Change the package name for AP1 - the package should be unscheduled
OnmsAccessPoint ap1 = m_accessPointDao.get(AP1_MAC);
ap1.setPollingPackage("default");
m_accessPointDao.update(ap1);
m_accessPointDao.flush();
List<String> packageNames = m_accessPointDao.findDistinctPackagesLike("dynamic-pkg-%");
assertEquals(1, packageNames.size());
awaitPackageSize(1);
// Change the package name for AP1 - the package should be unscheduled
ap1.setPollingPackage("dynamic-pkg-2");
m_accessPointDao.update(ap1);
m_accessPointDao.flush();
awaitPackageSize(1);
// Reload the daemon
updateConfigAndReloadDaemon(getDynamicPackageConfig(), true);
awaitPackageSize(1);
}
use of org.opennms.netmgt.model.OnmsAccessPoint in project opennms by OpenNMS.
the class InstanceStrategyIntegrationTest method addNewAccessPoint.
private void addNewAccessPoint(String name, String mac, String pkg) {
NetworkBuilder nb = new NetworkBuilder();
nb.addNode(name).setForeignSource("apmd").setForeignId(name);
nb.addInterface("169.254.0.1");
m_nodeDao.save(nb.getCurrentNode());
final OnmsAccessPoint ap1 = new OnmsAccessPoint(mac, nb.getCurrentNode().getId(), pkg);
ap1.setStatus(AccessPointStatus.UNKNOWN);
m_accessPointDao.save(ap1);
m_nodeDao.flush();
m_accessPointDao.flush();
}
use of org.opennms.netmgt.model.OnmsAccessPoint in project opennms by OpenNMS.
the class AccessPointDatabasePopulator method populateDatabase.
public void populateDatabase() {
m_node1 = new OnmsNode();
m_node1.setLabel("AP1");
getNodeDao().save(m_node1);
getNodeDao().flush();
m_ap1 = new OnmsAccessPoint("00:00:00:00:00:01", m_node1.getId(), "default");
getAccessPointDao().save(m_ap1);
getAccessPointDao().flush();
}
use of org.opennms.netmgt.model.OnmsAccessPoint in project opennms by OpenNMS.
the class DefaultPollingContext method updateApStatus.
private void updateApStatus(OnmsAccessPointCollection apsUp, OnmsAccessPointCollection apsDown) {
// events
for (OnmsAccessPoint ap : apsUp) {
// Update the status in the database
ap.setStatus(AccessPointStatus.ONLINE);
// Use merge() here because the object may have been updated in a separate thread
m_accessPointDao.merge(ap);
try {
// Generate an AP UP event
Event e = createApStatusEvent(ap.getPhysAddr(), ap.getNodeId(), "UP");
m_eventMgr.send(e);
} catch (EventProxyException e) {
LOG.error("Error occured sending events ", e);
}
}
// events
for (OnmsAccessPoint ap : apsDown) {
// Update the status in the database
ap.setStatus(AccessPointStatus.OFFLINE);
// Use merge() here because the object may have been updated in a separate thread
m_accessPointDao.merge(ap);
try {
// Generate an AP DOWN event
Event e = createApStatusEvent(ap.getPhysAddr(), ap.getNodeId(), "DOWN");
m_eventMgr.send(e);
} catch (EventProxyException e) {
LOG.error("Error occured sending events ", e);
}
}
m_accessPointDao.flush();
}
use of org.opennms.netmgt.model.OnmsAccessPoint 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;
}
Aggregations