Search in sources :

Example 16 with EventHandler

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

the class SnmpHardwareInventoryProvisioningAdapter method handleReloadConfigEvent.

/**
 * Handle reload configuration event.
 *
 * @param event the event
 */
@EventHandler(uei = EventConstants.RELOAD_DAEMON_CONFIG_UEI)
public void handleReloadConfigEvent(final Event event) {
    if (isReloadConfigEventTarget(event)) {
        EventBuilder ebldr = null;
        LOG.debug("Reloading the Hardware Inventory adapter configuration");
        try {
            m_hwInventoryAdapterConfigDao.reload();
            initializeVendorAttributes();
            ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, PREFIX + NAME);
            ebldr.addParam(EventConstants.PARM_DAEMON_NAME, PREFIX + NAME);
        } catch (Throwable e) {
            LOG.warn("Unable to reload Hardware Inventory adapter configuration", e);
            ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI, PREFIX + NAME);
            ebldr.addParam(EventConstants.PARM_DAEMON_NAME, PREFIX + NAME);
            ebldr.addParam(EventConstants.PARM_REASON, e.getMessage());
        }
        if (ebldr != null) {
            getEventForwarder().sendNow(ebldr.getEvent());
        }
    }
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler)

Example 17 with EventHandler

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

the class Provisioner method handleNewSuspectEvent.

@EventHandler(uei = EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI)
public void handleNewSuspectEvent(Event e) {
    final Event event = e;
    final String uei = e.getUei();
    final String ip = e.getInterface();
    final Map<String, String> paramMap = Maps.newHashMap();
    e.getParmCollection().forEach(eachParam -> paramMap.put(eachParam.getParmName(), eachParam.getValue().getContent()));
    if (ip == null) {
        LOG.error("Received a {} event with a null ipAddress", uei);
        return;
    }
    if (!getProvisionService().isDiscoveryEnabled()) {
        LOG.info("Ignoring {} event for ip {} since discovery handling is disabled in provisiond", uei, ip);
        return;
    }
    Runnable r = new Runnable() {

        @Override
        public void run() {
            try {
                final InetAddress addr = addr(ip);
                if (addr == null) {
                    LOG.error("Unable to convert {} to an InetAddress.", ip);
                    return;
                }
                final String location;
                if (paramMap.containsKey("location")) {
                    location = paramMap.get("location");
                } else if (event.getDistPoller() != null) {
                    location = monitoringSystemDao.get(event.getDistPoller()).getLocation();
                } else {
                    location = MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID;
                }
                final String foreignSource = paramMap.get("foreignSource");
                LOG.debug("Triggering new suspect scan for: {} at location: {} with foreign source: {}.", addr, location, foreignSource);
                final NewSuspectScan scan = createNewSuspectScan(addr, foreignSource, location);
                Task t = scan.createTask();
                t.schedule();
                t.waitFor();
            } catch (InterruptedException ex) {
                LOG.error("Task interrupted waiting for new suspect scan of {} to finish", ip, ex);
            } catch (ExecutionException ex) {
                LOG.error("An expected execution occurred waiting for new suspect scan of {} to finish", ip, ex);
            }
        }
    };
    m_scheduledExecutor.execute(r);
}
Also used : Task(org.opennms.core.tasks.Task) Event(org.opennms.netmgt.xml.event.Event) ExecutionException(java.util.concurrent.ExecutionException) InetAddress(java.net.InetAddress) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler)

Example 18 with EventHandler

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

the class Provisioner method handleReloadConfigEvent.

/**
 * <p>handleReloadConfigEvent</p>
 *
 * @param e a {@link org.opennms.netmgt.xml.event.Event} object.
 */
