use of org.opennms.features.geolocation.api.GeolocationQueryBuilder in project opennms by OpenNMS.
the class NodeMapComponent method refresh.
public void refresh() {
List<GeolocationInfo> locations = geolocationService.getLocations(new GeolocationQueryBuilder().withIncludeAcknowledgedAlarms(false).withStatusCalculationStrategy(StatusCalculationStrategy.Alarms).withSeverity(GeolocationSeverity.Normal).build());
// apply acl filter if enabled
if (m_aclsEnabled) {
Map<Integer, String> nodes = m_nodeDao.getAllLabelsById();
locations = locations.stream().filter(l -> nodes.containsKey(l.getNodeInfo().getNodeId())).collect(Collectors.toList());
}
// Convert
m_activeNodes = locations.stream().map(NodeMapComponent::createMapNode).collect(Collectors.toMap(l -> Integer.valueOf(l.getNodeId()), Function.identity()));
showNodes(m_activeNodes);
}
use of org.opennms.features.geolocation.api.GeolocationQueryBuilder 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.GeolocationQueryBuilder 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));
}
use of org.opennms.features.geolocation.api.GeolocationQueryBuilder in project opennms by OpenNMS.
the class LocationInfoPanelItemProvider method getContributions.
@Override
public Collection<? extends InfoPanelItem> getContributions(GraphContainer container) {
final List<Vertex> vertices = new ArrayList<>(container.getGraph().getDisplayVertices());
final Set<Integer> nodeIds = vertices.stream().filter(v -> v.getNodeID() != null).map(Vertex::getNodeID).collect(Collectors.toSet());
if (nodeIds.isEmpty()) {
return Collections.emptyList();
}
final List<GeolocationInfo> locations = geolocationService.getLocations(new GeolocationQueryBuilder().withNodeIds(nodeIds).withStatusCalculationStrategy(StatusCalculationStrategy.None).build());
final List<Marker> markers = locations.stream().filter(locationInfo -> locationInfo.getCoordinates() != null).map(locationInfo -> {
final Vertex vertex = vertices.stream().filter(v -> v.getNodeID() != null && locationInfo.getNodeInfo().getNodeId() == v.getNodeID()).findFirst().get();
return new Marker(locationInfo.getCoordinates(), createTooltip(vertex, locationInfo.getAddressInfo()), container.getSelectionManager().isVertexRefSelected(vertex));
}).collect(Collectors.toList());
if (!markers.isEmpty()) {
final LocationConfiguration config = new LocationConfiguration().withTileLayer(geolocationConfiguration.getTileServerUrl()).withMarker(markers).withInitialZoom(10).withLayerOptions(geolocationConfiguration.getOptions());
final LocationComponent locationComponent = new LocationComponent(config, "mapId-" + getClass().getSimpleName().toLowerCase());
locationComponent.setWidth(300, Sizeable.Unit.PIXELS);
locationComponent.setHeight(300, Sizeable.Unit.PIXELS);
return Collections.singleton(new DefaultInfoPanelItem().withTitle(String.format("Geolocation (%d/%d)", markers.size(), vertices.size())).withOrder(1).withComponent(locationComponent));
}
return Collections.emptyList();
}
use of org.opennms.features.geolocation.api.GeolocationQueryBuilder in project opennms by OpenNMS.
the class DefaultGeolocationServiceIT method verifyMerging.
@Test
@Transactional
public void verifyMerging() {
// Set coordinates for all
nodeDao.findAll().forEach(n -> {
n.getAssetRecord().getGeolocation().setLongitude(coordinates.getLongitude());
n.getAssetRecord().getGeolocation().setLatitude(coordinates.getLatitude());
nodeDao.saveOrUpdate(n);
});
// Query
final GeolocationQuery query = new GeolocationQueryBuilder().withStatusCalculationStrategy(StatusCalculationStrategy.Alarms).build();
// We do not have any alarms, therefore all nodes should be "NORMAL"
List<GeolocationInfo> locations = geolocationService.getLocations(query);
Assert.assertEquals(nodeDao.countAll(), locations.size());
locations.forEach(l -> Assert.assertEquals("Normal", l.getSeverityInfo().getLabel()));
// Add an alarm for one node and try again
alarmDao.save(createAlarm(databasePopulator.getNode1(), OnmsSeverity.MAJOR, distPollerDao.whoami()));
alarmDao.flush();
locations = geolocationService.getLocations(query);
Assert.assertEquals(nodeDao.countAll(), locations.size());
locations.forEach(l -> {
if (l.getNodeInfo().getNodeId() == databasePopulator.getNode1().getId()) {
Assert.assertEquals("Major", l.getSeverityInfo().getLabel());
} else {
Assert.assertEquals("Normal", l.getSeverityInfo().getLabel());
}
});
}
Aggregations