Search in sources :

Example 1 with SnmpTrapSink

use of org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapSink in project opennms by OpenNMS.

the class SnmpTrapNorthbounderConfigurationResource method updateImportMapping.

/**
     * Update import mapping.
     *
     * @param trapSinkName the trap sink name
     * @param mappingName the mapping name
     * @param params the parameters map
     * @return the response
     */
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("trapsinks/{trapsinkName}/import-mappings/{mappingName}")
public Response updateImportMapping(@PathParam("trapsinkName") final String trapSinkName, @PathParam("mappingName") final String mappingName, final MultivaluedMapImpl params) {
    writeLock();
    try {
        SnmpTrapSink trapSink = getSnmpTrapSink(trapSinkName);
        SnmpTrapMappingGroup mappingGroup = null;
        try {
            mappingGroup = trapSink.getImportMapping(mappingName);
        } catch (Throwable t) {
            throw getException(Status.INTERNAL_SERVER_ERROR, t);
        }
        if (mappingGroup == null) {
            return Response.status(404).build();
        }
        boolean modified = false;
        final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(mappingGroup);
        for (final String key : params.keySet()) {
            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) {
            try {
                trapSink.addImportMapping(mappingGroup);
            } catch (Throwable t) {
                throw getException(Status.INTERNAL_SERVER_ERROR, t);
            }
            saveConfiguration();
            return Response.noContent().build();
        }
        return Response.notModified().build();
    } finally {
        writeUnlock();
    }
}
Also used : SnmpTrapMappingGroup(org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapMappingGroup) BeanWrapper(org.springframework.beans.BeanWrapper) SnmpTrapSink(org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapSink) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 2 with SnmpTrapSink

use of org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapSink in project opennms by OpenNMS.

the class SnmpTrapNorthbounderConfigurationResource method updateSnmpTrapSink.

/**
     * Update a specific SNMP trap sink.
     *
     * @param trapSinkName the trap sink name
     * @param params the parameters map
     * @return the response
     */
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("trapsinks/{trapsinkName}")
public Response updateSnmpTrapSink(@PathParam("trapsinkName") final String trapSinkName, final MultivaluedMapImpl params) {
    writeLock();
    try {
        boolean modified = false;
        SnmpTrapSink trapSink = getSnmpTrapSink(trapSinkName);
        final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(trapSink);
        for (final String key : params.keySet()) {
            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) {
            saveConfiguration();
            return Response.noContent().build();
        }
        return Response.notModified().build();
    } finally {
        writeUnlock();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) SnmpTrapSink(org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapSink) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 3 with SnmpTrapSink

use of org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapSink in project opennms by OpenNMS.

the class SnmpTrapNorthbounderConfigurationResource method setImportMapping.

/**
     * Sets an import mapping.
     *
     * @param trapSinkName the trap sink name
     * @param mappingGroup the mapping group
     * @return the response
     */
@POST
@Path("trapsinks/{trapsinkName}/import-mappings")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
public Response setImportMapping(@PathParam("trapsinkName") final String trapSinkName, final SnmpTrapMappingGroup mappingGroup) {
    writeLock();
    try {
        SnmpTrapSink trapSink = getSnmpTrapSink(trapSinkName);
        try {
            trapSink.addImportMapping(mappingGroup);
        } catch (Throwable t) {
            throw getException(Status.INTERNAL_SERVER_ERROR, t);
        }
        saveConfiguration();
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : SnmpTrapSink(org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapSink) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Aggregations

Consumes (javax.ws.rs.Consumes)3 Path (javax.ws.rs.Path)3 SnmpTrapSink (org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapSink)3 PUT (javax.ws.rs.PUT)2 BeanWrapper (org.springframework.beans.BeanWrapper)2 POST (javax.ws.rs.POST)1 SnmpTrapMappingGroup (org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapMappingGroup)1