Search in sources :

Example 1 with Status

use of org.opennms.features.status.api.node.strategy.Status in project opennms by OpenNMS.

the class DefaultGeolocationService method calculateStatus.

private Status calculateStatus(GeolocationQuery query, Set<Integer> nodeIds) {
    final NodeStatusCalculatorConfig nodeStatusCalculatorConfig = new NodeStatusCalculatorConfig();
    nodeStatusCalculatorConfig.setIncludeAcknowledgedAlarms(query.isIncludeAcknowledgedAlarms());
    nodeStatusCalculatorConfig.setLocation(query.getLocation());
    if (query.getSeverity() != null) {
        final OnmsSeverity severity = OnmsSeverity.get(query.getSeverity().getId());
        final List<OnmsSeverity> severityFilter = Arrays.stream(OnmsSeverity.values()).filter(s -> s.isGreaterThanOrEqual(severity)).collect(Collectors.toList());
        nodeStatusCalculatorConfig.setSeverities(severityFilter);
    }
    nodeStatusCalculatorConfig.setCalculationStrategy(NodeStatusCalculationStrategy.None);
    if (query.getStatusCalculationStrategy() != null) {
        nodeStatusCalculatorConfig.setCalculationStrategy(NodeStatusCalculationStrategy.valueOf(query.getStatusCalculationStrategy().name()));
    }
    nodeStatusCalculatorConfig.setNodeIds(nodeIds);
    final Status status = nodeStatusCalculator.calculateStatus(nodeStatusCalculatorConfig);
    return status;
}
Also used : AddressInfo(org.opennms.features.geolocation.api.AddressInfo) Arrays(java.util.Arrays) NodeStatusCalculationStrategy(org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy) Status(org.opennms.features.status.api.node.strategy.Status) NodeStatusCalculatorConfig(org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig) ArrayList(java.util.ArrayList) Coordinates(org.opennms.features.geolocation.api.Coordinates) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo) GenericPersistenceAccessor(org.opennms.netmgt.dao.api.GenericPersistenceAccessor) OnmsNode(org.opennms.netmgt.model.OnmsNode) 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) NodeStatusCalculator(org.opennms.features.status.api.node.NodeStatusCalculator) 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) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) GeolocationService(org.opennms.features.geolocation.api.GeolocationService) Status(org.opennms.features.status.api.node.strategy.Status) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) NodeStatusCalculatorConfig(org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig)

Example 2 with Status

use of org.opennms.features.status.api.node.strategy.Status 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 Status status = 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) Arrays(java.util.Arrays) NodeStatusCalculationStrategy(org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy) Status(org.opennms.features.status.api.node.strategy.Status) NodeStatusCalculatorConfig(org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig) ArrayList(java.util.ArrayList) Coordinates(org.opennms.features.geolocation.api.Coordinates) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo) GenericPersistenceAccessor(org.opennms.netmgt.dao.api.GenericPersistenceAccessor) OnmsNode(org.opennms.netmgt.model.OnmsNode) 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) NodeStatusCalculator(org.opennms.features.status.api.node.NodeStatusCalculator) 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) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) GeolocationService(org.opennms.features.geolocation.api.GeolocationService) Status(org.opennms.features.status.api.node.strategy.Status) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) SeverityInfo(org.opennms.features.geolocation.api.SeverityInfo) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo)

Example 3 with Status

use of org.opennms.features.status.api.node.strategy.Status in project opennms by OpenNMS.

the class NodeStatusService method getStatus.

