Search in sources :

Example 26 with Value

use of org.opennms.netmgt.xml.event.Value in project opennms by OpenNMS.

the class PollerEventProcessor method nodeDeletedHandler.

/**
 * This method is responsible for removing the node specified in the
 * nodeDeleted event from the Poller's pollable node map.
 */
private void nodeDeletedHandler(Event event) {
    Long nodeId = event.getNodeid();
    final String sourceUei = event.getUei();
    // 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("nodeDeletedHandler:  parmName: {} /parmContent: {}", parmName, parmContent);
            try {
                txNo = Long.valueOf(temp).longValue();
            } catch (final NumberFormatException nfe) {
                LOG.warn("nodeDeletedHandler: Parameter {} cannot be non-numeric", EventConstants.PARM_TRANSACTION_NO, nfe);
                txNo = -1;
            }
        }
    }
    Date closeDate = event.getTime();
    getPoller().getQueryManager().closeOutagesForNode(closeDate, event.getDbid(), nodeId.intValue());
    PollableNode node = getNetwork().getNode(nodeId.intValue());
    if (node == null) {
        LOG.error("Nodeid {} does not exist in pollable node map, unable to delete node.", nodeId);
        return;
    }
    node.delete();
}
Also used : PollableNode(org.opennms.netmgt.poller.pollables.PollableNode) Value(org.opennms.netmgt.xml.event.Value) Parm(org.opennms.netmgt.xml.event.Parm) Date(java.util.Date)

Example 27 with Value

use of org.opennms.netmgt.xml.event.Value in project opennms by OpenNMS.

the class DataSender method handleRtcUnsubscribe.

/**
 * Inform the data sender of the listener unsubscribing
 */
@EventHandler(uei = EventConstants.RTC_UNSUBSCRIBE_EVENT_UEI)
public void handleRtcUnsubscribe(Event event) {
    List<Parm> list = event.getParmCollection();
    if (list == null) {
        LOG.warn("{} ignored - info incomplete (null event parms)", event.getUei());
        return;
    }
    String url = null;
    String parmName = null;
    Value parmValue = null;
    String parmContent = null;
    for (Parm parm : list) {
        parmName = parm.getParmName();
        parmValue = parm.getValue();
        if (parmValue == null)
            continue;
        else
            parmContent = parmValue.getContent();
        if (parmName.equals(EventConstants.PARM_URL)) {
            url = parmContent;
        }
    }
    // check that we got the required parameter
    if (url == null) {
        LOG.warn("{} did not have required information.  Value of url: {}", event.getUei(), url);
    } else {
        unsubscribe(url);
        LOG.debug("{} unsubscribed {}", event.getUei(), url);
    }
}
Also used : Value(org.opennms.netmgt.xml.event.Value) Parm(org.opennms.netmgt.xml.event.Parm) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler)

Example 28 with Value

use of org.opennms.netmgt.xml.event.Value in project opennms by OpenNMS.

the class DataUpdater method handleInterfaceReparented.

/**
 * Record the interfaceReparented info in the datastore
 */
private void handleInterfaceReparented(InetAddress ip, List<Parm> list) {
    if (ip == null || list == null) {
        LOG.warn("{} ignored - info incomplete - ip/parms: {}/{}", m_event.getUei(), InetAddressUtils.str(ip), list);
        return;
    }
    // old node ID
    int oldNodeId = -1;
    // new node ID
    int newNodeId = -1;
    String parmName = null;
    Value parmValue = null;
    String parmContent = null;
    for (Parm parm : list) {
        parmName = parm.getParmName();
        parmValue = parm.getValue();
        if (parmValue == null)
            continue;
        else
            parmContent = parmValue.getContent();
        // old node ID
        if (parmName.equals(EventConstants.PARM_OLD_NODEID)) {
            String temp = parmContent;
            try {
                oldNodeId = Integer.parseInt(temp);
            } catch (NumberFormatException nfe) {
                LOG.warn("Parameter {} cannot be non-numeric", EventConstants.PARM_OLD_NODEID, nfe);
                oldNodeId = -1;
            }
        } else // new node ID
        if (parmName.equals(EventConstants.PARM_NEW_NODEID)) {
            String temp = parmContent;
            try {
                newNodeId = Integer.parseInt(temp);
            } catch (NumberFormatException nfe) {
                LOG.warn("Parameter {} cannot be non-numeric", EventConstants.PARM_NEW_NODEID, nfe);
                newNodeId = -1;
            }
        }
    }
    if (oldNodeId == -1 || newNodeId == -1) {
        LOG.warn("{} did not have all required information for {} Values contained old nodeid: {} new nodeid: {}", m_event.getUei(), InetAddressUtils.str(ip), oldNodeId, newNodeId);
    } else {
        m_dataManager.interfaceReparented(ip, oldNodeId, newNodeId);
        LOG.debug("{} reparented ip: {} from {} to {}", m_event.getUei(), InetAddressUtils.str(ip), oldNodeId, newNodeId);
    }
}
Also used : Value(org.opennms.netmgt.xml.event.Value) Parm(org.opennms.netmgt.xml.event.Parm)

