Search in sources :

Example 1 with PollableService

use of org.opennms.netmgt.poller.pollables.PollableService in project opennms by OpenNMS.

the class PollerEventProcessor method serviceDeletedHandler.

/**
     * <p>
     * This method remove a deleted service from the pollable service list of
     * the specified interface, so that it will not be scheduled by the poller.
     * </p>
     */
private void serviceDeletedHandler(Event event) {
    Long nodeId = event.getNodeid();
    InetAddress ipAddr = event.getInterfaceAddress();
    String service = event.getService();
    Date closeDate = event.getTime();
    getPoller().getQueryManager().closeOutagesForService(closeDate, event.getDbid(), nodeId.intValue(), str(ipAddr), service);
    PollableService svc = getNetwork().getService(nodeId.intValue(), ipAddr, service);
    if (svc == null) {
        LOG.error("Interface {}/{} does not exist in pollable node map, unable to delete node.", nodeId, event.getInterface());
        return;
    }
    svc.delete();
}
Also used : PollableService(org.opennms.netmgt.poller.pollables.PollableService) InetAddress(java.net.InetAddress) Date(java.util.Date)

Example 2 with PollableService

use of org.opennms.netmgt.poller.pollables.PollableService in project opennms by OpenNMS.

the class PollerEventProcessor method nodeGainedServiceHandler.

/**
     * Process the event, construct a new PollableService object representing
     * the node/interface/service/pkg combination, and schedule the service for
     * polling.
     * 
     * If any errors occur scheduling the interface no error is returned.
     * 
     * @param event
     *            The event to process.
     * 
     */
private void nodeGainedServiceHandler(final Event event) {
    // First make sure the service gained is in active state before trying to schedule
    final String ipAddr = event.getInterface();
    final Long nodeId = event.getNodeid();
    final String svcName = event.getService();
    String nodeLabel = EventUtils.getParm(event, EventConstants.PARM_NODE_LABEL);
    try {
        nodeLabel = getPoller().getQueryManager().getNodeLabel(nodeId.intValue());
    } catch (final Exception e) {
        LOG.error("Unable to retrieve nodeLabel for node {}", nodeId, e);
    }
    String nodeLocation = null;
    try {
        nodeLocation = getPoller().getQueryManager().getNodeLocation(nodeId.intValue());
    } catch (final Exception e) {
        LOG.error("Unable to retrieve nodeLocation for node {}", nodeId, e);
    }
    final PollableNode pnode = getNetwork().getNode(nodeId.intValue());
    if (pnode != null) {
        final PollableService service = pnode.getService(addr(ipAddr), svcName);
        if (service != null) {
            LOG.debug("Node {} gained service {} on IP {}, but it is already being polled!", nodeId, svcName, ipAddr);
            return;
        }
    }
    getPoller().scheduleService(nodeId.intValue(), nodeLabel, nodeLocation, ipAddr, svcName);
}
Also used : PollableNode(org.opennms.netmgt.poller.pollables.PollableNode) PollableService(org.opennms.netmgt.poller.pollables.PollableService)

Example 3 with PollableService

use of org.opennms.netmgt.poller.pollables.PollableService in project opennms by OpenNMS.

the class Poller method refreshServiceThresholds.

/**
     * <p>refreshServiceThresholds</p>
     */
public void refreshServiceThresholds() {
    PollableVisitor visitor = new PollableVisitorAdaptor() {

        @Override
        public void visitService(PollableService service) {
            service.refreshThresholds();
        }
    };
    getNetwork().visit(visitor);
}
Also used : PollableVisitorAdaptor(org.opennms.netmgt.poller.pollables.PollableVisitorAdaptor) PollableService(org.opennms.netmgt.poller.pollables.PollableService) PollableVisitor(org.opennms.netmgt.poller.pollables.PollableVisitor)

Example 4 with PollableService

use of org.opennms.netmgt.poller.pollables.PollableService in project opennms by OpenNMS.

the class PollerEventProcessor method serviceReschedule.

