Search in sources :

Example 71 with OnmsIpInterface

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

the class OnmsIpInterfaceResource method updateIpInterface.

/**
 * <p>updateIpInterface</p>
 *
 * @param nodeCriteria a {@link java.lang.String} object.
 * @param ipAddress a {@link java.lang.String} object.
 * @param params a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
 * @return a {@link javax.ws.rs.core.Response} object.
 */
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{ipAddress}")
public Response updateIpInterface(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("ipAddress") final String ipAddress, final MultivaluedMapImpl params) {
    writeLock();
    try {
        final OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null) {
            throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
        }
        final OnmsIpInterface ipInterface = node.getIpInterfaceByIpAddress(ipAddress);
        if (ipInterface == null) {
            throw getException(Status.CONFLICT, "Can't find interface with IP address {} for node {}.", ipAddress, nodeCriteria);
        }
        LOG.debug("updateIpInterface: updating ip interface {}", ipInterface);
        final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(ipInterface);
        boolean modified = false;
        for (final String key : params.keySet()) {
            // skip nodeId since we already know the node this is associated with and don't want to overwrite it
            if ("nodeId".equals(key)) {
                continue;
            }
            if (wrapper.isWritableProperty(key)) {
                final String stringValue = params.getFirst(key);
                final Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
                wrapper.setPropertyValue(key, value);
                modified = true;
            }
        }
        if (modified) {
            LOG.debug("updateIpInterface: ip interface {} updated", ipInterface);
            m_ipInterfaceDao.saveOrUpdate(ipInterface);
            return Response.noContent().build();
        }
        return Response.notModified().build();
    } finally {
        writeUnlock();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 72 with OnmsIpInterface

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

the class OnmsMonitoredServiceResource method updateService.

/**
 * <p>updateService</p>
 *
 * @param nodeCriteria a {@link java.lang.String} object.
 * @param ipAddress a {@link java.lang.String} object.
 * @param serviceName a {@link java.lang.String} object.
 * @param params a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
 * @return a {@link javax.ws.rs.core.Response} object.
 */
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{service}")
public Response updateService(@PathParam("nodeCriteria") String nodeCriteria, @PathParam("ipAddress") String ipAddress, @PathParam("service") String serviceName, MultivaluedMapImpl params) {
    writeLock();
    try {
        OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null)
            throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
        OnmsIpInterface intf = node.getIpInterfaceByIpAddress(ipAddress);
        if (intf == null)
            throw getException(Status.BAD_REQUEST, "IP Interface {} was not found on node {}.", ipAddress, nodeCriteria);
        OnmsMonitoredService service = intf.getMonitoredServiceByServiceType(serviceName);
        if (service == null)
            throw getException(Status.BAD_REQUEST, "Monitored Service {} was not found on IP Interface {} and node {}.", serviceName, ipAddress, nodeCriteria);
        LOG.debug("updateService: updating service {}", service);
        boolean modified = false;
        BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(service);
        for (String key : params.keySet()) {
            if (wrapper.isWritableProperty(key)) {
                String stringValue = params.getFirst(key);
                Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
                if (key.equals("status")) {
                    if ("S".equals(value) || ("A".equals(service.getStatus()) && "F".equals(value))) {
                        LOG.debug("updateService: suspending polling for service {} on node with IP {}", service.getServiceName(), service.getIpAddress().getHostAddress());
                        value = "F";
                        sendEvent(EventConstants.SUSPEND_POLLING_SERVICE_EVENT_UEI, service);
                    }
                    if ("R".equals(value) || ("F".equals(service.getStatus()) && "A".equals(value))) {
                        LOG.debug("updateService: resuming polling for service {} on node with IP {}", service.getServiceName(), service.getIpAddress().getHostAddress());
                        value = "A";
                        sendEvent(EventConstants.RESUME_POLLING_SERVICE_EVENT_UEI, service);
                    }
                }
                wrapper.setPropertyValue(key, value);
                modified = true;
            }
        }
        if (modified) {
            LOG.debug("updateSservice: service {} updated", service);
            m_serviceDao.saveOrUpdate(service);
            return Response.noContent().build();
        }
        return Response.notModified().build();
    } finally {
        writeUnlock();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 73 with OnmsIpInterface

use of org.opennms.netmgt.model.OnmsIpInterface 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 74 with OnmsIpInterface

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

the class OnmsMonitoredServiceResource method deleteService.

/**
 * <p>deleteService</p>
 *
 * @param nodeCriteria a {@link java.lang.String} object.
 * @param ipAddress a {@link java.lang.String} object.
 * @param serviceName a {@link java.lang.String} object.
 * @return a {@link javax.ws.rs.core.Response} object.
 */
@DELETE
@Path("{service}")
public Response deleteService(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("ipAddress") final String ipAddress, @PathParam("service") final String serviceName) {
    writeLock();
    try {
        OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null)
            throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
        OnmsIpInterface intf = node.getIpInterfaceByIpAddress(ipAddress);
        if (intf == null)
            throw getException(Status.BAD_REQUEST, "IP Interface {} was not found on node {}.", ipAddress, nodeCriteria);
        OnmsMonitoredService service = intf.getMonitoredServiceByServiceType(serviceName);
        if (service == null)
            throw getException(Status.CONFLICT, "Monitored Service {} was not found on IP Interface {} and node {}.", serviceName, ipAddress, nodeCriteria);
        LOG.debug("deleteService: deleting service {} from node {}", serviceName, nodeCriteria);
        Event e = EventUtils.createDeleteServiceEvent("OpenNMS.REST", node.getId(), ipAddress, serviceName, -1L);
        sendEvent(e);
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Event(org.opennms.netmgt.xml.event.Event) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 75 with OnmsIpInterface

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

the class OnmsSnmpInterfaceResource method addSnmpInterface.

/**
 * <p>addSnmpInterface</p>
 *
 * @param nodeCriteria a {@link java.lang.String} object.
 * @param snmpInterface a {@link org.opennms.netmgt.model.OnmsSnmpInterface} object.
 * @return a {@link javax.ws.rs.core.Response} object.
 */
@POST
@Consumes(MediaType.APPLICATION_XML)
public Response addSnmpInterface(@Context final UriInfo uriInfo, @PathParam("nodeCriteria") final String nodeCriteria, final OnmsSnmpInterface snmpInterface) {
    writeLock();
    try {
        final OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null)
            throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
        if (snmpInterface == null)
            throw getException(Status.BAD_REQUEST, "SNMP interface object cannot be null");
        LOG.debug("addSnmpInterface: adding interface {}", snmpInterface);
        node.addSnmpInterface(snmpInterface);
        if (snmpInterface.getPrimaryIpInterface() != null) {
            final OnmsIpInterface iface = snmpInterface.getPrimaryIpInterface();
            iface.setSnmpInterface(snmpInterface);
        // TODO Add important events here
        }
        m_snmpInterfaceDao.save(snmpInterface);
        final Integer ifIndex = snmpInterface.getIfIndex();
        return Response.created(getRedirectUri(uriInfo, ifIndex)).build();
    } finally {
        writeUnlock();
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Aggregations

OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)186 OnmsNode (org.opennms.netmgt.model.OnmsNode)117 Test (org.junit.Test)53 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)43 InetAddress (java.net.InetAddress)40 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)33 Transactional (org.springframework.transaction.annotation.Transactional)30 ArrayList (java.util.ArrayList)22 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)21 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)20 Date (java.util.Date)17 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)17 File (java.io.File)16 HashMap (java.util.HashMap)15 Before (org.junit.Before)15 LinkedList (java.util.LinkedList)14 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)14 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)12 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)12 OnmsResource (org.opennms.netmgt.model.OnmsResource)11