use of org.opennms.netmgt.measurements.model.QueryRequest in project opennms by OpenNMS.
the class MeasurementsRestServiceITCase method canRetrieveNoMeasurementsInRelaxedMode.
@Test
public void canRetrieveNoMeasurementsInRelaxedMode() throws Exception {
// Enable relaxed mode
QueryRequest request = new QueryRequest();
request.setRelaxed(true);
request.setStart(1414602000000L);
request.setEnd(1417046400000L);
request.setStep(1000L);
request.setMaxRows(700);
// Query for some attribute that doesn't exist, on an existing resource
Source notIfInOctetsAvg = new Source();
notIfInOctetsAvg.setResourceId("node[1].interfaceSnmp[eth0-04013f75f101]");
notIfInOctetsAvg.setAttribute("notIfInOctets");
notIfInOctetsAvg.setAggregation("AVERAGE");
notIfInOctetsAvg.setLabel("notIfInOctets");
request.setSources(Lists.newArrayList(notIfInOctetsAvg));
// Perform the query
try {
m_svc.query(request);
fail("HTTP 204 exception expected.");
} catch (WebApplicationException ex) {
assertEquals(204, ex.getResponse().getStatus());
}
}
use of org.opennms.netmgt.measurements.model.QueryRequest in project opennms by OpenNMS.
the class MeasurementsRestServiceITCase method notFoundOnMissingResource.
@Test
public void notFoundOnMissingResource() {
final QueryRequest request = buildRequest();
request.getSources().get(0).setResourceId("node[99].interfaceSnmp[eth0-04013f75f101]");
exception.expect(exceptionWithResponseCode(404));
m_svc.query(request);
}
use of org.opennms.netmgt.measurements.model.QueryRequest in project opennms by OpenNMS.
the class MeasurementsRestServiceITCase method canRetrieveFallbackAttributeWhenAttributeNotFound.
@Test
public void canRetrieveFallbackAttributeWhenAttributeNotFound() {
QueryRequest request = new QueryRequest();
request.setStart(1414602000000L);
request.setEnd(1417046400000L);
request.setStep(1000L);
request.setMaxRows(700);
// Average
Source ifInOctetsAvg = new Source();
ifInOctetsAvg.setResourceId("node[1].interfaceSnmp[eth0-04013f75f101]");
ifInOctetsAvg.setAttribute("willNotBeFound");
ifInOctetsAvg.setFallbackAttribute("ifInOctets");
ifInOctetsAvg.setAggregation("AVERAGE");
ifInOctetsAvg.setLabel("ifInOctetsAvg");
request.setSources(Lists.newArrayList(ifInOctetsAvg));
// Perform the query
QueryResponse response = m_svc.query(request);
// Validate the results
long[] timestamps = response.getTimestamps();
final Map<String, double[]> columns = response.columnsWithLabels();
assertEquals(3600000L, response.getStep());
assertEquals(680, timestamps.length);
// Verify the values at an arbitrary index
final int idx = 8;
assertEquals(1414630800000L, timestamps[idx]);
assertEquals(270.66140826873385, columns.get("ifInOctetsAvg")[idx], 0.0001);
}
use of org.opennms.netmgt.measurements.model.QueryRequest in project opennms by OpenNMS.
the class MeasurementsRestServiceITCase method badRequestOnMissingLabel.
@Test
public void badRequestOnMissingLabel() {
final QueryRequest request = buildRequest();
request.getSources().get(0).setLabel(null);
exception.expect(exceptionWithResponseCode(400));
m_svc.query(request);
}
use of org.opennms.netmgt.measurements.model.QueryRequest in project opennms by OpenNMS.
the class MeasurementsWrapper method queryInt.
private QueryResponse queryInt(final String resource, final String attribute, final long start, final long end, final long step, final String aggregation, final boolean relaxed) throws MeasurementException {
QueryRequest request = new QueryRequest();
request.setRelaxed(relaxed);
request.setStart(start);
request.setEnd(end);
request.setStep(step);
Source source = new Source();
source.setAggregation(aggregation);
source.setTransient(false);
source.setAttribute(attribute);
source.setResourceId(resource);
source.setLabel(attribute);
request.setSources(Collections.singletonList(source));
return measurementsService.query(request);
}
Aggregations