private void serviceReschedule(Long nodeId, String nodeLabel, String nodeLocation, Event sourceEvent, boolean rescheduleExisting) {
    if (nodeId == null || nodeId <= 0) {
        LOG.warn("Invalid node ID for event, skipping service reschedule: {}", sourceEvent);
        return;
    }
    Date closeDate = sourceEvent.getTime();
    final Set<Service> databaseServices = new HashSet<>();
    for (final String[] s : getPoller().getQueryManager().getNodeServices(nodeId.intValue())) {
        databaseServices.add(new Service(s));
    }
    LOG.debug("# of Services in Database: {}", databaseServices.size());
    LOG.trace("Database Services: {}", databaseServices);
    final Set<Service> polledServices = new HashSet<>();
    final PollableNode pnode = getNetwork().getNode(nodeId.intValue());
    if (pnode == null) {
        LOG.debug("Node {} is not already being polled.", nodeId);
    } else {
        if (pnode.getNodeLabel() != null) {
            nodeLabel = pnode.getNodeLabel();
        }
        for (final PollableInterface iface : pnode.getInterfaces()) {
            for (final PollableService s : iface.getServices()) {
                polledServices.add(new Service(s.getIpAddr(), s.getSvcName()));
            }
        }
        LOG.debug("# of Polled Services: {}", polledServices.size());
        LOG.trace("Polled Services: {}", polledServices);
    }
    // if any of these are no longer in the database, then remove them
    for (final Iterator<Service> iter = polledServices.iterator(); iter.hasNext(); ) {
        final Service polledService = iter.next();
        if (!databaseServices.contains(polledService)) {
            // We are polling the service, but it no longer exists.  Stop polling.
            if (pnode != null) {
                final PollableService service = pnode.getService(polledService.getInetAddress(), polledService.getServiceName());
                // Delete the service
                service.delete();
                while (!service.isDeleted()) {
                    try {
                        Thread.sleep(20);
                    } catch (final InterruptedException e) {
                        Thread.currentThread().interrupt();
                    }
                }
            }
            // Close outages.
            LOG.debug("{} should no longer be polled.  Resolving outages.", polledService);
            closeOutagesForService(sourceEvent, nodeId, closeDate, polledService);
            iter.remove();
        }
    }
    // Delete the remaining services if we which to reschedule those that are already active
    if (rescheduleExisting && pnode != null) {
        for (final Iterator<Service> iter = polledServices.iterator(); iter.hasNext(); ) {
            final Service polledService = iter.next();
            final PollableService service = pnode.getService(polledService.getInetAddress(), polledService.getServiceName());
            // Delete the service
            service.delete();
            while (!service.isDeleted()) {
                try {
                    Thread.sleep(20);
                } catch (final InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            }
            iter.remove();
        }
    }
    // Schedule all of the services, if they are not already
    for (final Service databaseService : databaseServices) {
        if (polledServices.contains(databaseService)) {
            LOG.debug("{} is being skipped. Already scheduled.", databaseService);
            continue;
        }
        LOG.debug("{} is being scheduled (or rescheduled) for polling.", databaseService);
        getPoller().scheduleService(nodeId.intValue(), nodeLabel, nodeLocation, databaseService.getAddress(), databaseService.getServiceName());
        if (!getPollerConfig().isPolled(databaseService.getAddress(), databaseService.getServiceName())) {
            LOG.debug("{} is no longer polled.  Closing any pending outages.", databaseService);
            closeOutagesForService(sourceEvent, nodeId, closeDate, databaseService);
        }
    }
}
Also used : PollableNode(org.opennms.netmgt.poller.pollables.PollableNode) PollableService(org.opennms.netmgt.poller.pollables.PollableService) PollableService(org.opennms.netmgt.poller.pollables.PollableService) PollableInterface(org.opennms.netmgt.poller.pollables.PollableInterface) Date(java.util.Date) HashSet(java.util.HashSet)

Example 5 with PollableService

use of org.opennms.netmgt.poller.pollables.PollableService in project opennms by OpenNMS.

the class PollerEventProcessor method nodeRemovePollableServiceHandler.

/**
     * This method is responsible for removing a node's pollable service from
     * the pollable services list
     */
private void nodeRemovePollableServiceHandler(Event event) {
    Long nodeId = event.getNodeid();
    InetAddress ipAddr = event.getInterfaceAddress();
    String svcName = event.getService();
    if (svcName == null) {
        LOG.error("nodeRemovePollableServiceHandler: service name is null, ignoring event");
        return;
    }
    PollableService svc = getNetwork().getService(nodeId.intValue(), ipAddr, svcName);
    svc.delete();
}
Also used : PollableService(org.opennms.netmgt.poller.pollables.PollableService) InetAddress(java.net.InetAddress)

Aggregations

PollableService (org.opennms.netmgt.poller.pollables.PollableService)7 InetAddress (java.net.InetAddress)3 Date (java.util.Date)3 PollableNode (org.opennms.netmgt.poller.pollables.PollableNode)2 PollableVisitor (org.opennms.netmgt.poller.pollables.PollableVisitor)2 PollableVisitorAdaptor (org.opennms.netmgt.poller.pollables.PollableVisitorAdaptor)2 HashSet (java.util.HashSet)1 Package (org.opennms.netmgt.config.poller.Package)1 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)1 DbPollEvent (org.opennms.netmgt.poller.pollables.DbPollEvent)1 PollEvent (org.opennms.netmgt.poller.pollables.PollEvent)1 PollableInterface (org.opennms.netmgt.poller.pollables.PollableInterface)1 PollableServiceConfig (org.opennms.netmgt.poller.pollables.PollableServiceConfig)1 Schedule (org.opennms.netmgt.scheduler.Schedule)1