Search in sources :

Example 1 with OnmsMonitoredServiceList

use of org.opennms.netmgt.model.OnmsMonitoredServiceList in project opennms by OpenNMS.

the class OnmsMonitoredServiceResource method getServices.

/**
     * <p>getServices</p>
     *
     * @param nodeCriteria a {@link java.lang.String} object.
     * @param ipAddress a {@link java.lang.String} object.
     * @return a {@link org.opennms.netmgt.model.OnmsMonitoredServiceList} object.
     */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public OnmsMonitoredServiceList getServices(@PathParam("nodeCriteria") String nodeCriteria, @PathParam("ipAddress") String ipAddress) {
    OnmsNode node = m_nodeDao.get(nodeCriteria);
    if (node == null) {
        throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
    }
    final OnmsIpInterface iface = node.getIpInterfaceByIpAddress(ipAddress);
    if (iface == null) {
        throw getException(Status.BAD_REQUEST, "IP Interface {} was not found on node {}.", ipAddress, nodeCriteria);
    }
    return new OnmsMonitoredServiceList(iface.getMonitoredServices());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsMonitoredServiceList(org.opennms.netmgt.model.OnmsMonitoredServiceList) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with OnmsMonitoredServiceList

use of org.opennms.netmgt.model.OnmsMonitoredServiceList in project opennms by OpenNMS.

the class IfServicesRestService method updateServices.

@PUT
public Response updateServices(@Context final UriInfo uriInfo, final MultivaluedMapImpl params) {
    final String status = params.getFirst("status");
    if (status == null || !status.matches("(A|R|S|F)")) {
        throw getException(Status.BAD_REQUEST, "Parameter status must be specified. Possible values: A (Managed), F (Forced Unmanaged), R (Rescan to Resume), S (Rescan to Suspend)");
    }
    final String services_csv = params.getFirst("services");
    final List<String> serviceList = new ArrayList<String>();
    if (services_csv != null) {
        for (String s : services_csv.split(",")) {
            serviceList.add(s);
        }
    }
    final Criteria c = getCriteria(uriInfo.getQueryParameters());
    c.setLimit(null);
    c.setOffset(null);
    final OnmsMonitoredServiceList services = new OnmsMonitoredServiceList(m_serviceDao.findMatching(c));
    if (services.isEmpty()) {
        throw getException(Status.BAD_REQUEST, "Can't find any service matching the provided criteria: {}.", uriInfo.getQueryParameters().toString());
    }
    boolean modified = false;
    for (OnmsMonitoredService svc : services) {
        boolean proceed = false;
        if (serviceList.isEmpty()) {
            proceed = true;
        } else {
            if (serviceList.contains(svc.getServiceName())) {
                proceed = true;
            }
        }
        if (proceed) {
            modified = true;
            final String currentStatus = svc.getStatus();
            svc.setStatus(status);
            m_serviceDao.update(svc);
            if ("S".equals(status) || ("A".equals(currentStatus) && "F".equals(status))) {
                LOG.debug("updateServices: suspending polling for service {} on node with IP {}", svc.getServiceName(), svc.getIpAddress().getHostAddress());
                // TODO ManageNodeServlet is sending this.
                sendEvent(EventConstants.SERVICE_UNMANAGED_EVENT_UEI, svc);
                sendEvent(EventConstants.SUSPEND_POLLING_SERVICE_EVENT_UEI, svc);
            }
            if ("R".equals(status) || ("F".equals(currentStatus) && "A".equals(status))) {
                LOG.debug("updateServices: resuming polling for service {} on node with IP {}", svc.getServiceName(), svc.getIpAddress().getHostAddress());
                sendEvent(EventConstants.RESUME_POLLING_SERVICE_EVENT_UEI, svc);
            }
        }
    }
    return modified ? Response.noContent().build() : Response.notModified().build();
}
Also used : ArrayList(java.util.ArrayList) OnmsMonitoredServiceList(org.opennms.netmgt.model.OnmsMonitoredServiceList) Criteria(org.opennms.core.criteria.Criteria) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) PUT(javax.ws.rs.PUT)

Aggregations

OnmsMonitoredServiceList (org.opennms.netmgt.model.OnmsMonitoredServiceList)2 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1 Produces (javax.ws.rs.Produces)1 Criteria (org.opennms.core.criteria.Criteria)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1