Search in sources :

Example 1 with EventHandler

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

the class Bsmd method handleAlarmLifecycleEvents.

@EventHandler(ueis = { EventConstants.ALARM_CREATED_UEI, EventConstants.ALARM_ESCALATED_UEI, EventConstants.ALARM_CLEARED_UEI, EventConstants.ALARM_UNCLEARED_UEI, EventConstants.ALARM_UPDATED_WITH_REDUCED_EVENT_UEI, EventConstants.ALARM_DELETED_EVENT_UEI })
public void handleAlarmLifecycleEvents(Event e) {
    if (e == null || !m_hasBusinessServicesDefined) {
        // in which case we don't need to perform any further handling
        return;
    }
    final Parm alarmIdParm = e.getParm(EventConstants.PARM_ALARM_ID);
    if (alarmIdParm == null || alarmIdParm.getValue() == null) {
        LOG.warn("The alarmId parameter has no value on event with uei: {}. Ignoring.", e.getUei());
        return;
    }
    int alarmId;
    try {
        alarmId = Integer.parseInt(alarmIdParm.getValue().getContent());
    } catch (NumberFormatException ee) {
        LOG.warn("Failed to retrieve the alarmId for event with uei: {}. Ignoring.", e.getUei(), ee);
        return;
    }
    if (EventConstants.ALARM_DELETED_EVENT_UEI.equals(e.getUei())) {
        handleAlarmDeleted(e, alarmId);
    } else {
        handleAlarmCreatedOrUpdated(e, alarmId);
    }
}
Also used : Parm(org.opennms.netmgt.xml.event.Parm) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler)

Example 2 with EventHandler

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

the class Ackd method handleAckEvent.

/**
 * Handles the event driven access to acknowledging <code>OnmsAcknowledgable</code>s.  The acknowledgment event
 * contains 4 parameters:
 *     ackUser: The user acknowledging the <code>OnmsAcknowledgable</code>
 *     ackAction: ack, unack, esc, clear
 *     ackType: <code>AckType</code. representing either an <code>OnmsAlarm</code>, <code>OnmsNotification</code>, etc.
 *     refId: The ID of the <code>OnmsAcknowledgable</code>
 *
 * @param event a {@link org.opennms.netmgt.xml.event.Event} object.
 */
@EventHandler(uei = EventConstants.ACKNOWLEDGE_EVENT_UEI)
public void handleAckEvent(Event event) {
    LOG.info("handleAckEvent: Received acknowledgment event: {}", event);
    OnmsAcknowledgment ack;
    try {
        ack = new OnmsAcknowledgment(event);
        m_ackDao.processAck(ack);
    } catch (ParseException e) {
        LOG.error("handleAckEvent: unable to process acknowledgment event: {}", event, e);
    }
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) ParseException(java.text.ParseException) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler)

Example 3 with EventHandler

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

the class Ackd method handleReloadConfigEvent.

/**
 * <p>handleReloadConfigEvent</p>
 *
 * @param event a {@link org.opennms.netmgt.xml.event.Event} object.
 */
@EventHandler(uei = EventConstants.RELOAD_DAEMON_CONFIG_UEI)
public void handleReloadConfigEvent(Event event) {
    String specifiedDaemon = null;
    LOG.info("handleReloadConfigEvent: processing reload event: {}", event);
    List<Parm> parms = event.getParmCollection();
    for (Parm parm : parms) {
        specifiedDaemon = parm.getValue().getContent();
        if (EventConstants.PARM_DAEMON_NAME.equals(parm.getParmName()) && getName().equalsIgnoreCase(specifiedDaemon)) {
            LOG.debug("handleReloadConfigEvent: reload event is for this daemon: {}; reloading configuration...", getName());
            try {
                m_configDao.reloadConfiguration();
                EventBuilder bldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, getName(), Calendar.getInstance().getTime());
                bldr.addParam(EventConstants.PARM_DAEMON_NAME, getName());
                m_eventForwarder.sendNow(bldr.getEvent());
                LOG.debug("handleReloadConfigEvent: restarting readers due to reload configuration event...");
                this.restartReaders(true);
            } catch (Throwable e) {
                LOG.error("handleReloadConfigEvent: ", e);
                EventBuilder bldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI, getName(), Calendar.getInstance().getTime());
                bldr.addParam(EventConstants.PARM_DAEMON_NAME, getName());
                bldr.addParam(EventConstants.PARM_REASON, e.getLocalizedMessage().substring(0, 128));
                m_eventForwarder.sendNow(bldr.getEvent());
            }
            LOG.debug("handleReloadConfigEvent: configuration reloaded.");
            // return here because we are done.
            return;
        }
    }
    LOG.debug("handleReloadConfigEvent: reload event not for this daemon: {}; daemon specified is: {}", getName(), specifiedDaemon);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Parm(org.opennms.netmgt.xml.event.Parm) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler)

Example 4 with EventHandler

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

the class RancidProvisioningAdapter method handleReloadConfigEvent.

/**
 * <p>handleReloadConfigEvent</p>
 *
 * @param event a {@link org.opennms.netmgt.xml.event.Event} object.
 */
@EventHandler(uei = EventConstants.RELOAD_DAEMON_CONFIG_UEI)
public void handleReloadConfigEvent(Event event) {
    if (isReloadConfigEventTarget(event)) {
        EventBuilder ebldr = null;
        LOG.debug("reloading the rancid adapter configuration");
        try {
            RancidAdapterConfigFactory.init();
            final RancidAdapterConfigFactory factory = RancidAdapterConfigFactory.getInstance();
            factory.getWriteLock().lock();
            try {
                factory.update();
                m_template.execute(new TransactionCallbackWithoutResult() {

                    @Override
                    public void doInTransactionWithoutResult(TransactionStatus arg0) {
                        buildRancidNodeMap();
                    }
                });
            } finally {
                factory.getWriteLock().unlock();
            }
            ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, "Provisiond.RancidProvisioningAdapter");
            ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Provisiond.RancidProvisioningAdapter");
        } catch (Throwable e) {
            LOG.info("unable to reload rancid adapter configuration", e);
            ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI, "Provisiond.RancidProvisioningAdapter");
            ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Provisiond.RancidProvisioningAdapter");
            ebldr.addParam(EventConstants.PARM_REASON, e.getLocalizedMessage().substring(1, 128));
        }
        if (ebldr != null) {
            getEventForwarder().sendNow(ebldr.getEvent());
        }
    }
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) RancidAdapterConfigFactory(org.opennms.netmgt.config.RancidAdapterConfigFactory) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler)

Example 5 with EventHandler

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

the class Reportd method handleRunReportEvent.

/**
 * <p>handleRunReportEvent</p>
 *
 * @param e a {@link org.opennms.netmgt.xml.event.Event} object.
 */
@EventHandler(uei = EventConstants.REPORTD_RUN_REPORT)
public void handleRunReportEvent(Event e) {
    String reportName = "";
    for (Parm parm : e.getParmCollection()) {
        if (EventConstants.PARM_REPORT_NAME.equals(parm.getParmName()))
            reportName = parm.getValue().getContent();
        else
            LOG.info("Unknown Event Constant: {}", parm.getParmName());
    }
    if (!"".equals(reportName)) {
        LOG.debug("running report {}", reportName);
        runReport(reportName);
    } else {
        LOG.error("Can not run report -- reportName not specified");
    }
}
Also used : Parm(org.opennms.netmgt.xml.event.Parm) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler)

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