Search in sources :

Example 6 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class OnmsIpInterfaceResource method getIpInterfaces.

/**
     * <p>getIpInterfaces</p>
     *
     * @param nodeCriteria a {@link java.lang.String} object.
     * @return a {@link org.opennms.netmgt.model.OnmsIpInterfaceList} object.
     */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public OnmsIpInterfaceList getIpInterfaces(@Context final UriInfo uriInfo, @PathParam("nodeCriteria") final String nodeCriteria) {
    LOG.debug("getIpInterfaces: reading interfaces for node {}", nodeCriteria);
    final OnmsNode node = m_nodeDao.get(nodeCriteria);
    final MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
    final CriteriaBuilder builder = new CriteriaBuilder(OnmsIpInterface.class);
    builder.alias("monitoredServices.serviceType", "serviceType", JoinType.LEFT_JOIN);
    builder.ne("isManaged", "D");
    builder.limit(20);
    applyQueryFilters(params, builder);
    builder.alias("node", "node");
    builder.eq("node.id", node.getId());
    final OnmsIpInterfaceList interfaceList = new OnmsIpInterfaceList(m_ipInterfaceDao.findMatching(builder.toCriteria()));
    interfaceList.setTotalCount(m_ipInterfaceDao.countMatching(builder.count().toCriteria()));
    return interfaceList;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterfaceList(org.opennms.netmgt.model.OnmsIpInterfaceList) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class OnmsSnmpInterfaceResource method getSnmpInterfaces.

/**
     * <p>getSnmpInterfaces</p>
     *
     * @param nodeCriteria a {@link java.lang.String} object.
     * @return a {@link org.opennms.netmgt.model.OnmsSnmpInterfaceList} object.
     */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public OnmsSnmpInterfaceList getSnmpInterfaces(@Context final UriInfo uriInfo, @PathParam("nodeCriteria") final String nodeCriteria) {
    final OnmsNode node = m_nodeDao.get(nodeCriteria);
    final MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
    final CriteriaBuilder builder = new CriteriaBuilder(OnmsSnmpInterface.class);
    builder.ne("collect", "D");
    builder.limit(20);
    applyQueryFilters(params, builder);
    builder.eq("node.id", node.getId());
    final OnmsSnmpInterfaceList snmpList = new OnmsSnmpInterfaceList(m_snmpInterfaceDao.findMatching(builder.toCriteria()));
    snmpList.setTotalCount(m_snmpInterfaceDao.countMatching(builder.count().toCriteria()));
    return snmpList;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsSnmpInterfaceList(org.opennms.netmgt.model.OnmsSnmpInterfaceList) OnmsNode(org.opennms.netmgt.model.OnmsNode) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 8 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class OutageRestService method forNodeId.

/**
     * <p>forNodeId</p>
     *
     * @param nodeId a int.
     * @param dateRange a long.
     * @param startTs a java.lang.Long.
     * @param endTs a java.lang.Long.
     * @return a {@link org.opennms.netmgt.model.OnmsOutageCollection} object.
     */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Transactional
@Path("forNode/{nodeId}")
public OnmsOutageCollection forNodeId(@Context final UriInfo uriInfo, @PathParam("nodeId") final int nodeId, @DefaultValue("604800000") @QueryParam("dateRange") final long dateRange, @QueryParam("start") final Long startTs, @QueryParam("end") final Long endTs) {
    final CriteriaBuilder builder = new CriteriaBuilder(OnmsOutage.class);
    builder.eq("node.id", nodeId);
    builder.alias("monitoredService", "monitoredService");
    builder.alias("monitoredService.ipInterface", "ipInterface");
    builder.alias("monitoredService.ipInterface.node", "node");
    builder.alias("monitoredService.serviceType", "serviceType");
    final MultivaluedMap<String, String> params = new MultivaluedMapImpl();
    params.putAll(uriInfo.getQueryParameters());
    LOG.debug("Processing outages for node {} using {}", nodeId, params);
    if (startTs != null && endTs != null) {
        params.remove("start");
        params.remove("end");
        final Date start = new Date(startTs);
        final Date end = new Date(endTs);
        LOG.debug("Getting all outages from {} to {} for node {}", start, end, nodeId);
        builder.or(Restrictions.isNull("ifRegainedService"), Restrictions.and(Restrictions.gt("ifLostService", start), Restrictions.lt("ifLostService", end)));
    } else {
        params.remove("dateRange");
        final Date start = new Date(System.currentTimeMillis() - dateRange);
        LOG.debug("Getting all outgae from {} to current date for node {}", start, nodeId);
        builder.or(Restrictions.isNull("ifRegainedService"), Restrictions.gt("ifLostService", start));
    }
    applyQueryFilters(params, builder);
    builder.orderBy("id").desc();
    return new OnmsOutageCollection(m_outageDao.findMatching(builder.toCriteria()));
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) MultivaluedMapImpl(org.opennms.web.rest.support.MultivaluedMapImpl) OnmsOutageCollection(org.opennms.netmgt.model.OnmsOutageCollection) Date(java.util.Date) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class SummaryDashlet method countBySeverity.

/**
     * Searches for alarms with the given criterias and returns the number found.
     *
     * @param acknowledged search for acknowledged or unacknowledged alarms
     * @param age          the age of the alarms
     * @param onmsSeverity the {@link OnmsSeverity} to search for
     * @return number of alarms found
     */
public int countBySeverity(boolean acknowledged, long age, OnmsSeverity onmsSeverity) {
    CriteriaBuilder criteriaBuilder = new CriteriaBuilder(OnmsAlarm.class);
    if (acknowledged) {
        criteriaBuilder.isNotNull("alarmAckUser");
    } else {
        criteriaBuilder.isNull("alarmAckUser");
    }
    criteriaBuilder.eq("severity", onmsSeverity);
    criteriaBuilder.sql("EXTRACT(EPOCH FROM CURRENT_TIMESTAMP - lastEventTime) < " + age);
    return m_alarmDao.countMatching(criteriaBuilder.toCriteria());
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder)

Example 10 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class SummaryDashlet method countByUei.

/**
     * Searches for alarms with the given criterias and returns the number found.
     *
     * @param acknowledged search for acknowledged or unacknowledged alarms
     * @param age          the age of the alarms
     * @param uei          search for alarms with the specified uei
     * @return number of alarms found
     */
public int countByUei(boolean acknowledged, long age, String uei) {
    CriteriaBuilder criteriaBuilder = new CriteriaBuilder(OnmsAlarm.class);
    if (acknowledged) {
        criteriaBuilder.isNotNull("alarmAckUser");
    } else {
        criteriaBuilder.isNull("alarmAckUser");
    }
    criteriaBuilder.eq("uei", uei);
    criteriaBuilder.sql("EXTRACT(EPOCH FROM CURRENT_TIMESTAMP - lastEventTime) < " + age);
    return m_alarmDao.countMatching(criteriaBuilder.toCriteria());
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder)

Aggregations

CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)128 Test (org.junit.Test)55 Criteria (org.opennms.core.criteria.Criteria)28 OnmsNode (org.opennms.netmgt.model.OnmsNode)21 Transactional (org.springframework.transaction.annotation.Transactional)20 Date (java.util.Date)18 GET (javax.ws.rs.GET)13 Produces (javax.ws.rs.Produces)12 InetSocketAddress (java.net.InetSocketAddress)8 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)8 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)8 ArrayList (java.util.ArrayList)7 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 OnmsMinion (org.opennms.netmgt.model.minion.OnmsMinion)6 RateLimiter (com.google.common.util.concurrent.RateLimiter)4 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)4 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)4 ScanReport (org.opennms.netmgt.model.ScanReport)4 ScanReportRestService (org.opennms.web.rest.v2.ScanReportRestService)4 PUT (javax.ws.rs.PUT)3