Search in sources :

Example 1 with OnmsAccessPointCollection

use of org.opennms.netmgt.model.OnmsAccessPointCollection 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;
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) OnmsAccessPoint(org.opennms.netmgt.model.OnmsAccessPoint) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) OnmsAccessPointCollection(org.opennms.netmgt.model.OnmsAccessPointCollection) IOException(java.io.IOException) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) InetAddress(java.net.InetAddress) Map(java.util.Map) ParameterMap(org.opennms.core.utils.ParameterMap)

Example 2 with OnmsAccessPointCollection

use of org.opennms.netmgt.model.OnmsAccessPointCollection in project opennms by OpenNMS.

the class AccessPointRestService method getAccessPoints.

/**
 * <p>
 * getOutages
 * </p>
 *
 * @return a {@link org.opennms.netmgt.model.OnmsOutageCollection} object.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Transactional
public OnmsAccessPointCollection getAccessPoints(@Context final UriInfo uriInfo) {
    readLock();
    try {
        final CriteriaBuilder builder = new CriteriaBuilder(OnmsAccessPoint.class);
        // TODO: Fix query filters - these don't seem to work outside of
        // the opennms-webapp project
        // applyQueryFilters(uriInfo.getQueryParameters(), builder);
        final OnmsAccessPointCollection coll = new OnmsAccessPointCollection(m_accessPointDao.findAll());
        // For getting totalCount
        coll.setTotalCount(m_accessPointDao.countMatching(builder.count().toCriteria()));
        return coll;
    } finally {
        readUnlock();
    }
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsAccessPointCollection(org.opennms.netmgt.model.OnmsAccessPointCollection) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with OnmsAccessPointCollection

use of org.opennms.netmgt.model.OnmsAccessPointCollection in project opennms by OpenNMS.

the class InstanceStrategy 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 = getAgentConfig(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.");
    }
    String operator = ParameterMap.getKeyedString(m_parameters, "operator", null);
    String operand = ParameterMap.getKeyedString(m_parameters, "operand", null);
    String matchstr = ParameterMap.getKeyedString(m_parameters, "match", "true");
    LOG.debug("InstanceStrategy.poll: SnmpAgentConfig address= {}", agentConfig);
    // Establish SNMP session with interface
    try {
        SnmpObjId snmpObjectId = SnmpObjId.get(oid);
        Map<SnmpInstId, SnmpValue> map = SnmpUtils.getOidValues(agentConfig, "AccessPointMonitor::InstanceStrategy", snmpObjectId);
        if (map.size() <= 0) {
            throw new IOException("No entries found in table (possible timeout).");
        }
        for (Map.Entry<SnmpInstId, SnmpValue> entry : map.entrySet()) {
            boolean isUp = false;
            SnmpInstId instance = entry.getKey();
            SnmpValue value = entry.getValue();
            // Check the value against the configured criteria
            if (meetsCriteria(value, operator, operand)) {
                if ("true".equals(matchstr)) {
                    isUp = true;
                }
            } else if ("false".equals(matchstr)) {
                isUp = true;
            }
            // of online APs
            if (isUp) {
                String physAddr = getPhysAddrFromInstance(instance);
                LOG.debug("AP at instance '{}' with MAC '{}' is considered to be ONLINE on controller '{}'", instance, 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 instance '{}'.", instance);
                }
            }
        }
    } catch (NumberFormatException e) {
        LOG.error("Number operator used on a non-number ", e);
    } catch (IllegalArgumentException e) {
        LOG.error("Invalid SNMP Criteria ", e);
    } catch (InterruptedException e) {
        LOG.error("Interrupted while polling {}", hostAddress, e);
    }
    return apsUp;
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) OnmsAccessPoint(org.opennms.netmgt.model.OnmsAccessPoint) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) OnmsAccessPointCollection(org.opennms.netmgt.model.OnmsAccessPointCollection) IOException(java.io.IOException) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) InetAddress(java.net.InetAddress) Map(java.util.Map) ParameterMap(org.opennms.core.utils.ParameterMap)

Example 4 with OnmsAccessPointCollection

use of org.opennms.netmgt.model.OnmsAccessPointCollection in project opennms by OpenNMS.

the class DefaultPollingContext method run.

@Override
@Transactional
public void run() {
    // Determine the list of interfaces to poll at runtime
    OnmsIpInterfaceList ifaces = getInterfaceList();
    // If the list of interfaces is empty, print a warning message
    if (ifaces.getIpInterfaces().isEmpty()) {
        LOG.warn("Package '{}' was scheduled, but no interfaces were matched.", getPackage().getName());
    }
    // Get the complete list of APs that we are responsible for polling
    OnmsAccessPointCollection apsDown = m_accessPointDao.findByPackage(getPackage().getName());
    LOG.debug("Found {} APs in package '{}'", apsDown.size(), getPackage().getName());
    // Keep track of all APs that we've confirmed to be ONLINE
    OnmsAccessPointCollection apsUp = new OnmsAccessPointCollection();
    Set<Callable<OnmsAccessPointCollection>> callables = new HashSet<Callable<OnmsAccessPointCollection>>();
    // Iterate over all of the matched interfaces
    for (final OnmsIpInterface iface : ifaces.getIpInterfaces()) {
        // Create a new instance of the poller
        final AccessPointPoller p = m_package.getPoller(m_pollerConfig.getMonitors());
        p.setInterfaceToPoll(iface);
        p.setAccessPointDao(m_accessPointDao);
        p.setPackage(m_package);
        p.setPropertyMap(m_parameters);
        // Schedule the poller for execution
        callables.add(p);
    }
    boolean succesfullyPolledAController = false;
    try {
        if (m_pool == null) {
            LOG.warn("run() called, but no thread pool has been initialized.  Calling init()");
            init();
        }
        // Invoke all of the pollers using the thread pool
        List<Future<OnmsAccessPointCollection>> futures = m_pool.invokeAll(callables);
        // Gather the list of APs that are ONLINE
        for (Future<OnmsAccessPointCollection> future : futures) {
            try {
                apsUp.addAll(future.get().getObjects());
                succesfullyPolledAController = true;
            } catch (ExecutionException e) {
                LOG.error("An error occurred while polling", e);
            }
        }
    } catch (InterruptedException e) {
        LOG.error("I was interrupted", e);
    }
    // Remove the APs from the list that are ONLINE
    apsDown.removeAll(apsUp.getObjects());
    LOG.debug("({}) APs Online, ({}) APs offline in package '{}'", apsUp.size(), apsDown.size(), getPackage().getName());
    if (!succesfullyPolledAController) {
        LOG.warn("Failed to poll at least one controller in the package '{}'", getPackage().getName());
    }
    updateApStatus(apsUp, apsDown);
    // Reschedule the service
    LOG.debug("Re-scheduling the package '{}' in {}", getPackage().getName(), m_interval);
    m_scheduler.schedule(m_interval, getReadyRunnable());
}
Also used : OnmsAccessPointCollection(org.opennms.netmgt.model.OnmsAccessPointCollection) Callable(java.util.concurrent.Callable) AccessPointPoller(org.opennms.netmgt.accesspointmonitor.poller.AccessPointPoller) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) OnmsIpInterfaceList(org.opennms.netmgt.model.OnmsIpInterfaceList) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with OnmsAccessPointCollection

use of org.opennms.netmgt.model.OnmsAccessPointCollection in project opennms by OpenNMS.

the class AccessPointDaoTest method testFindByPackage.

@Test
@Transactional
public void testFindByPackage() {
    addNewAccessPoint("ap1", AP1_MAC, "package1");
    addNewAccessPoint("ap2", AP2_MAC, "package1");
    addNewAccessPoint("ap3", AP3_MAC, "package2");
    OnmsAccessPointCollection apsInPkg = m_accessPointDao.findByPackage("package1");
    assertEquals("There should be two APs in the package.", 2, apsInPkg.size());
    List<String> unqPkgNames = m_accessPointDao.findDistinctPackagesLike("%ack%");
    assertEquals(2, unqPkgNames.size());
    assertEquals(true, unqPkgNames.contains("package1"));
    assertEquals(true, unqPkgNames.contains("package2"));
}
Also used : OnmsAccessPointCollection(org.opennms.netmgt.model.OnmsAccessPointCollection) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OnmsAccessPointCollection (org.opennms.netmgt.model.OnmsAccessPointCollection)6 Transactional (org.springframework.transaction.annotation.Transactional)3 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 Map (java.util.Map)2 ParameterMap (org.opennms.core.utils.ParameterMap)2 OnmsAccessPoint (org.opennms.netmgt.model.OnmsAccessPoint)2 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)2 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)2 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)2 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)2 HashSet (java.util.HashSet)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 Test (org.junit.Test)1 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)1 AccessPointPoller (org.opennms.netmgt.accesspointmonitor.poller.AccessPointPoller)1