Search in sources :

Example 11 with EventProxy

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

the class SnmpCollector method collect.

/**
     * {@inheritDoc}
     *
     * Perform data collection.
     */
@Override
public CollectionSet collect(CollectionAgent agent, Map<String, Object> parameters) throws CollectionException {
    try {
        ((SnmpCollectionAgent) agent).validateAgent();
        final ServiceParameters params = new ServiceParameters(parameters);
        params.logIfAliasConfig();
        if (m_client == null) {
            m_client = BeanUtils.getBean("daoContext", "locationAwareSnmpClient", LocationAwareSnmpClient.class);
        }
        OnmsSnmpCollection snmpCollection = new OnmsSnmpCollection((SnmpCollectionAgent) agent, params, m_client);
        final EventProxy eventProxy = EventIpcManagerFactory.getIpcManager();
        final ForceRescanState forceRescanState = new ForceRescanState(agent, eventProxy);
        SnmpCollectionSet collectionSet = snmpCollection.createCollectionSet((SnmpCollectionAgent) agent);
        collectionSet.setCollectionTimestamp(new Date());
        if (!collectionSet.hasDataToCollect()) {
            LOG.info("agent {} defines no data to collect.  Skipping.", agent);
        // should we return here?
        }
        collectionSet.collect();
        /*
             * FIXME: Should we even be doing this? I say we get rid of this force rescan thingie
             * {@see http://issues.opennms.org/browse/NMS-1057}
             */
        if (System.getProperty("org.opennms.netmgt.collectd.SnmpCollector.forceRescan", "false").equalsIgnoreCase("true") && collectionSet.rescanNeeded()) {
            /*
                 * TODO: the behavior of this object may have been re-factored away.
                 * Verify that this is correct and remove this unused object if it
                 * is no longer needed.  My gut thinks this should be investigated.
                 */
            forceRescanState.rescanIndicated();
        } else {
            collectionSet.checkForSystemRestart();
        }
        return collectionSet;
    } catch (CollectionException e) {
        throw e;
    } catch (Throwable t) {
        throw new CollectionException("Unexpected error during node SNMP collection for: " + agent.getHostAddress(), t);
    }
}
Also used : LocationAwareSnmpClient(org.opennms.netmgt.snmp.proxy.LocationAwareSnmpClient) CollectionException(org.opennms.netmgt.collection.api.CollectionException) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) EventProxy(org.opennms.netmgt.events.api.EventProxy) Date(java.util.Date)

Aggregations

EventProxy (org.opennms.netmgt.events.api.EventProxy)11 TcpEventProxy (org.opennms.netmgt.events.api.support.TcpEventProxy)7 InetSocketAddress (java.net.InetSocketAddress)5 Test (org.junit.Test)4 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)4 InetAddress (java.net.InetAddress)3 ServletException (javax.servlet.ServletException)3 RequestDispatcher (javax.servlet.RequestDispatcher)2 Ignore (org.junit.Ignore)2 Event (org.opennms.netmgt.xml.event.Event)2 Events (org.opennms.netmgt.xml.event.Events)2 Log (org.opennms.netmgt.xml.event.Log)2 Transactional (org.springframework.transaction.annotation.Transactional)2 StringWriter (java.io.StringWriter)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 UnknownHostException (java.net.UnknownHostException)1 Date (java.util.Date)1 HttpSession (javax.servlet.http.HttpSession)1 CollectionException (org.opennms.netmgt.collection.api.CollectionException)1 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)1