Search in sources :

Example 1 with OnmsIpInterfaceList

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

the class DefaultPollingContext method getInterfaceList.

protected OnmsIpInterfaceList getInterfaceList() {
    StringBuffer filterRules = new StringBuffer(getPackage().getEffectiveFilter());
    List<InetAddress> ipList = FilterDaoFactory.getInstance().getActiveIPAddressList(filterRules.toString());
    OnmsIpInterfaceList ifaces = new OnmsIpInterfaceList();
    // Only poll the primary interface
    final Criteria criteria = new Criteria(OnmsIpInterface.class);
    criteria.addRestriction(new EqRestriction("isSnmpPrimary", PrimaryType.PRIMARY));
    List<OnmsIpInterface> allValidIfaces = getIpInterfaceDao().findMatching(criteria);
    for (OnmsIpInterface iface : allValidIfaces) {
        if (ipList.contains(iface.getIpAddress())) {
            ifaces.add(iface);
        }
    }
    return ifaces;
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) Criteria(org.opennms.core.criteria.Criteria) InetAddress(java.net.InetAddress) OnmsIpInterfaceList(org.opennms.netmgt.model.OnmsIpInterfaceList)

Example 2 with OnmsIpInterfaceList

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

the class OnmsIpInterfaceResource method getIpInterfaces.

/**
 * <p>getIpInterfaces</p>
 *
 * @param nodeCriteria a {@link java.lang.String} object.
 * @return a {@link org.opennms.netmgt.model.OnmsIpInterfaceList} object.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public OnmsIpInterfaceList getIpInterfaces(@Context final UriInfo uriInfo, @PathParam("nodeCriteria") final String nodeCriteria) {
    LOG.debug("getIpInterfaces: reading interfaces for node {}", nodeCriteria);
    final OnmsNode node = m_nodeDao.get(nodeCriteria);
    final MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
    final CriteriaBuilder builder = new CriteriaBuilder(OnmsIpInterface.class);
    builder.alias("monitoredServices.serviceType", "serviceType", JoinType.LEFT_JOIN);
    builder.ne("isManaged", "D");
    builder.limit(20);
    applyQueryFilters(params, builder);
    builder.alias("node", "node");
    builder.eq("node.id", node.getId());
    final OnmsIpInterfaceList interfaceList = new OnmsIpInterfaceList(m_ipInterfaceDao.findMatching(builder.toCriteria()));
    interfaceList.setTotalCount(m_ipInterfaceDao.countMatching(builder.count().toCriteria()));
    return interfaceList;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterfaceList(org.opennms.netmgt.model.OnmsIpInterfaceList) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with OnmsIpInterfaceList

use of org.opennms.netmgt.model.OnmsIpInterfaceList 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)

Aggregations

OnmsIpInterfaceList (org.opennms.netmgt.model.OnmsIpInterfaceList)3 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)2 InetAddress (java.net.InetAddress)1 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 Criteria (org.opennms.core.criteria.Criteria)1 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)1 EqRestriction (org.opennms.core.criteria.restrictions.EqRestriction)1 AccessPointPoller (org.opennms.netmgt.accesspointmonitor.poller.AccessPointPoller)1 OnmsAccessPointCollection (org.opennms.netmgt.model.OnmsAccessPointCollection)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 Transactional (org.springframework.transaction.annotation.Transactional)1