Search in sources :

Example 1 with AlarmSummary

use of org.opennms.netmgt.model.alarm.AlarmSummary in project opennms by OpenNMS.

the class AlarmStatusProvider method calculateAlarmStatusForGroup.

private static AlarmStatus calculateAlarmStatusForGroup(List<AlarmSummary> alarmSummaries) {
    if (!alarmSummaries.isEmpty()) {
        Collections.sort(alarmSummaries, new Comparator<AlarmSummary>() {

            @Override
            public int compare(AlarmSummary o1, AlarmSummary o2) {
                return o1.getMaxSeverity().compareTo(o2.getMaxSeverity());
            }
        });
        OnmsSeverity severity = alarmSummaries.get(0).getMaxSeverity();
        int count = 0;
        for (AlarmSummary eachSummary : alarmSummaries) {
            count += eachSummary.getAlarmCount();
        }
        return new AlarmStatus(severity.getLabel(), count);
    }
    return createDefaultStatus();
}
Also used : OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary)

Example 2 with AlarmSummary

use of org.opennms.netmgt.model.alarm.AlarmSummary in project opennms by OpenNMS.

the class GraphMLVertexStatusProvider method getStatusForVertices.

@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
    // All vertices for the current vertexProvider
    final List<GraphMLVertex> graphMLVertices = vertices.stream().filter(eachVertex -> contributesTo(eachVertex.getNamespace()) && eachVertex instanceof GraphMLVertex).map(eachVertex -> (GraphMLVertex) eachVertex).collect(Collectors.toList());
    // All vertices associated with a node id
    final Map<Integer, VertexRef> nodeIdMap = graphMLVertices.stream().filter(eachVertex -> eachVertex.getNodeID() != null).collect(Collectors.toMap(AbstractVertex::getNodeID, Function.identity()));
    // Alarm summary for each node id
    final Map<Integer, AlarmSummary> nodeIdToAlarmSummaryMap = getAlarmSummaries(nodeIdMap.keySet());
    // Set the result
    Map<VertexRef, Status> resultMap = Maps.newHashMap();
    for (GraphMLVertex eachVertex : graphMLVertices) {
        AlarmSummary alarmSummary = nodeIdToAlarmSummaryMap.get(eachVertex.getNodeID());
        DefaultStatus status = alarmSummary == null ? new VertexStatus(OnmsSeverity.NORMAL) : new VertexStatus(alarmSummary.getMaxSeverity(), alarmSummary.getAlarmCount());
        resultMap.put(eachVertex, status);
    }
    return resultMap;
}
Also used : AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) Collection(java.util.Collection) Set(java.util.Set) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) ArrayList(java.util.ArrayList) Objects(java.util.Objects) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) List(java.util.List) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) VertexProvider(org.opennms.features.topology.api.topo.VertexProvider) AlarmSummaryWrapper(org.opennms.features.topology.plugins.topo.graphml.internal.AlarmSummaryWrapper) Map(java.util.Map) Criteria(org.opennms.features.topology.api.topo.Criteria) Status(org.opennms.features.topology.api.topo.Status) VertexRef(org.opennms.features.topology.api.topo.VertexRef) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) Status(org.opennms.features.topology.api.topo.Status) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 3 with AlarmSummary

use of org.opennms.netmgt.model.alarm.AlarmSummary in project opennms by OpenNMS.

the class AlarmDaoIT method testAlarmSummary_AlarmWithNoEvent.