public List<StatusEntity<OnmsNode>> getStatus(NodeQuery query) {
    // Build query
    final NodeStatusCalculatorConfig config = buildFrom(query);
    // Calculate Status
    final Status status = statusCalculator.calculateStatus(config);
    // Find nodes for node id
    final List<OnmsNode> nodes = getNodes(status.getIds());
    final Map<Integer, OnmsNode> nodeIdMap = nodes.stream().collect(Collectors.toMap(n -> n.getId(), n -> n));
    // convert to wrapper
    return status.getIds().stream().map(nodeId -> {
        OnmsSeverity nodeStatus = status.getSeverity(nodeId);
        OnmsNode node = nodeIdMap.get(nodeId);
        if (nodeStatus == null) {
            throw new IllegalStateException("nodeStatus should not be null");
        }
        if (node == null) {
            throw new IllegalStateException("node should not be null");
        }
        return new StatusEntityWrapper<>(node, nodeStatus);
    }).collect(Collectors.toList());
}
Also used : Status(org.opennms.features.status.api.node.strategy.Status) NodeDao(org.opennms.netmgt.dao.api.NodeDao) NodeStatusCalculationStrategy(org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy) Status(org.opennms.features.status.api.node.strategy.Status) Autowired(org.springframework.beans.factory.annotation.Autowired) NodeStatusCalculatorConfig(org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig) StatusEntityWrapper(org.opennms.features.status.api.StatusEntityWrapper) Collectors(java.util.stream.Collectors) StatusEntity(org.opennms.features.status.api.StatusEntity) ArrayList(java.util.ArrayList) List(java.util.List) StatusSummary(org.opennms.features.status.api.StatusSummary) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) NodeStatusCalculatorConfig(org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig)

Example 4 with Status

use of org.opennms.features.status.api.node.strategy.Status in project opennms by OpenNMS.

the class AlarmQuery method status.

@Override
public Status status() {
    sql = new StringBuilder();
    sql.append("SELECT ").append(getViewName()).append(".nodeid").append(", ").append(getSeverityColumn()).append(" AS severity, alarm_count, alarm_count_unack ");
    sql.append("FROM ").append(getViewName()).append(" ");
    sql.append("JOIN node on ").append(getViewName()).append(".nodeid = node.nodeid ");
    applyRestrictions();
    applyOrder();
    applyLimitAndOffset();
    final Status status = new Status();
    executeQuery((RowHandler<Object[]>) columns -> status.add((int) columns[0], OnmsSeverity.get((int) columns[1]), columns[2] != null ? ((BigInteger) columns[2]).longValue() : 0, columns[3] != null ? ((BigInteger) columns[3]).longValue() : 0));
    return status;
}
Also used : Status(org.opennms.features.status.api.node.strategy.Status) GenericPersistenceAccessor(org.opennms.netmgt.dao.api.GenericPersistenceAccessor) Status(org.opennms.features.status.api.node.strategy.Status) BigInteger(java.math.BigInteger) NodeStatusCalculatorConfig(org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) BigInteger(java.math.BigInteger)

Example 5 with Status

use of org.opennms.features.status.api.node.strategy.Status in project opennms by OpenNMS.

the class OutageQuery method status.

@Override
public Status status() {
    sql = new StringBuilder();
    sql.append("SELECT ").append(getViewName()).append(".nodeid").append(", ").append(getSeverityColumn()).append(" AS severity ");
    sql.append("FROM ").append(getViewName()).append(" ");
    sql.append("JOIN node on ").append(getViewName()).append(".nodeid = node.nodeid ");
    applyRestrictions();
    applyOrder();
    applyLimitAndOffset();
    final Status status = new Status();
    executeQuery((RowHandler<Object[]>) columns -> status.add((int) columns[0], OnmsSeverity.get((int) columns[1])));
    return status;
}
Also used : Status(org.opennms.features.status.api.node.strategy.Status) GenericPersistenceAccessor(org.opennms.netmgt.dao.api.GenericPersistenceAccessor) Status(org.opennms.features.status.api.node.strategy.Status) NodeStatusCalculatorConfig(org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity)

Aggregations

NodeStatusCalculatorConfig (org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig)5 Status (org.opennms.features.status.api.node.strategy.Status)5 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)5 GenericPersistenceAccessor (org.opennms.netmgt.dao.api.GenericPersistenceAccessor)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)3 NodeStatusCalculationStrategy (org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 Arrays (java.util.Arrays)2 Objects (java.util.Objects)2 Set (java.util.Set)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 GeolocationInfo (org.opennms.features.geolocation.api.GeolocationInfo)2 GeolocationQuery (org.opennms.features.geolocation.api.GeolocationQuery)2 GeolocationService (org.opennms.features.geolocation.api.GeolocationService)2