Search in sources :

Example 1 with PollableInterface

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

the class PollerEventProcessor method interfaceReparentedHandler.

/**
     * This method is responsible for processing 'interfacReparented' events. An
     * 'interfaceReparented' event will have old and new nodeId parms associated
     * with it. Node outage processing hierarchy will be updated to reflect the
     * new associations.
     * 
     * @param event
     *            The event to process.
     * 
     */
private void interfaceReparentedHandler(Event event) {
    LOG.debug("interfaceReparentedHandler: processing interfaceReparented event for {}", event.getInterface());
    // Verify that the event has an interface associated with it
    if (event.getInterfaceAddress() == null)
        return;
    InetAddress ipAddr = event.getInterfaceAddress();
    // Extract the old and new nodeId's from the event parms
    String oldNodeIdStr = null;
    String newNodeIdStr = null;
    String parmName = null;
    Value parmValue = null;
    String parmContent = null;
    for (Parm parm : event.getParmCollection()) {
        parmName = parm.getParmName();
        parmValue = parm.getValue();
        if (parmValue == null)
            continue;
        else
            parmContent = parmValue.getContent();
        // old nodeid
        if (parmName.equals(EventConstants.PARM_OLD_NODEID)) {
            oldNodeIdStr = parmContent;
        } else // new nodeid
        if (parmName.equals(EventConstants.PARM_NEW_NODEID)) {
            newNodeIdStr = parmContent;
        }
    }
    //
    if (oldNodeIdStr == null || newNodeIdStr == null) {
        LOG.error("interfaceReparentedHandler: old and new nodeId parms are required, unable to process.");
        return;
    }
    PollableNode oldNode;
    PollableNode newNode;
    try {
        oldNode = getNetwork().getNode(Integer.parseInt(oldNodeIdStr));
        if (oldNode == null) {
            LOG.error("interfaceReparentedHandler: Cannot locate old node {} belonging to interface {}", oldNodeIdStr, ipAddr);
            return;
        }
        newNode = getNetwork().getNode(Integer.parseInt(newNodeIdStr));
        if (newNode == null) {
            LOG.error("interfaceReparentedHandler: Cannot locate new node {} to move interface to.  Also, grammar error: ended a sentence with a preposition.", newNodeIdStr);
            return;
        }
        PollableInterface iface = oldNode.getInterface(ipAddr);
        if (iface == null) {
            LOG.error("interfaceReparentedHandler: Cannot locate interface with ipAddr {} to reparent.", ipAddr);
            return;
        }
        iface.reparentTo(newNode);
    } catch (final NumberFormatException nfe) {
        LOG.error("interfaceReparentedHandler: failed converting old/new nodeid parm to integer, unable to process.");
        return;
    }
}
Also used : PollableNode(org.opennms.netmgt.poller.pollables.PollableNode) Value(org.opennms.netmgt.xml.event.Value) Parm(org.opennms.netmgt.xml.event.Parm) PollableInterface(org.opennms.netmgt.poller.pollables.PollableInterface) InetAddress(java.net.InetAddress)

Example 2 with PollableInterface

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

the class PollerEventProcessor method interfaceDeletedHandler.

private void interfaceDeletedHandler(Event event) {
    Long nodeId = event.getNodeid();
    String sourceUei = event.getUei();
    InetAddress ipAddr = event.getInterfaceAddress();
    // Extract node label and transaction No. from the event parms
    long txNo = -1L;
    String parmName = null;
    Value parmValue = null;
    String parmContent = null;
    for (Parm parm : event.getParmCollection()) {
        parmName = parm.getParmName();
        parmValue = parm.getValue();
        if (parmValue == null)
            continue;
        else
            parmContent = parmValue.getContent();
        // get the external transaction number
        if (parmName.equals(EventConstants.PARM_TRANSACTION_NO)) {
            String temp = parmContent;
            LOG.debug("interfaceDeletedHandlerHandler:  parmName: {} /parmContent: {}", parmName, parmContent);
            try {
                txNo = Long.valueOf(temp).longValue();
            } catch (final NumberFormatException nfe) {
                LOG.warn("interfaceDeletedHandlerHandler: Parameter {} cannot be non-numberic", EventConstants.PARM_TRANSACTION_NO, nfe);
                txNo = -1;
            }
        }
    }
    Date closeDate = event.getTime();
    getPoller().getQueryManager().closeOutagesForInterface(closeDate, event.getDbid(), nodeId.intValue(), str(ipAddr));
    PollableInterface iface = getNetwork().getInterface(nodeId.intValue(), ipAddr);
    if (iface == null) {
        LOG.error("Interface {}/{} does not exist in pollable node map, unable to delete node.", nodeId, event.getInterface());
        return;
    }
    iface.delete();
}
Also used : Value(org.opennms.netmgt.xml.event.Value) Parm(org.opennms.netmgt.xml.event.Parm) PollableInterface(org.opennms.netmgt.poller.pollables.PollableInterface) InetAddress(java.net.InetAddress) Date(java.util.Date)

Example 3 with PollableInterface

use of org.opennms.netmgt.poller.pollables.PollableInterface 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)

Aggregations

PollableInterface (org.opennms.netmgt.poller.pollables.PollableInterface)3 InetAddress (java.net.InetAddress)2 Date (java.util.Date)2 PollableNode (org.opennms.netmgt.poller.pollables.PollableNode)2 Parm (org.opennms.netmgt.xml.event.Parm)2 Value (org.opennms.netmgt.xml.event.Value)2 HashSet (java.util.HashSet)1 PollableService (org.opennms.netmgt.poller.pollables.PollableService)1