use of org.opennms.netmgt.dao.api.ApplicationStatusEntity in project opennms by OpenNMS.
the class ApplicationStatusEntityTest method testKey.
@Test
public void testKey() {
ApplicationStatusEntity entity = new ApplicationStatusEntity(100, InetAddressUtils.getLocalHostAddress(), 20, new Date(), OnmsSeverity.NORMAL, 20L);
ApplicationStatusEntity.Key key1 = entity.getKey();
Assert.assertEquals(new ApplicationStatusEntity.Key("100", "20", InetAddressUtils.getLocalHostAddress().toString()), key1);
}
use of org.opennms.netmgt.dao.api.ApplicationStatusEntity in project opennms by OpenNMS.
the class ApplicationDaoHibernate method getAlarmStatus.
@Override
public List<ApplicationStatusEntity> getAlarmStatus() {
final StringBuilder sql = new StringBuilder();
sql.append("select distinct alarm.node.id, alarm.ipAddr, alarm.serviceType.id, min(alarm.lastEventTime), max(alarm.severity), (count(*) - count(alarm.alarmAckTime)) ");
sql.append("from OnmsAlarm alarm ");
sql.append("where alarm.severity > 3 and alarm.node.id != null and alarm.ipAddr != null and alarm.serviceType.id != null and alarm.alarmAckTime is null ");
sql.append("group by alarm.node.id, alarm.ipAddr, alarm.serviceType.id");
List<ApplicationStatusEntity> entityList = new ArrayList<>();
List<Object[][]> objects = (List<Object[][]>) getHibernateTemplate().find(sql.toString());
for (Object[] eachRow : objects) {
ApplicationStatusEntity entity = new ApplicationStatusEntity((Integer) eachRow[0], (InetAddress) eachRow[1], (Integer) eachRow[2], (Date) eachRow[3], (OnmsSeverity) eachRow[4], (Long) eachRow[5]);
entityList.add(entity);
}
return entityList;
}
use of org.opennms.netmgt.dao.api.ApplicationStatusEntity in project opennms by OpenNMS.
the class ApplicationStatusProvider method getStatusForVertices.
@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
Map<VertexRef, Status> returnMap = new HashMap<>();
Map<ApplicationStatusEntity.Key, Status> statusMap = new HashMap<>();
List<ApplicationStatusEntity> result = applicationDao.getAlarmStatus();
for (ApplicationStatusEntity eachRow : result) {
DefaultStatus status = createStatus(eachRow.getSeverity(), eachRow.getCount());
statusMap.put(eachRow.getKey(), status);
}
// status for all known node ids
Collection<VertexRef> vertexRefsForNamespace = getVertexRefsForNamespace(vertices);
Collection<VertexRef> vertexRefsRoot = getRootElements(vertexRefsForNamespace);
Collection<VertexRef> vertexRefs = new ArrayList<>(vertexRefsForNamespace);
vertexRefs.removeAll(vertexRefsRoot);
// calculate status for children
for (VertexRef eachVertex : vertexRefs) {
ApplicationVertex applicationVertex = (ApplicationVertex) eachVertex;
Status alarmStatus = statusMap.get(createKey(applicationVertex));
if (alarmStatus == null) {
alarmStatus = createStatus(OnmsSeverity.NORMAL, 0);
}
returnMap.put(eachVertex, alarmStatus);
}
// calculate status for root
for (VertexRef eachRoot : vertexRefsRoot) {
ApplicationVertex eachRootApplication = (ApplicationVertex) eachRoot;
OnmsSeverity maxSeverity = OnmsSeverity.NORMAL;
int count = 0;
for (VertexRef eachChild : eachRootApplication.getChildren()) {
ApplicationVertex eachChildApplication = (ApplicationVertex) eachChild;
ApplicationStatusEntity.Key childKey = createKey(eachChildApplication);
Status childStatus = statusMap.get(childKey);
if (childStatus != null && maxSeverity.isLessThan(createSeverity(childStatus.computeStatus()))) {
maxSeverity = createSeverity(childStatus.computeStatus());
count = Integer.parseInt(childStatus.getStatusProperties().get("statusCount"));
}
}
returnMap.put(eachRoot, createStatus(maxSeverity, count));
}
return returnMap;
}
Aggregations