Search in sources :

Example 1 with MonitorException

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();
}
Also used : MonitorManager(nl.nn.adapterframework.monitoring.MonitorManager) Monitor(nl.nn.adapterframework.monitoring.Monitor) Date(java.util.Date) MonitorException(nl.nn.adapterframework.monitoring.MonitorException) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 2 with MonitorException

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;
}
Also used : MonitorManager(nl.nn.adapterframework.monitoring.MonitorManager) Monitor(nl.nn.adapterframework.monitoring.Monitor) Digester(org.apache.commons.digester.Digester) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) IOException(java.io.IOException) IOException(java.io.IOException) MonitorException(nl.nn.adapterframework.monitoring.MonitorException) Date(java.util.Date) FormFile(org.apache.struts.upload.FormFile) PrintWriter(java.io.PrintWriter)

Aggregations

Date (java.util.Date)2 Monitor (nl.nn.adapterframework.monitoring.Monitor)2 MonitorException (nl.nn.adapterframework.monitoring.MonitorException)2 MonitorManager (nl.nn.adapterframework.monitoring.MonitorManager)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)1 Digester (org.apache.commons.digester.Digester)1 FormFile (org.apache.struts.upload.FormFile)1