Search in sources :

Example 1 with ApplicationStatusEntity

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);
}
Also used : ApplicationStatusEntity(org.opennms.netmgt.dao.api.ApplicationStatusEntity) Date(java.util.Date) Test(org.junit.Test)

Example 2 with ApplicationStatusEntity

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;
}
Also used : ArrayList(java.util.ArrayList) ApplicationStatusEntity(org.opennms.netmgt.dao.api.ApplicationStatusEntity) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with ApplicationStatusEntity

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;
}
Also used : DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) Status(org.opennms.features.topology.api.topo.Status) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApplicationStatusEntity(org.opennms.netmgt.dao.api.ApplicationStatusEntity) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Aggregations

ApplicationStatusEntity (org.opennms.netmgt.dao.api.ApplicationStatusEntity)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Test (org.junit.Test)1 DefaultStatus (org.opennms.features.topology.api.topo.DefaultStatus)1 Status (org.opennms.features.topology.api.topo.Status)1 VertexRef (org.opennms.features.topology.api.topo.VertexRef)1 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)1