Search in sources :

Example 1 with CollectionJob

use of org.opennms.nrtg.api.model.CollectionJob in project opennms by OpenNMS.

the class CollectionJobListener method onMessage.

@Override
public void onMessage(Message message) {
    try {
        // FIXME abstraction between technology and job handling is missing
        CollectionJob collectionJob = (CollectionJob) simpleMessageConverter.fromMessage(message);
        collectionJob = protocolCollectorRegistry.getProtocolCollector(collectionJob.getService()).collect(collectionJob);
        Date finishedTimestamp = new Date();
        collectionJob.setFinishedTimestamp(finishedTimestamp);
        Map<String, MeasurementSet> measurementSets = collectionJob.getMeasurementSetsByDestination();
        int val = counter.incrementAndGet();
        if (val % 1000 == 0) {
            logger.debug("processed job #{}, {} measurement set(s)", val, measurementSets.size());
        } else {
            logger.trace("processed job #{}, {} measurement set(s)", val, measurementSets.size());
        }
        for (String destinationString : measurementSets.keySet()) {
            jmsTemplate.convertAndSend(destinationString, measurementSets.get(destinationString));
            logger.info("** sending msg '{}' to '{}'", measurementSets.get(destinationString), destinationString);
        }
        LightweightMeasurementSet errorMeasurementSet = new LightweightMeasurementSet(collectionJob.getNodeId(), collectionJob.getService(), collectionJob.getNetInterface(), collectionJob.getFinishedTimestamp());
        for (String metricId : collectionJob.getAllMetrics()) {
            if (collectionJob.getMetricValue(metricId) == null) {
                errorMeasurementSet.addMeasurement(metricId, collectionJob.getMetricType(metricId), null, collectionJob.getOnmsLogicMetricId(metricId));
            }
            logger.trace("collected metric of job #{}='{}'", counter + ": " + metricId, collectionJob.getMetricValue(metricId));
        }
        if (errorMeasurementSet.getMeasurements().size() > 0) {
            logger.warn("result set of job #{} contains {} null values", counter, errorMeasurementSet.getMeasurements().size());
            jmsTemplate.convertAndSend("error", errorMeasurementSet);
            logger.trace("** sending to 'error'");
        }
    } catch (JMSException ex) {
        logger.error(ex.getMessage());
    // FIXME react, don't continue
    } catch (MessageConversionException ex) {
        logger.error(ex.getMessage());
    // FIXME react, don't continue
    }
}
Also used : MessageConversionException(org.springframework.jms.support.converter.MessageConversionException) CollectionJob(org.opennms.nrtg.api.model.CollectionJob) JMSException(javax.jms.JMSException) Date(java.util.Date) MeasurementSet(org.opennms.nrtg.api.model.MeasurementSet) LightweightMeasurementSet(org.opennms.nrtg.api.model.LightweightMeasurementSet) LightweightMeasurementSet(org.opennms.nrtg.api.model.LightweightMeasurementSet)

Example 2 with CollectionJob

use of org.opennms.nrtg.api.model.CollectionJob in project opennms by OpenNMS.

the class SnmpProtocolCollectorTest method testCollect.

@Test
public void testCollect() {
    collectionJob.setService("SNMP");
    collectionJob.setNodeId(1);
    collectionJob.setNetInterface(localhost.getHostAddress());
    collectionJob.addMetric(testMetric, destinations, "OnmsLocicMetricId");
    collectionJob.setId("testing");
    CollectionJob result = protocolCollector.collect(collectionJob);
    Assert.assertEquals(result.getService(), "SNMP");
    Assert.assertEquals(result.getMetricValue(testMetric), testMetricValue);
}
Also used : DefaultCollectionJob(org.opennms.nrtg.api.model.DefaultCollectionJob) CollectionJob(org.opennms.nrtg.api.model.CollectionJob) Test(org.junit.Test)

Example 3 with CollectionJob

use of org.opennms.nrtg.api.model.CollectionJob in project opennms by OpenNMS.

the class PooledJobPublisher method createTestJob.

private CollectionJob createTestJob() {
    if (this.job == null) {
        TreeSet<String> destinationSet = new TreeSet<String>();
        destinationSet.add("NrtResults");
        CollectionJob snmpJob = new DefaultCollectionJob();
        snmpJob.addMetric(".1.3.6.1.4.1.2021.9.1.9.1", destinationSet, "DummyName");
        //            snmpJob.addMetric(".1.3.6.1.2.1.2.2.1.10.1", destinationSet);
        //            snmpJob.addMetric(".1.3.6.1.2.1.2.2.1.10.2", destinationSet);
        //            snmpJob.addMetric(".1.3.6.1.2.1.2.2.1.10.4", destinationSet);
        //            snmpJob.addMetric(".1.3.6.1.2.1.2.2.1.10.5", destinationSet);
        //            snmpJob.addMetric(".1.3.6.1.2.1.2.2.1.10.6", destinationSet);
        //            snmpJob.addMetric(".1.3.6.1.2.1.2.2.1.10.7", destinationSet);
        //            snmpJob.addMetric(".1.3.6.1.2.1.2.2.1.10.8", destinationSet);
        //            snmpJob.addMetric(".1.3.6.1.2.1.2.2.1.10.9", destinationSet);
        //            snmpJob.addMetric(".1.3.6.1.2.1.2.2.1.10.10", destinationSet);
        //            snmpJob.addMetric(".1.3.6.1.2.1.2.2.1.10.11", destinationSet);
        //            destinationSet.add("NrtPersister");
        //            snmpJob.addMetric(".1.3.6.1.2.1.2.2.1.10.11", destinationSet);
        snmpJob.setNetInterface("127.0.0.1");
        snmpJob.setService("SNMP");
        this.job = snmpJob;
    }
    return this.job;
}
Also used : CollectionJob(org.opennms.nrtg.api.model.CollectionJob) DefaultCollectionJob(org.opennms.nrtg.api.model.DefaultCollectionJob) TreeSet(java.util.TreeSet) DefaultCollectionJob(org.opennms.nrtg.api.model.DefaultCollectionJob)

