use of org.opennms.features.geolocation.api.GeolocationQuery in project opennms by OpenNMS.
the class DefaultGeolocationService method applyStatus.
private void applyStatus(GeolocationQuery query, List<GeolocationInfo> locations) {
final Set<Integer> nodeIds = locations.stream().map(l -> l.getNodeInfo().getNodeId()).collect(Collectors.toSet());
if (!nodeIds.isEmpty()) {
final StatusCalculator calculator = getStatusCalculator(query.getStatusCalculationStrategy());
final Status status = calculator.calculateStatus(query, nodeIds);
// Appliing the calculated status to each location
for (GeolocationInfo info : locations) {
OnmsSeverity severity = status.getSeverity(info.getNodeInfo().getNodeId());
// Therefore for all locations with no status must be set to "NORMAL" in the result
if (severity == null) {
severity = OnmsSeverity.NORMAL;
}
info.setSeverityInfo(new SeverityInfo(severity.getId(), severity.getLabel()));
info.setAlarmUnackedCount(status.getUnacknowledgedAlarmCount(info.getNodeInfo().getNodeId()));
}
}
}
use of org.opennms.features.geolocation.api.GeolocationQuery in project opennms by OpenNMS.
the class DefaultGeolocationService method getLocations.
@Override
public List<GeolocationInfo> getLocations(GeolocationQuery query) {
if (query == null) {
return new ArrayList<>();
}
final List<OnmsNode> nodes = getNodes(query);
final List<GeolocationInfo> nodesWithCoordinates = nodes.stream().filter(n -> geoLocation(n) != null && geoLocation(n).getLongitude() != null && geoLocation(n).getLatitude() != null).filter(n -> geoLocation(n).getLatitude() != Float.NEGATIVE_INFINITY && geoLocation(n).getLongitude() != Float.NEGATIVE_INFINITY).map(node -> convert(node)).collect(Collectors.toList());
if (query.getStatusCalculationStrategy() != null) {
applyStatus(query, nodesWithCoordinates);
}
if (query.getSeverity() != null) {
OnmsSeverity severity = OnmsSeverity.get(query.getSeverity().getId());
return nodesWithCoordinates.stream().filter(n -> severity.getId() <= n.getSeverityInfo().getId()).collect(Collectors.toList());
}
return nodesWithCoordinates;
}
use of org.opennms.features.geolocation.api.GeolocationQuery in project opennms by OpenNMS.
the class GeolocationRestService method getLocations.
@POST
@Path("/")
public Response getLocations(GeolocationQueryDTO queryDTO) {
final GeolocationService service = getServiceRegistry().findProvider(GeolocationService.class);
if (service == null) {
return temporarilyNotAvailable();
}
try {
validate(queryDTO);
GeolocationQuery query = toQuery(queryDTO);
final List<GeolocationInfo> locations = service.getLocations(query);
if (locations.isEmpty()) {
return Response.noContent().build();
}
return Response.ok(locations).build();
} catch (InvalidQueryException ex) {
return Response.status(Response.Status.BAD_REQUEST).entity(ex.getMessage()).build();
}
}
use of org.opennms.features.geolocation.api.GeolocationQuery in project opennms by OpenNMS.
the class AlarmStatusCalculatorIT method verifyCalculateStatus.
@Test
@Transactional
public void verifyCalculateStatus() {
final OnmsNode node = databasePopulator.getNode1();
final GeolocationQuery query = new GeolocationQueryBuilder().build();
final StatusCalculator statusCalculator = new AlarmStatusCalculator(genericPersistenceAccessor);
final Set<Integer> nodeIds = Sets.newHashSet(node.getId());
// No alarm exists, status should be normal
verifyStatus(0, new HashMap<>(), statusCalculator.calculateStatus(query, nodeIds));
// Create an alarm and verify status
OnmsAlarm alarm = createAlarm(node, OnmsSeverity.WARNING);
alarmDao.save(alarm);
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.WARNING), statusCalculator.calculateStatus(query, nodeIds));
// Create an alarm for same node and verify
OnmsAlarm alarm2 = createAlarm(node, OnmsSeverity.MINOR);
alarmDao.save(alarm2);
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MINOR), statusCalculator.calculateStatus(query, nodeIds));
// Create an alarm for another node and verify
alarmDao.save(createAlarm(databasePopulator.getNode2(), OnmsSeverity.CRITICAL));
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MINOR), statusCalculator.calculateStatus(query, nodeIds));
// Acknowledge alarms
alarm2.setAlarmAckTime(new Date());
alarm2.setAlarmAckUser("ulf");
alarmDao.saveOrUpdate(alarm2);
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.WARNING), statusCalculator.calculateStatus(query, nodeIds));
alarm.setAlarmAckTime(new Date());
alarm.setAlarmAckUser("ulf");
alarmDao.saveOrUpdate(alarm);
verifyStatus(0, new HashMap<>(), statusCalculator.calculateStatus(query, nodeIds));
// Include acknowledged alarms
query.setIncludeAcknowledgedAlarms(true);
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MINOR), statusCalculator.calculateStatus(query, nodeIds));
// Apply severity filter
query.setSeverity(GeolocationSeverity.Warning);
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MINOR), statusCalculator.calculateStatus(query, nodeIds));
query.setSeverity(GeolocationSeverity.Minor);
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MINOR), statusCalculator.calculateStatus(query, nodeIds));
query.setSeverity(GeolocationSeverity.Major);
verifyStatus(0, new HashMap<>(), statusCalculator.calculateStatus(query, nodeIds));
// reset severity filter and apply location filter
query.setSeverity(null);
query.setLocation(distPollerDao.whoami().getLocation());
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MINOR), statusCalculator.calculateStatus(query, nodeIds));
query.setLocation("XXX");
verifyStatus(0, new HashMap<>(), statusCalculator.calculateStatus(query, nodeIds));
}
use of org.opennms.features.geolocation.api.GeolocationQuery in project opennms by OpenNMS.
the class OutageStatusCalculatorIT method verifyCalculateStatus.
@Test
@Transactional
public void verifyCalculateStatus() {
final OnmsNode node = databasePopulator.getNode1();
final OnmsMonitoredService icmpService = node.getIpInterfaceByIpAddress("192.168.1.1").getMonitoredServiceByServiceType("ICMP");
final OnmsMonitoredService snmpService = node.getIpInterfaceByIpAddress("192.168.1.1").getMonitoredServiceByServiceType("SNMP");
final GeolocationQuery query = new GeolocationQueryBuilder().build();
final StatusCalculator statusCalculator = new OutageStatusCalculator(genericPersistenceAccessor);
final Set<Integer> nodeIds = Sets.newHashSet(node.getId());
// No outage exist, status should be normal
verifyStatus(0, new HashMap<>(), statusCalculator.calculateStatus(query, nodeIds));
// Create an alarm and verify status
final OnmsOutage outage = createOutage(icmpService, createEvent(node, OnmsSeverity.WARNING));
saveOrUpdate(outage);
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.WARNING), statusCalculator.calculateStatus(query, nodeIds));
// Create another outage on same interface and verify
final OnmsOutage outage2 = createOutage(snmpService, createEvent(node, OnmsSeverity.MINOR));
saveOrUpdate(outage2);
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MINOR), statusCalculator.calculateStatus(query, nodeIds));
// Create another outage on another interface and verify
final OnmsMonitoredService httpService = node.getIpInterfaceByIpAddress("192.168.1.2").getMonitoredServiceByServiceType("HTTP");
saveOrUpdate(createOutage(httpService, createEvent(node, OnmsSeverity.MAJOR)));
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR), statusCalculator.calculateStatus(query, nodeIds));
// Create another outage on another node and verify
saveOrUpdate(createOutage(databasePopulator.getNode2().getPrimaryInterface().getMonitoredServiceByServiceType("ICMP"), createEvent(databasePopulator.getNode2(), OnmsSeverity.CRITICAL)));
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR), statusCalculator.calculateStatus(query, nodeIds));
// calculate status for both
verifyStatus(2, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR, databasePopulator.getNode2().getId(), OnmsSeverity.CRITICAL), statusCalculator.calculateStatus(query, Sets.newHashSet(node.getId(), databasePopulator.getNode2().getId())));
// Resolve the Warning Outage
outage.setServiceRegainedEvent(createEvent(node, OnmsSeverity.WARNING));
outage.setIfRegainedService(new Date());
saveOrUpdate(outage);
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR), statusCalculator.calculateStatus(query, nodeIds));
// Apply severity filter
query.setSeverity(GeolocationSeverity.Warning);
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR), statusCalculator.calculateStatus(query, nodeIds));
query.setSeverity(GeolocationSeverity.Minor);
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR), statusCalculator.calculateStatus(query, nodeIds));
query.setSeverity(GeolocationSeverity.Major);
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR), statusCalculator.calculateStatus(query, nodeIds));
query.setSeverity(GeolocationSeverity.Critical);
verifyStatus(0, new HashMap<>(), statusCalculator.calculateStatus(query, nodeIds));
// reset severity filter and apply location filter
query.setSeverity(null);
query.setLocation(distPollerDao.whoami().getLocation());
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR), statusCalculator.calculateStatus(query, nodeIds));
query.setLocation("XXX");
verifyStatus(0, new HashMap<>(), statusCalculator.calculateStatus(query, nodeIds));
}
Aggregations