Search in sources :

Example 6 with EventHandler

use of org.opennms.netmgt.events.api.annotations.EventHandler in project opennms by OpenNMS.

the class DataSender method handleRtcSubscribe.

/**
 * Inform the data sender of the new listener
 */
@EventHandler(uei = EventConstants.RTC_SUBSCRIBE_EVENT_UEI)
public void handleRtcSubscribe(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 clabel = null;
    String user = null;
    String passwd = 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;
        } else if (parmName.equals(EventConstants.PARM_CAT_LABEL)) {
            clabel = parmContent;
        } else if (parmName.equals(EventConstants.PARM_USER)) {
            user = parmContent;
        } else if (parmName.equals(EventConstants.PARM_PASSWD)) {
            passwd = parmContent;
        }
    }
    // check that we got all required parms
    if (url == null || clabel == null || user == null || passwd == null) {
        LOG.warn("{} did not have all required information. Values contained url: {} catlabel: {} user: {} passwd: {}", event.getUei(), url, clabel, user, passwd);
    } else {
        subscribe(url, clabel, user, passwd);
        LOG.debug("{} subscribed {}: {}: {}", event.getUei(), url, clabel, user);
    }
}
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 7 with EventHandler

use of org.opennms.netmgt.events.api.annotations.EventHandler in project opennms by OpenNMS.

the class SnmpPoller method reloadSnmpConfig.

/**
 * <p>reloadSnmpConfig</p>
 *
 * @param event a {@link org.opennms.netmgt.xml.event.Event} object.
 */
@EventHandler(uei = EventConstants.CONFIGURE_SNMP_EVENT_UEI)
public void reloadSnmpConfig(Event event) {
    LOG.debug("reloadSnmpConfig: managing event: {}", event.getUei());
    try {
        Thread.sleep(5000);
    } catch (final InterruptedException e) {
        LOG.debug("interrupted while waiting for reload", e);
        Thread.currentThread().interrupt();
    }
    SnmpEventInfo info = null;
    try {
        info = new SnmpEventInfo(event);
        if (StringUtils.isBlank(info.getFirstIPAddress())) {
            LOG.error("configureSNMPHandler: event contained invalid firstIpAddress. {}", event);
            return;
        }
    } catch (final Throwable e) {
        LOG.error("reloadSnmpConfig: ", e);
        return;
    }
    final IPAddressRange range = new IPAddressRange(info.getFirstIPAddress(), info.getLastIPAddress());
    for (final IPAddress ipaddr : range) {
        LOG.debug("reloadSnmpConfig: found ipaddr: {}", ipaddr);
        if (getNetwork().hasPollableInterface(ipaddr.toDbString())) {
            LOG.debug("reloadSnmpConfig: recreating the Interface to poll: {}", ipaddr);
            getNetwork().delete(ipaddr.toDbString());
            scheduleNewSnmpInterface(ipaddr.toDbString());
        } else {
            LOG.debug("reloadSnmpConfig: no Interface found for ipaddr: {}", ipaddr);
        }
    }
}
Also used : SnmpEventInfo(org.opennms.netmgt.config.SnmpEventInfo) IPAddressRange(org.opennms.core.network.IPAddressRange) IPAddress(org.opennms.core.network.IPAddress) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler)

Example 8 with EventHandler

use of org.opennms.netmgt.events.api.annotations.EventHandler in project opennms by OpenNMS.

the class Tl1d method handleRelooadConfigurationEvent.

/**
 * <p>handleRelooadConfigurationEvent</p>
 *
 * @param e a {@link org.opennms.netmgt.xml.event.Event} object.
 */
@EventHandler(uei = EventConstants.RELOAD_DAEMON_CONFIG_UEI)
public void handleRelooadConfigurationEvent(Event e) {
    if (isReloadConfigEventTarget(e)) {
        EventBuilder ebldr = null;
        try {
            stopListeners();
            removeClients();
            /*
                 * leave everything currently on the queue, no need to mess with that, might want a handler
                 * someday for emptying the current queue on a reload event or even a pause clients or something.
                 * 
                 * Don't interrupt message processor, it simply waits on the queue from something to be added.
                 * 
                 */
            m_configurationDao.update();
            initializeTl1Connections();
            startClients();
            LOG.debug("handleReloadConfigurationEvent: {} defined.", m_tl1Clients.size());
            LOG.info("handleReloadConfigurationEvent: completed.");
            ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, getName());
            ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Tl1d");
        } catch (Throwable exception) {
            LOG.error("handleReloadConfigurationEvent: failed.", exception);
            ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI, getName());
            ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Tl1d");
            ebldr.addParam(EventConstants.PARM_REASON, exception.getLocalizedMessage().substring(1, 128));
        }
        if (ebldr != null) {
            m_eventForwarder.sendNow(ebldr.getEvent());
        }
    }
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler)

