use of org.opennms.netmgt.events.api.EventProxyException in project opennms by OpenNMS.
the class OnmsSnmpInterfaceResource method updateSnmpInterface.
/**
* <p>updateSnmpInterface</p>
*
* @param nodeCriteria a {@link java.lang.String} object.
* @param ifIndex a int.
* @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("{ifIndex}")
public Response updateSnmpInterface(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("ifIndex") final int ifIndex, 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);
if (ifIndex < 0)
throw getException(Status.BAD_REQUEST, "Invalid ifIndex specified for SNMP interface on node {}: {}", nodeCriteria, Integer.toString(ifIndex));
final OnmsSnmpInterface snmpInterface = node.getSnmpInterfaceWithIfIndex(ifIndex);
if (snmpInterface == null)
throw getException(Status.BAD_REQUEST, "Can't find SNMP interface with ifIndex {} for node {}", Integer.toString(ifIndex), nodeCriteria);
LOG.debug("updateSnmpInterface: updating SNMP interface {}", snmpInterface);
boolean modified = false;
final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(snmpInterface);
for (final String key : params.keySet()) {
// don't try setting the node data
if ("nodeId".equals(key))
continue;
// don't try setting ipinterface data
if ("ipInterface".equals(key) || "ipInterfaces".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("updateSnmpInterface: SNMP interface {} updated", snmpInterface);
m_snmpInterfaceDao.saveOrUpdate(snmpInterface);
}
Event e = null;
if (params.containsKey("collect")) {
// TODO Is this still valid if the interface was not modified ?
// we've updated the collection flag so we need to send an event to redo collection
final EventBuilder bldr = new EventBuilder(EventConstants.REINITIALIZE_PRIMARY_SNMP_INTERFACE_EVENT_UEI, "ReST");
bldr.setNode(node);
// Bug NMS-4432 says that sometimes the primary SNMP interface is null
// so we need to check for that before we set the interface
final OnmsIpInterface iface = node.getPrimaryInterface();
if (iface == null) {
LOG.warn("updateSnmpInterface: Cannot send {} event because node {} has no primary SNMP interface", EventConstants.REINITIALIZE_PRIMARY_SNMP_INTERFACE_EVENT_UEI, node.getId());
} else {
bldr.setInterface(iface.getIpAddress());
e = bldr.getEvent();
}
}
if (e != null) {
try {
m_eventProxy.send(e);
} catch (final EventProxyException ex) {
throw getException(Response.Status.INTERNAL_SERVER_ERROR, "Exception occurred sending event {} : {}", e.getUei(), ex.getMessage());
}
}
return modified ? Response.noContent().build() : Response.notModified().build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.events.api.EventProxyException in project opennms by OpenNMS.
the class NodeRestService method sendEvent.
private void sendEvent(final String uei, final int nodeId, String nodeLabel) {
try {
final EventBuilder bldr = new EventBuilder(uei, "ReST");
bldr.setNodeid(nodeId);
bldr.addParam("nodelabel", nodeLabel);
m_eventProxy.send(bldr.getEvent());
} catch (final EventProxyException e) {
throw getException(Status.INTERNAL_SERVER_ERROR, "Cannot send event {} : {}", uei, e.getMessage());
}
}
use of org.opennms.netmgt.events.api.EventProxyException in project opennms by OpenNMS.
the class DefaultGraphResultsService method sendEvent.
private void sendEvent(List<String> filesToPromote) {
EventBuilder bldr = new EventBuilder(EventConstants.PROMOTE_QUEUE_DATA_UEI, "OpenNMS.Webapp");
bldr.addParam(EventConstants.PARM_FILES_TO_PROMOTE, filesToPromote);
try {
m_eventProxy.send(bldr.getEvent());
} catch (EventProxyException e) {
LOG.warn("Unable to send promotion event to opennms daemon", e);
}
}
use of org.opennms.netmgt.events.api.EventProxyException in project opennms by OpenNMS.
the class MinionRestService method delete.
@DELETE
@Path("{id}")
@Override
public Response delete(@PathParam("id") final String id) {
final OnmsMinion minion = getDao().get(id);
final String location = minion.getLocation();
Response response = super.delete(id);
final EventBuilder eventBuilder = new EventBuilder(EventConstants.MONITORING_SYSTEM_DELETED_UEI, "OpenNMS.WebUI");
eventBuilder.addParam(EventConstants.PARAM_MONITORING_SYSTEM_TYPE, OnmsMonitoringSystem.TYPE_MINION);
eventBuilder.addParam(EventConstants.PARAM_MONITORING_SYSTEM_ID, id);
eventBuilder.addParam(EventConstants.PARAM_MONITORING_SYSTEM_LOCATION, location);
try {
m_eventProxy.send(eventBuilder.getEvent());
} catch (final EventProxyException e) {
LOG.warn(" Failed to send Event on Minion deletion " + e.getMessage(), e);
}
return response;
}
use of org.opennms.netmgt.events.api.EventProxyException in project opennms by OpenNMS.
the class AssetRecordResource method updateAssetRecord.
/**
* <p>updateAssetRecord</p>
*
* @param nodeCriteria 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)
public Response updateAssetRecord(@PathParam("nodeCriteria") final String nodeCriteria, final MultivaluedMapImpl params) {
OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null) {
throw getException(Status.BAD_REQUEST, "updateAssetRecord: Can't find node " + nodeCriteria);
}
OnmsAssetRecord assetRecord = getAssetRecord(node);
if (assetRecord == null) {
throw getException(Status.BAD_REQUEST, "updateAssetRecord: Node " + node + " could not update ");
}
if (assetRecord.getGeolocation() == null) {
assetRecord.setGeolocation(new OnmsGeolocation());
}
LOG.debug("updateAssetRecord: updating asset {}", assetRecord);
boolean modified = false;
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(assetRecord);
wrapper.registerCustomEditor(Date.class, new ISO8601DateEditor());
for (String key : params.keySet()) {
if (wrapper.isWritableProperty(key)) {
String stringValue = params.getFirst(key);
Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
wrapper.setPropertyValue(key, value);
modified = true;
}
}
if (modified) {
LOG.debug("updateAssetRecord: assetRecord {} updated", assetRecord);
m_assetRecordDao.saveOrUpdate(assetRecord);
try {
sendEvent(EventConstants.ASSET_INFO_CHANGED_EVENT_UEI, node.getId());
} catch (EventProxyException e) {
throw getException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
}
return Response.noContent().build();
}
return Response.notModified().build();
}
Aggregations