Search in sources :

Example 41 with ServiceParameters

use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.

the class MockCollectionResource method visit.

@Override
public void visit(CollectionSetVisitor visitor) {
    for (Entry<String, String> entry : attributes.entrySet()) {
        final CollectionResource resource = this;
        final String attrName = entry.getKey();
        final String attrValue = entry.getValue();
        CollectionAttribute attribute = new CollectionAttribute() {

            @Override
            public CollectionResource getResource() {
                return resource;
            }

            @Override
            public String getStringValue() {
                return attrValue;
            }

            @Override
            public Double getNumericValue() {
                try {
                    return Double.parseDouble(attrValue);
                } catch (NumberFormatException | NullPointerException e) {
                    return null;
                }
            }

            @Override
            public String getName() {
                return attrName;
            }

            @Override
            public void storeAttribute(Persister persister) {
            }

            @Override
            public boolean shouldPersist(ServiceParameters params) {
                return true;
            }

            @Override
            public CollectionAttributeType getAttributeType() {
                return null;
            }

            @Override
            public void visit(CollectionSetVisitor visitor) {
            }

            @Override
            public AttributeType getType() {
                return AttributeType.STRING;
            }

            @Override
            public String getMetricIdentifier() {
                return "MOCK_" + getName();
            }
        };
        visitor.visitAttribute(attribute);
    }
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) Persister(org.opennms.netmgt.collection.api.Persister) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters)

Example 42 with ServiceParameters

use of org.opennms.netmgt.collection.api.ServiceParameters 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

ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)42 HashMap (java.util.HashMap)27 Test (org.junit.Test)18 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)17 CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)14 MockDataCollectionConfig (org.opennms.netmgt.mock.MockDataCollectionConfig)14 File (java.io.File)10 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)10 OnmsSnmpCollection (org.opennms.netmgt.collectd.OnmsSnmpCollection)9 MibObject (org.opennms.netmgt.config.datacollection.MibObject)9 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)7 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)7 RrdDb (org.jrobin.core.RrdDb)6 NodeResourceType (org.opennms.netmgt.collectd.NodeResourceType)6 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)6 Datasource (org.jrobin.core.Datasource)5 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)5 SnmpCollectionResource (org.opennms.netmgt.collectd.SnmpCollectionResource)5 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)5 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)4