Example 9 with EventHandler

use of org.opennms.netmgt.events.api.annotations.EventHandler in project opennms by OpenNMS.

the class Provisioner method handleNodeUpdated.

/**
 * <p>handleNodeUpdated</p>
 * A re-import has occurred, attempt a rescan now.
 *
 * @param e a {@link org.opennms.netmgt.xml.event.Event} object.
 */
@EventHandler(uei = EventConstants.NODE_UPDATED_EVENT_UEI)
public void handleNodeUpdated(Event e) {
    LOG.debug("Node updated event received: {}", e);
    if (!Boolean.valueOf(System.getProperty(SCHEDULE_RESCAN_FOR_UPDATED_NODES, "true"))) {
        LOG.debug("Rescanning updated nodes is disabled via property: {}", SCHEDULE_RESCAN_FOR_UPDATED_NODES);
        return;
    }
    // Default
    String rescanExisting = Boolean.TRUE.toString();
    for (Parm parm : e.getParmCollection()) {
        if (EventConstants.PARM_RESCAN_EXISTING.equals(parm.getParmName()) && ("false".equalsIgnoreCase(parm.getValue().getContent()) || "dbonly".equalsIgnoreCase(parm.getValue().getContent()))) {
            rescanExisting = Boolean.FALSE.toString();
        }
    }
    if (!Boolean.valueOf(rescanExisting)) {
        LOG.debug("Rescanning updated nodes is disabled via event parameter: {}", EventConstants.PARM_RESCAN_EXISTING);
        return;
    }
    removeNodeFromScheduleQueue(new Long(e.getNodeid()).intValue());
    NodeScanSchedule scheduleForNode = getProvisionService().getScheduleForNode(e.getNodeid().intValue(), true);
    if (scheduleForNode != null) {
        addToScheduleQueue(scheduleForNode);
    }
}
Also used : Parm(org.opennms.netmgt.xml.event.Parm) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler)

Example 10 with EventHandler

use of org.opennms.netmgt.events.api.annotations.EventHandler in project opennms by OpenNMS.

the class InterfaceToNodeCacheEventProcessor method handleNodeGainedInterface.

@EventHandler(uei = EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI)
@Transactional
public void handleNodeGainedInterface(Event event) {
    LOG.debug("Received event: {}", event.getUei());
    Long nodeId = event.getNodeid();
    if (nodeId == null) {
        LOG.error(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI + ": Event with no node ID: " + event.toString());
        return;
    }
    OnmsNode node = m_nodeDao.get(nodeId.intValue());
    if (node == null) {
        LOG.warn(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI + ": Cannot find node in DB: " + nodeId);
        return;
    }
    // add to known nodes
    m_cache.setNodeId(node.getLocation().getLocationName(), event.getInterfaceAddress(), nodeId.intValue());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

EventHandler (org.opennms.netmgt.events.api.annotations.EventHandler)23 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)9 Parm (org.opennms.netmgt.xml.event.Parm)8 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ExecutionException (java.util.concurrent.ExecutionException)2 Task (org.opennms.core.tasks.Task)2 Value (org.opennms.netmgt.xml.event.Value)2 Method (java.lang.reflect.Method)1 InetAddress (java.net.InetAddress)1 ParseException (java.text.ParseException)1 IPAddress (org.opennms.core.network.IPAddress)1 IPAddressRange (org.opennms.core.network.IPAddressRange)1 RancidAdapterConfigFactory (org.opennms.netmgt.config.RancidAdapterConfigFactory)1 SnmpEventInfo (org.opennms.netmgt.config.SnmpEventInfo)1 OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)1 Event (org.opennms.netmgt.xml.event.Event)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1