Search in sources :

Example 1 with GeolocationQuery

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()));
        }
    }
}
Also used : AddressInfo(org.opennms.features.geolocation.api.AddressInfo) OutageStatusCalculator(org.opennms.features.geolocation.services.status.OutageStatusCalculator) Status(org.opennms.features.geolocation.services.status.Status) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) Coordinates(org.opennms.features.geolocation.api.Coordinates) StatusCalculator(org.opennms.features.geolocation.services.status.StatusCalculator) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo) GenericPersistenceAccessor(org.opennms.netmgt.dao.api.GenericPersistenceAccessor) OnmsNode(org.opennms.netmgt.model.OnmsNode) Logger(org.slf4j.Logger) InetAddressUtils(org.opennms.core.utils.InetAddressUtils) Set(java.util.Set) SeverityInfo(org.opennms.features.geolocation.api.SeverityInfo) Collectors(java.util.stream.Collectors) Restrictions(org.opennms.core.criteria.restrictions.Restrictions) Objects(java.util.Objects) OnmsGeolocation(org.opennms.netmgt.model.OnmsGeolocation) List(java.util.List) GeolocationQuery(org.opennms.features.geolocation.api.GeolocationQuery) NodeInfo(org.opennms.features.geolocation.api.NodeInfo) StatusCalculationStrategy(org.opennms.features.geolocation.api.StatusCalculationStrategy) AlarmStatusCalculator(org.opennms.features.geolocation.services.status.AlarmStatusCalculator) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) GeolocationResolver(org.opennms.features.geolocation.api.GeolocationResolver) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) GeolocationService(org.opennms.features.geolocation.api.GeolocationService) Status(org.opennms.features.geolocation.services.status.Status) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) SeverityInfo(org.opennms.features.geolocation.api.SeverityInfo) OutageStatusCalculator(org.opennms.features.geolocation.services.status.OutageStatusCalculator) StatusCalculator(org.opennms.features.geolocation.services.status.StatusCalculator) AlarmStatusCalculator(org.opennms.features.geolocation.services.status.AlarmStatusCalculator) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo)

Example 2 with GeolocationQuery

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;
}
Also used : AddressInfo(org.opennms.features.geolocation.api.AddressInfo) OutageStatusCalculator(org.opennms.features.geolocation.services.status.OutageStatusCalculator) Status(org.opennms.features.geolocation.services.status.Status) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) Coordinates(org.opennms.features.geolocation.api.Coordinates) StatusCalculator(org.opennms.features.geolocation.services.status.StatusCalculator) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo) GenericPersistenceAccessor(org.opennms.netmgt.dao.api.GenericPersistenceAccessor) OnmsNode(org.opennms.netmgt.model.OnmsNode) Logger(org.slf4j.Logger) InetAddressUtils(org.opennms.core.utils.InetAddressUtils) Set(java.util.Set) SeverityInfo(org.opennms.features.geolocation.api.SeverityInfo) Collectors(java.util.stream.Collectors) Restrictions(org.opennms.core.criteria.restrictions.Restrictions) Objects(java.util.Objects) OnmsGeolocation(org.opennms.netmgt.model.OnmsGeolocation) List(java.util.List) GeolocationQuery(org.opennms.features.geolocation.api.GeolocationQuery) NodeInfo(org.opennms.features.geolocation.api.NodeInfo) StatusCalculationStrategy(org.opennms.features.geolocation.api.StatusCalculationStrategy) AlarmStatusCalculator(org.opennms.features.geolocation.services.status.AlarmStatusCalculator) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) GeolocationResolver(org.opennms.features.geolocation.api.GeolocationResolver) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) GeolocationService(org.opennms.features.geolocation.api.GeolocationService) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) ArrayList(java.util.ArrayList) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo)

Example 3 with GeolocationQuery

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();
    }
}
Also used : GeolocationService(org.opennms.features.geolocation.api.GeolocationService) GeolocationQuery(org.opennms.features.geolocation.api.GeolocationQuery) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 4 with GeolocationQuery

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));
}
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 5 with GeolocationQuery

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));
}
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)

Aggregations

GeolocationQuery (org.opennms.features.geolocation.api.GeolocationQuery)7 GeolocationInfo (org.opennms.features.geolocation.api.GeolocationInfo)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 Test (org.junit.Test)3 GeolocationQueryBuilder (org.opennms.features.geolocation.api.GeolocationQueryBuilder)3 GeolocationService (org.opennms.features.geolocation.api.GeolocationService)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 List (java.util.List)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)2 Restrictions (org.opennms.core.criteria.restrictions.Restrictions)2 InetAddressUtils (org.opennms.core.utils.InetAddressUtils)2 AddressInfo (org.opennms.features.geolocation.api.AddressInfo)2 Coordinates (org.opennms.features.geolocation.api.Coordinates)2 GeolocationResolver (org.opennms.features.geolocation.api.GeolocationResolver)2 NodeInfo (org.opennms.features.geolocation.api.NodeInfo)2