Search in sources :

Example 6 with MonitorManager

use of nl.nn.adapterframework.monitoring.MonitorManager in project iaf by ibissource.

the class ShowMonitors method addMonitor.

@SuppressWarnings("unchecked")
@POST
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/monitors")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response addMonitor(LinkedHashMap<String, Object> json) throws ApiException {
    initBase(servletConfig);
    String name = null;
    EventTypeEnum type = null;
    ArrayList<String> destinations = new ArrayList<String>();
    for (Entry<String, Object> entry : json.entrySet()) {
        String key = entry.getKey();
        if (key.equalsIgnoreCase("name")) {
            name = entry.getValue().toString();
        }
        if (key.equalsIgnoreCase("type")) {
            type = EventTypeEnum.getEnum(entry.getValue().toString());
        }
        if (key.equalsIgnoreCase("destinations")) {
            try {
                destinations.addAll((ArrayList<String>) entry.getValue());
            } catch (Exception e) {
                throw new ApiException("Failed to parse destinations!");
            }
        }
    }
    if (name == null)
        throw new ApiException("Name not set!");
    if (type == null)
        throw new ApiException("Type not set!");
    MonitorManager mm = MonitorManager.getInstance();
    Monitor monitor = new Monitor();
    monitor.setName(name);
    monitor.setTypeEnum(type);
    // Check if destination is set, and if it actually exists...
    if (destinations != null && destinations.size() > 0) {
        List<String> tmp = new ArrayList<String>();
        for (Iterator<String> i = destinations.iterator(); i.hasNext(); ) {
            String destination = (String) i.next();
            if (mm.getDestination(destination) != null) {
                tmp.add(destination);
            }
        }
        String[] result = new String[tmp.size()];
        result = (String[]) tmp.toArray(result);
        monitor.setDestinations(result);
    }
    mm.addMonitor(monitor);
    return Response.status(Response.Status.CREATED).build();
}
Also used : ArrayList(java.util.ArrayList) MonitorException(nl.nn.adapterframework.monitoring.MonitorException) MonitorManager(nl.nn.adapterframework.monitoring.MonitorManager) Monitor(nl.nn.adapterframework.monitoring.Monitor) EventTypeEnum(nl.nn.adapterframework.monitoring.EventTypeEnum) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 7 with MonitorManager

use of nl.nn.adapterframework.monitoring.MonitorManager in project iaf by ibissource.

the class ShowMonitors method deleteMonitor.

@DELETE
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/monitors/{monitorName}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteMonitor(@PathParam("monitorName") String monitorName) throws ApiException {
    initBase(servletConfig);
    MonitorManager mm = MonitorManager.getInstance();
    Monitor monitor = mm.findMonitor(monitorName);
    if (monitor == null) {
        throw new ApiException("Monitor not found!");
    }
    if (monitor != null) {
        int index = mm.getMonitors().indexOf(monitor);
        log.info("removing monitor nr [" + index + "] name [" + monitor.getName() + "]");
        mm.removeMonitor(index);
    }
    return Response.status(Response.Status.OK).build();
}
Also used : MonitorManager(nl.nn.adapterframework.monitoring.MonitorManager) Monitor(nl.nn.adapterframework.monitoring.Monitor) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces)

Example 8 with MonitorManager

use of nl.nn.adapterframework.monitoring.MonitorManager 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)

Example 9 with MonitorManager

use of nl.nn.adapterframework.monitoring.MonitorManager in project iaf by ibissource.

the class ShowMonitors method executeSub.

public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    // Initialize action
    initAction(request);
    if (ibisManager == null)
        return (mapping.findForward("noIbisContext"));
    String forward = null;
    DynaActionForm monitorForm = getPersistentForm(mapping, form, request);
    if (isCancelled(request)) {
        log.debug("edit is canceled");
        forward = determineExitForward(monitorForm);
    } else {
        // debugFormData(request,form);
        String action = request.getParameter("action");
        String indexStr = request.getParameter("index");
        String triggerIndexStr = request.getParameter("triggerIndex");
        int index = -1;
        if (StringUtils.isNotEmpty(indexStr)) {
            index = Integer.parseInt(indexStr);
        }
        int triggerIndex = -1;
        if (StringUtils.isNotEmpty(triggerIndexStr)) {
            triggerIndex = Integer.parseInt(triggerIndexStr);
        }
        MonitorManager mm = MonitorManager.getInstance();
        if ("getStatus".equals(action)) {
            response.setContentType("text/xml");
            PrintWriter out = response.getWriter();
            out.print(mm.getStatusXml().toXML());
            out.close();
            return null;
        }
        Lock lock = mm.getStructureLock();
        try {
            lock.acquireExclusive();
            forward = performAction(monitorForm, action, index, triggerIndex, response);
            log.debug("forward [" + forward + "] returned from performAction");
            mm.reconfigure();
        } catch (Exception e) {
            error("could not perform action [" + action + "] on monitorIndex [" + index + "] triggerIndex [" + triggerIndex + "]", e);
        } finally {
            lock.releaseExclusive();
        }
        if (response.isCommitted()) {
            return null;
        }
    }
    if (StringUtils.isEmpty(forward)) {
        log.debug("replacing empty forward with [success]");
        forward = "success";
    }
    initForm(monitorForm);
    ActionForward af = mapping.findForward(forward);
    if (af == null) {
        throw new ServletException("could not find forward [" + forward + "]");
    }
    // Forward control to the specified success URI
    log.debug("forward to [" + forward + "], path [" + af.getPath() + "]");
    return (af);
}
Also used : ServletException(javax.servlet.ServletException) MonitorManager(nl.nn.adapterframework.monitoring.MonitorManager) DynaActionForm(org.apache.struts.action.DynaActionForm) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) MonitorException(nl.nn.adapterframework.monitoring.MonitorException) ActionForward(org.apache.struts.action.ActionForward) PrintWriter(java.io.PrintWriter) Lock(nl.nn.adapterframework.util.Lock)

Example 10 with MonitorManager

use of nl.nn.adapterframework.monitoring.MonitorManager in project iaf by ibissource.

the class EditMonitor method performAction.

protected String performAction(DynaActionForm monitorForm, String action, int index, int triggerIndex, HttpServletResponse response) {
    MonitorManager mm = MonitorManager.getInstance();
    if (index >= 0) {
        Monitor monitor = mm.getMonitor(index);
        monitorForm.set("monitor", monitor);
    }
    return null;
}
Also used : MonitorManager(nl.nn.adapterframework.monitoring.MonitorManager) Monitor(nl.nn.adapterframework.monitoring.Monitor)

Aggregations

MonitorManager (nl.nn.adapterframework.monitoring.MonitorManager)11 Monitor (nl.nn.adapterframework.monitoring.Monitor)10 ArrayList (java.util.ArrayList)4 RolesAllowed (javax.annotation.security.RolesAllowed)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 MonitorException (nl.nn.adapterframework.monitoring.MonitorException)4 Trigger (nl.nn.adapterframework.monitoring.Trigger)4 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 Date (java.util.Date)2 List (java.util.List)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 ServletException (javax.servlet.ServletException)1 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1