use of nl.nn.adapterframework.monitoring.MonitorException in project iaf by ibissource.
the class ShowMonitors method raiseMonitor.
@PUT
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/monitors/{monitorName}")
@Produces(MediaType.APPLICATION_JSON)
public Response raiseMonitor(@PathParam("monitorName") String monitorName, @QueryParam("action") String action) throws ApiException {
initBase(servletConfig);
MonitorManager mm = MonitorManager.getInstance();
Monitor monitor = mm.findMonitor(monitorName);
if (monitor == null) {
throw new ApiException("Monitor not found!");
}
if (action.equals("clearMonitor")) {
try {
log.info("clearing monitor [" + monitor.getName() + "]");
monitor.changeState(new Date(), false, SeverityEnum.WARNING, null, null, null);
} catch (MonitorException e) {
throw new ApiException("Failed to change monitor state!");
}
}
if (action.equals("raiseMonitor")) {
try {
log.info("raising monitor [" + monitor.getName() + "]");
monitor.changeState(new Date(), true, SeverityEnum.WARNING, null, null, null);
} catch (MonitorException e) {
throw new ApiException("Failed to change monitor state!");
}
}
return Response.status(Response.Status.OK).build();
}
use of nl.nn.adapterframework.monitoring.MonitorException in project iaf by ibissource.
the class ShowMonitorExecute method performAction.
protected String performAction(DynaActionForm monitorForm, String action, int index, int triggerIndex, HttpServletResponse response) throws MonitorException {
log.debug("performing action [" + action + "] on monitorName nr [" + index + "]");
MonitorManager mm = MonitorManager.getInstance();
if (StringUtils.isEmpty(action)) {
log.warn("monitorHandler did not find action");
return null;
}
if (action.equals("edit")) {
FormFile form_file = (FormFile) monitorForm.get("configFile");
if (form_file != null && form_file.getFileSize() > 0) {
log.debug("Upload of file [" + form_file.getFileName() + "] ContentType[" + form_file.getContentType() + "]");
Digester d = new Digester();
mm.setDigesterRules(d);
mm.getMonitors().clear();
d.push(mm);
try {
d.parse(form_file.getInputStream());
} catch (Exception e) {
error("cannot parse file [" + form_file.getFileName() + "]", e);
}
} else {
mm.updateDestinations((String[]) monitorForm.get("selDestinations"));
}
mm.setEnabled(((Boolean) monitorForm.get("enabled")).booleanValue());
return null;
}
if (action.equals("createMonitor")) {
Monitor monitor = new Monitor();
int i = 1;
while (mm.findMonitor("monitor " + i) != null) {
i++;
}
monitor.setName("monitor " + i);
mm.addMonitor(monitor);
return null;
}
if (action.equals("deleteMonitor")) {
Monitor monitor = mm.getMonitor(index);
if (monitor != null) {
log.info("removing monitor nr [" + index + "] name [" + monitor.getName() + "]");
mm.removeMonitor(index);
}
return null;
}
if (action.equals("clearMonitor")) {
Monitor monitor = mm.getMonitor(index);
if (monitor != null) {
log.info("clearing monitor [" + monitor.getName() + "]");
monitor.changeState(new Date(), false, SeverityEnum.WARNING, null, null, null);
}
return null;
}
if (action.equals("raiseMonitor")) {
Monitor monitor = mm.getMonitor(index);
if (monitor != null) {
log.info("raising monitor [" + monitor.getName() + "]");
monitor.changeState(new Date(), true, SeverityEnum.WARNING, null, null, null);
}
return null;
}
if (action.equals("exportConfig")) {
try {
response.setContentType("text/xml; charset=" + Misc.DEFAULT_INPUT_STREAM_ENCODING);
response.setHeader("Content-Disposition", "attachment; filename=\"monitorConfig-" + AppConstants.getInstance().getProperty("instance.name", "") + ".xml\"");
PrintWriter writer = response.getWriter();
XmlBuilder config = mm.toXml();
writer.print(config.toXML());
writer.close();
} catch (IOException e) {
error("could not export config", e);
}
return null;
}
log.debug("should performing action [" + action + "]");
return null;
}
Aggregations