Example 4 with CollectionJob

use of org.opennms.nrtg.api.model.CollectionJob in project opennms by OpenNMS.

the class TcaProtocolCollectorTest method testCollectWithCompountMertic.

@Test
public void testCollectWithCompountMertic() {
    final String testMetric = ".1.3.6.1.4.1.27091.3.1.6.1.2.171.19.37.60_inboundDelay";
    final String testMetricValue = "12";
    collectionJob.setService("TCA");
    collectionJob.setNodeId(1);
    collectionJob.setNetInterface(localhost.getHostAddress());
    collectionJob.addMetric(testMetric, destinations, "OnmsLocicMetricId");
    collectionJob.setId("testing");
    CollectionJob result = protocolCollector.collect(collectionJob);
    Assert.assertNotNull(result);
    Assert.assertEquals(result.getMetricValue(testMetric), testMetricValue);
}
Also used : DefaultCollectionJob(org.opennms.nrtg.api.model.DefaultCollectionJob) CollectionJob(org.opennms.nrtg.api.model.CollectionJob) Test(org.junit.Test)

Example 5 with CollectionJob

use of org.opennms.nrtg.api.model.CollectionJob in project opennms by OpenNMS.

the class NrtController method nrtStart.

public ModelAndView nrtStart(ResourceId resourceId, String report, HttpSession httpSession) {
    assert (resourceId != null);
    logger.debug("resourceId: '{}'", resourceId);
    assert (report != null);
    logger.debug("report: '{}'", report);
    OnmsResource reportResource = m_resourceDao.getResourceById(resourceId);
    PrefabGraph prefabGraph = m_graphDao.getPrefabGraph(report);
    String nrtCollectionTaskId = String.format("NrtCollectionTaskId_%d_%d", System.currentTimeMillis(), new Random().nextInt());
    List<CollectionJob> collectionJobs = createCollectionJobs(reportResource, prefabGraph, nrtCollectionTaskId);
    for (CollectionJob collectionJob : collectionJobs) {
        m_nrtBroker.publishCollectionJob(collectionJob);
        getCollectionJobMap(httpSession, true).put(nrtCollectionTaskId, collectionJob);
    }
    ModelAndView modelAndView = new ModelAndView("nrt/realtime.json");
    modelAndView.addObject("nrtCollectionTaskId", nrtCollectionTaskId);
    modelAndView.addObject("graphTitle", prefabGraph.getTitle());
    modelAndView.addObject("graphName", prefabGraph.getName());
    modelAndView.addObject("graphDescription", prefabGraph.getDescription());
    NrtHelper nrtHelper = new NrtHelper();
    modelAndView.addObject("rrdGraphString", nrtHelper.cleanUpRrdGraphStringForWebUi(prefabGraph, getRequiredExternalPropertyAttributes(reportResource, prefabGraph), getRequiredStringPropertyAttributes(reportResource, prefabGraph)));
    Set<RrdGraphAttribute> relevantRrdGraphAttributes = getRequiredRrdGraphAttributes(reportResource, prefabGraph);
    Map<String, String> rrdGraphAttributesMetaData = getMetaDataForReport(relevantRrdGraphAttributes);
    Map<String, String> rrdGraphAttributesToMetricIds = getRrdGraphAttributesToMetricIds(rrdGraphAttributesMetaData);
    modelAndView.addObject("metricsMapping", nrtHelper.generateJsMappingObject(prefabGraph.getCommand(), rrdGraphAttributesToMetricIds));
    return modelAndView;
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) Random(java.util.Random) DefaultCollectionJob(org.opennms.nrtg.api.model.DefaultCollectionJob) CollectionJob(org.opennms.nrtg.api.model.CollectionJob) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute)

Aggregations

CollectionJob (org.opennms.nrtg.api.model.CollectionJob)8 DefaultCollectionJob (org.opennms.nrtg.api.model.DefaultCollectionJob)7 Date (java.util.Date)2 Test (org.junit.Test)2 OnmsResource (org.opennms.netmgt.model.OnmsResource)2 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 TreeSet (java.util.TreeSet)1 JMSException (javax.jms.JMSException)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)1 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)1 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)1 LightweightMeasurementSet (org.opennms.nrtg.api.model.LightweightMeasurementSet)1