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