Example 29 with Value

use of org.opennms.netmgt.xml.event.Value in project opennms by OpenNMS.

the class Collectd method handleInterfaceReparented.

/**
 * This method is responsible for processing 'interfacReparented' events.
 * An 'interfaceReparented' event will have old and new nodeId parms
 * associated with it. All CollectableService objects in the service
 * updates map which match the event's interface address and the SNMP
 * service have a reparenting update associated with them. When the
 * scheduler next pops one of these services from an interval queue for
 * collection all of the RRDs associated with the old nodeId are moved
 * under the new nodeId and the nodeId of the collectable service is
 * updated to reflect the interface's new parent nodeId.
 *
 * @param event
 *            The event to process.
 * @throws InsufficientInformationException
 */
private void handleInterfaceReparented(Event event) throws InsufficientInformationException {
    EventUtils.checkNodeId(event);
    EventUtils.checkInterface(event);
    LOG.debug("interfaceReparentedHandler:  processing interfaceReparented event for {}", event.getInterface());
    // Verify that the event has an interface associated with it
    if (event.getInterface() == null)
        return;
    // 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.warn("interfaceReparentedHandler: old and new nodeId parms are required, unable to process.");
        return;
    }
    // Iterate over the CollectableService objects in the services
    // list looking for entries which share the same interface
    // address as the reparented interface. Mark any matching objects
    // for reparenting.
    // 
    // The next time the service is scheduled for execution it
    // will move all of the RRDs associated
    // with the old nodeId under the new nodeId and update the service's
    // SnmpMonitor.NodeInfo attribute to reflect the new nodeId. All
    // subsequent collections will then be updating the appropriate RRDs.
    // 
    OnmsIpInterface iface = null;
    synchronized (getCollectableServices()) {
        CollectableService cSvc = null;
        Iterator<CollectableService> iter = getCollectableServices().iterator();
        while (iter.hasNext()) {
            cSvc = iter.next();
            InetAddress addr = (InetAddress) cSvc.getAddress();
            if (addr.equals(event.getInterfaceAddress())) {
                synchronized (cSvc) {
                    // Got a match!
                    LOG.debug("interfaceReparentedHandler: got a CollectableService match for {}", event.getInterface());
                    // Retrieve the CollectorUpdates object associated
                    // with
                    // this CollectableService.
                    CollectorUpdates updates = cSvc.getCollectorUpdates();
                    if (iface == null) {
                        iface = getIpInterface(event.getNodeid().intValue(), event.getInterface());
                    }
                    // Now set the reparenting flag
                    updates.markForReparenting(oldNodeIdStr, newNodeIdStr, iface);
                    LOG.debug("interfaceReparentedHandler: marking {} for reparenting for service SNMP.", event.getInterface());
                }
            }
        }
    }
    LOG.debug("interfaceReparentedHandler: processing of interfaceReparented event for interface {} completed.", event.getInterface());
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Value(org.opennms.netmgt.xml.event.Value) Parm(org.opennms.netmgt.xml.event.Parm) InetAddress(java.net.InetAddress)

Example 30 with Value

use of org.opennms.netmgt.xml.event.Value in project opennms by OpenNMS.

the class EventBuilder method setParam.

/**
 * <p>setParam</p>
 *
 * @param parmName a {@link java.lang.String} object.
 * @param val a {@link java.lang.String} object.
 * @return a {@link org.opennms.netmgt.model.events.EventBuilder} object.
 */
public EventBuilder setParam(final String parmName, final String val) {
    if (m_event.getParmCollection().size() < 1) {
        return addParam(parmName, val);
    }
    for (final Parm parm : m_event.getParmCollection()) {
        if (parm.getParmName().equals(parmName)) {
            final Value value = new Value();
            value.setContent(val);
            parm.setValue(value);
            return this;
        }
    }
    return addParam(parmName, val);
}
Also used : Value(org.opennms.netmgt.xml.event.Value) Parm(org.opennms.netmgt.xml.event.Parm)

Aggregations

Value (org.opennms.netmgt.xml.event.Value)33 Parm (org.opennms.netmgt.xml.event.Parm)31 InetAddress (java.net.InetAddress)5 Event (org.opennms.netmgt.xml.event.Event)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)3 Test (org.junit.Test)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 PollableNode (org.opennms.netmgt.poller.pollables.PollableNode)3 EventHandler (org.opennms.netmgt.events.api.annotations.EventHandler)2 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)2 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)2 PollableInterface (org.opennms.netmgt.poller.pollables.PollableInterface)2 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)2 Logmsg (org.opennms.netmgt.xml.event.Logmsg)2 Snmp (org.opennms.netmgt.xml.event.Snmp)2 BufferedReader (java.io.BufferedReader)1 StringReader (java.io.StringReader)1 InetSocketAddress (java.net.InetSocketAddress)1 HashMap (java.util.HashMap)1