Search in sources :

Example 1 with GeolocationQueryBuilder

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);
}
Also used : GeolocationQueryBuilder(org.opennms.features.geolocation.api.GeolocationQueryBuilder) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo)

Example 2 with GeolocationQueryBuilder

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));
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) GeolocationQueryBuilder(org.opennms.features.geolocation.api.GeolocationQueryBuilder) GeolocationQuery(org.opennms.features.geolocation.api.GeolocationQuery) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Date(java.util.Date) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with GeolocationQueryBuilder

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));
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) GeolocationQueryBuilder(org.opennms.features.geolocation.api.GeolocationQueryBuilder) GeolocationQuery(org.opennms.features.geolocation.api.GeolocationQuery) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with GeolocationQueryBuilder

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();
}
Also used : AddressInfo(org.opennms.features.geolocation.api.AddressInfo) GraphContainer(org.opennms.features.topology.api.GraphContainer) GeolocationConfiguration(org.opennms.features.geolocation.api.GeolocationConfiguration) Collection(java.util.Collection) InfoPanelItem(org.opennms.features.topology.api.info.item.InfoPanelItem) Vertex(org.opennms.features.topology.api.topo.Vertex) Set(java.util.Set) LocationConfiguration(org.opennms.features.topology.app.internal.ui.geographical.LocationConfiguration) Marker(org.opennms.features.topology.app.internal.ui.geographical.Marker) LocationComponent(org.opennms.features.topology.app.internal.ui.geographical.LocationComponent) Collectors(java.util.stream.Collectors) Sizeable(com.vaadin.server.Sizeable) GeolocationQueryBuilder(org.opennms.features.geolocation.api.GeolocationQueryBuilder) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) List(java.util.List) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo) DefaultInfoPanelItem(org.opennms.features.topology.api.info.item.DefaultInfoPanelItem) StatusCalculationStrategy(org.opennms.features.geolocation.api.StatusCalculationStrategy) InfoPanelItemProvider(org.opennms.features.topology.api.info.InfoPanelItemProvider) Collections(java.util.Collections) GeolocationService(org.opennms.features.geolocation.api.GeolocationService) Vertex(org.opennms.features.topology.api.topo.Vertex) ArrayList(java.util.ArrayList) Marker(org.opennms.features.topology.app.internal.ui.geographical.Marker) LocationComponent(org.opennms.features.topology.app.internal.ui.geographical.LocationComponent) DefaultInfoPanelItem(org.opennms.features.topology.api.info.item.DefaultInfoPanelItem) LocationConfiguration(org.opennms.features.topology.app.internal.ui.geographical.LocationConfiguration) GeolocationQueryBuilder(org.opennms.features.geolocation.api.GeolocationQueryBuilder) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo)

Example 5 with GeolocationQueryBuilder

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());
        }
    });
}
Also used : GeolocationQueryBuilder(org.opennms.features.geolocation.api.GeolocationQueryBuilder) GeolocationQuery(org.opennms.features.geolocation.api.GeolocationQuery) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

GeolocationQueryBuilder (org.opennms.features.geolocation.api.GeolocationQueryBuilder)5 Test (org.junit.Test)3 GeolocationInfo (org.opennms.features.geolocation.api.GeolocationInfo)3 GeolocationQuery (org.opennms.features.geolocation.api.GeolocationQuery)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Date (java.util.Date)2 OnmsNode (org.opennms.netmgt.model.OnmsNode)2 Strings (com.google.common.base.Strings)1 Sizeable (com.vaadin.server.Sizeable)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 AddressInfo (org.opennms.features.geolocation.api.AddressInfo)1 GeolocationConfiguration (org.opennms.features.geolocation.api.GeolocationConfiguration)1 GeolocationService (org.opennms.features.geolocation.api.GeolocationService)1 StatusCalculationStrategy (org.opennms.features.geolocation.api.StatusCalculationStrategy)1 GraphContainer (org.opennms.features.topology.api.GraphContainer)1