Search in sources :

Example 6 with Monitor

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

the class EditTrigger method performAction.

public String performAction(DynaActionForm monitorForm, String action, int index, int triggerIndex, HttpServletResponse response) {
    MonitorManager mm = MonitorManager.getInstance();
    Monitor monitor = null;
    Trigger trigger = null;
    if (index >= 0) {
        monitor = mm.getMonitor(index);
        monitorForm.set("monitor", monitor);
        if (triggerIndex >= 0) {
            trigger = monitor.getTrigger(triggerIndex);
            monitorForm.set("trigger", trigger);
        }
    }
    List triggerTypes = new ArrayList();
    {
        triggerTypes.add("Alarm");
        triggerTypes.add("Clearing");
    }
    monitorForm.set("triggerTypes", triggerTypes);
    // Trigger formTrigger = (Trigger)monitorForm.get("trigger");
    List eventCodes;
    if (action.equals(LABEL_FILTER_ADAPTERS2EVENTS)) {
        log.debug("performAction() " + LABEL_FILTER_ADAPTERS2EVENTS);
        eventCodes = mm.getEventCodesByAdapters((String[]) monitorForm.get("selAdapters"));
    } else {
        if (action.equals(LABEL_FILTER_SOURCES2EVENTS)) {
            log.debug("performAction() " + LABEL_FILTER_SOURCES2EVENTS);
            trigger.setSources((String[]) monitorForm.get("selSources"));
            eventCodes = mm.getEventCodesBySources(trigger.getSourceList());
        } else {
            eventCodes = mm.getEventCodesBySources(mm.getThrowers());
        }
    }
    monitorForm.set("eventCodes", eventCodes);
    List adapters;
    if (action.equals(LABEL_FILTER_EVENTS2ADAPTERS)) {
        log.debug("performAction() " + LABEL_FILTER_EVENTS2ADAPTERS);
        trigger.setSourceFiltering(Trigger.SOURCE_FILTERING_BY_ADAPTER);
        adapters = mm.getAdapterNamesByEventCodes(trigger.getEventCodeList());
    } else {
        if (action.equals(LABEL_FILTER_SOURCES2ADAPTERS)) {
            log.debug("performAction() " + LABEL_FILTER_SOURCES2ADAPTERS);
            trigger.setSourceFiltering(Trigger.SOURCE_FILTERING_BY_ADAPTER);
            trigger.setSources((String[]) monitorForm.get("selSources"));
            adapters = mm.getAdapterNamesBySources(trigger.getSourceList());
        } else {
            adapters = mm.getAdapterNames();
        }
    }
    monitorForm.set("adapters", adapters);
    if (!action.equals(LABEL_FILTER_ADAPTERS2EVENTS) && !action.equals(LABEL_FILTER_ADAPTERS2SOURCES)) {
        monitorForm.set("selAdapters", trigger.getAdapters());
    }
    List sources;
    if (action.equals(LABEL_FILTER_EVENTS2SOURCES)) {
        log.debug("performAction() " + LABEL_FILTER_EVENTS2SOURCES);
        trigger.setSourceFiltering(Trigger.SOURCE_FILTERING_BY_LOWER_LEVEL_OBJECT);
        sources = mm.getEventSourceNamesByEventCodes(trigger.getEventCodeList());
    } else {
        if (action.equals(LABEL_FILTER_ADAPTERS2SOURCES)) {
            log.debug("performAction() " + LABEL_FILTER_ADAPTERS2SOURCES);
            trigger.setSourceFiltering(Trigger.SOURCE_FILTERING_BY_LOWER_LEVEL_OBJECT);
            sources = mm.getEventSourceNamesByAdapters((String[]) monitorForm.get("selAdapters"));
        } else {
            sources = mm.getEventSourceNamesByEventCodes(null);
        }
    }
    monitorForm.set("sources", sources);
    if (!action.equals(LABEL_FILTER_SOURCES2EVENTS) && !action.equals(LABEL_FILTER_SOURCES2ADAPTERS)) {
        monitorForm.set("selSources", trigger.getSources());
    }
    return null;
}
Also used : MonitorManager(nl.nn.adapterframework.monitoring.MonitorManager) Monitor(nl.nn.adapterframework.monitoring.Monitor) Trigger(nl.nn.adapterframework.monitoring.Trigger) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 7 with Monitor

use of nl.nn.adapterframework.monitoring.Monitor 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 8 with Monitor

use of nl.nn.adapterframework.monitoring.Monitor 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 9 with Monitor

use of nl.nn.adapterframework.monitoring.Monitor 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 10 with Monitor

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

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