@EventHandler(uei = EventConstants.RELOAD_DAEMON_CONFIG_UEI)
public void handleReloadConfigEvent(Event e) {
    if (isReloadConfigEventTarget(e)) {
        LOG.info("handleReloadConfigEvent: reloading configuration...");
        EventBuilder ebldr = null;
        try {
            LOG.debug("handleReloadConfigEvent: lock acquired, unscheduling current reports...");
            m_importSchedule.rebuildImportSchedule();
            LOG.debug("handleRelodConfigEvent: reports rescheduled.");
            ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, "Provisiond");
            ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Provisiond");
        } catch (Throwable exception) {
            LOG.error("handleReloadConfigurationEvent: Error reloading configuration", exception);
            ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI, "Provisiond");
            ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Provisiond");
            ebldr.addParam(EventConstants.PARM_REASON, exception.getLocalizedMessage().substring(1, 128));
        }
        if (ebldr != null) {
            m_eventForwarder.sendNow(ebldr.getEvent());
        }
        LOG.info("handleReloadConfigEvent: configuration reloaded.");
    }
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler)

Example 19 with EventHandler

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

the class Provisioner method handleForceRescan.

/**
 * <p>handleForceRescan</p>
 *
 * @param e a {@link org.opennms.netmgt.xml.event.Event} object.
 */
@EventHandler(uei = EventConstants.FORCE_RESCAN_EVENT_UEI)
public void handleForceRescan(Event e) {
    final Integer nodeId = new Integer(e.getNodeid().intValue());
    removeNodeFromScheduleQueue(nodeId);
    Runnable r = new Runnable() {

        @Override
        public void run() {
            try {
                ForceRescanScan scan = createForceRescanScan(nodeId);
                Task t = scan.createTask();
                t.schedule();
                t.waitFor();
                // It has 'false' because a node scan was already executed by ForceRescanScan.
                NodeScanSchedule scheduleForNode = getProvisionService().getScheduleForNode(nodeId, false);
                if (scheduleForNode != null) {
                    addToScheduleQueue(scheduleForNode);
                }
            } catch (InterruptedException ex) {
                LOG.error("Task interrupted waiting for rescan of nodeId {} to finish", nodeId, ex);
            } catch (ExecutionException ex) {
                LOG.error("An expected execution occurred waiting for rescan of nodeId {} to finish", nodeId, ex);
            }
        }
    };
    m_scheduledExecutor.execute(r);
}
Also used : Task(org.opennms.core.tasks.Task) ExecutionException(java.util.concurrent.ExecutionException) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler)

Example 20 with EventHandler

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

the class Reportd method handleReloadConfigEvent.

/**
 * <p>handleReloadConfigEvent</p>
 *
 * @param e a {@link org.opennms.netmgt.xml.event.Event} object.
 */
@EventHandler(uei = EventConstants.RELOAD_DAEMON_CONFIG_UEI)
public void handleReloadConfigEvent(Event e) {
    if (isReloadConfigEventTarget(e)) {
        LOG.info("handleReloadConfigEvent: reloading configuration...");
        EventBuilder ebldr = null;
        try {
            reportDirectory = m_reportConfigurationDao.getStorageDirectory();
            LOG.debug("handleReloadConfigEvent: lock acquired, unscheduling current reports...");
            m_reportScheduler.rebuildReportSchedule();
            LOG.debug("handleReloadConfigEvent: reports rescheduled.");
            m_reportDeliveryService.reloadConfiguration();
            LOG.debug("handleReloadConfigEvent: Configuration reloaded for report delivery service {}", m_reportDeliveryService.getClass().getName());
            ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, "Reportd");
            ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Reportd");
        } catch (Throwable ex) {
            LOG.error("handleReloadConfigurationEvent: Error reloading configuration: {}", ex.getMessage(), ex);
            ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI, "Reportd");
            ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Reportd");
            ebldr.addParam(EventConstants.PARM_REASON, ex.getLocalizedMessage().substring(1, 128));
        }
        if (ebldr != null) {
            getEventForwarder().sendNow(ebldr.getEvent());
        }
        LOG.info("handleReloadConfigEvent: configuration reloaded.");
    }
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) 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