@Test
@Transactional
public void testAlarmSummary_AlarmWithNoEvent() {
    OnmsNode node = m_nodeDao.findAll().iterator().next();
    OnmsAlarm alarm = new OnmsAlarm();
    alarm.setNode(node);
    alarm.setUei("uei://org/opennms/test/badAlarmTest");
    alarm.setSeverityId(new Integer(7));
    alarm.setCounter(1);
    alarm.setDistPoller(m_distPollerDao.whoami());
    m_alarmDao.save(alarm);
    List<AlarmSummary> summary = m_alarmDao.getNodeAlarmSummaries();
    Assert.assertNotNull(summary);
    Assert.assertEquals(1, summary.size());
    AlarmSummary sum = summary.get(0);
    Assert.assertEquals(node.getLabel(), sum.getNodeLabel());
    Assert.assertEquals(alarm.getSeverity().getId(), sum.getMaxSeverity().getId());
    Assert.assertEquals("N/A", sum.getFuzzyTimeDown());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with AlarmSummary

use of org.opennms.netmgt.model.alarm.AlarmSummary in project opennms by OpenNMS.

the class GraphMLDefaultVertexStatusProvider method getStatusForVertices.

@Override
public Map<? extends VertexRef, ? extends Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
    // All vertices for the current vertexProvider
    final List<GraphMLVertex> graphMLVertices = vertices.stream().filter(eachVertex -> contributesTo(eachVertex.getNamespace()) && eachVertex instanceof GraphMLVertex).map(eachVertex -> (GraphMLVertex) eachVertex).collect(Collectors.toList());
    // All vertices associated with a node id
    final Map<Integer, VertexRef> nodeIdMap = graphMLVertices.stream().filter(eachVertex -> eachVertex.getNodeID() != null).collect(Collectors.toMap(AbstractVertex::getNodeID, Function.identity()));
    // Alarm summary for each node id
    final Map<Integer, AlarmSummary> nodeIdToAlarmSummaryMap = getAlarmSummaries(nodeIdMap.keySet());
    // Set the result
    Map<VertexRef, Status> resultMap = Maps.newHashMap();
    for (GraphMLVertex eachVertex : graphMLVertices) {
        AlarmSummary alarmSummary = nodeIdToAlarmSummaryMap.get(eachVertex.getNodeID());
        GraphMLVertexStatus status = alarmSummary == null ? new GraphMLVertexStatus() : new GraphMLVertexStatus(alarmSummary.getMaxSeverity(), alarmSummary.getAlarmCount());
        resultMap.put(eachVertex, status);
    }
    return resultMap;
}
Also used : AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) Collection(java.util.Collection) Set(java.util.Set) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) VertexProvider(org.opennms.features.topology.api.topo.VertexProvider) AlarmSummaryWrapper(org.opennms.features.topology.plugins.topo.graphml.internal.AlarmSummaryWrapper) Map(java.util.Map) Criteria(org.opennms.features.topology.api.topo.Criteria) Status(org.opennms.features.topology.api.topo.Status) VertexRef(org.opennms.features.topology.api.topo.VertexRef) GraphMLVertex(org.opennms.features.topology.plugins.topo.graphml.GraphMLVertex) Status(org.opennms.features.topology.api.topo.Status) GraphMLVertex(org.opennms.features.topology.plugins.topo.graphml.GraphMLVertex) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 5 with AlarmSummary

use of org.opennms.netmgt.model.alarm.AlarmSummary in project opennms by OpenNMS.

the class AlarmStatusProvider method getStatusForVertices.

@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
    Map<VertexRef, Status> returnMap = new HashMap<VertexRef, Status>();
    // split nodes from groups and others
    // nodes
    List<VertexRef> nodeRefs = getNodeVertexRefs(vertexProvider, vertices, criteria);
    // groups
    List<VertexRef> otherRefs = getOtherVertexRefs(vertices);
    Map<Integer, VertexRef> nodeIdMap = extractNodeIds(nodeRefs);
    // calculate status for ALL nodes
    Map<Integer, AlarmSummary> nodeIdToAlarmSummaryMap = getAlarmSummaries(nodeIdMap.keySet());
    // status for all known node ids
    for (Integer eachNodeId : nodeIdMap.keySet()) {
        AlarmSummary summary = nodeIdToAlarmSummaryMap.get(eachNodeId);
        AlarmStatus status = summary == null ? createDefaultStatus() : createStatus(summary);
        VertexRef ref = nodeIdMap.get(eachNodeId);
        returnMap.put(ref, status);
        LoggerFactory.getLogger(getClass()).debug("Status for node '{}' with id '{}' is: {}", ref.getLabel(), ref.getId(), status);
    }
    // calculate status for groups and nodes which are neither group nor node
    for (VertexRef eachRef : otherRefs) {
        if (isGroup(eachRef)) {
            List<AlarmSummary> alarmSummariesForGroup = new ArrayList<>();
            List<Vertex> children = vertexProvider.getChildren(eachRef, criteria);
            for (Vertex eachChildren : children) {
                AlarmSummary eachChildrenAlarmSummary = nodeIdToAlarmSummaryMap.get(eachChildren.getNodeID());
                if (eachChildrenAlarmSummary != null) {
                    alarmSummariesForGroup.add(eachChildrenAlarmSummary);
                }
            }
            AlarmStatus groupStatus = calculateAlarmStatusForGroup(alarmSummariesForGroup);
            returnMap.put(eachRef, groupStatus);
        } else {
            returnMap.put(eachRef, createDefaultStatus());
        }
    }
    return returnMap;
}
Also used : DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) Status(org.opennms.features.topology.api.topo.Status) Vertex(org.opennms.features.topology.api.topo.Vertex) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Aggregations

AlarmSummary (org.opennms.netmgt.model.alarm.AlarmSummary)11 ArrayList (java.util.ArrayList)5 Status (org.opennms.features.topology.api.topo.Status)5 VertexRef (org.opennms.features.topology.api.topo.VertexRef)5 Collection (java.util.Collection)4 List (java.util.List)4 Map (java.util.Map)4 Objects (java.util.Objects)4 Function (java.util.function.Function)4 Collectors (java.util.stream.Collectors)4 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)4 Criteria (org.opennms.features.topology.api.topo.Criteria)4 StatusProvider (org.opennms.features.topology.api.topo.StatusProvider)4 VertexProvider (org.opennms.features.topology.api.topo.VertexProvider)4 Maps (com.google.common.collect.Maps)3 Set (java.util.Set)3 DefaultStatus (org.opennms.features.topology.api.topo.DefaultStatus)3 AlarmSummaryWrapper (org.opennms.features.topology.plugins.topo.graphml.internal.AlarmSummaryWrapper)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2