Search in sources :

Example 1 with MonitorManager

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

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

the class ShowMonitors method getMonitors.

@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/monitors")
@Produces(MediaType.APPLICATION_JSON)
public Response getMonitors() throws ApiException {
    initBase(servletConfig);
    Map<String, Object> returnMap = new HashMap<String, Object>();
    MonitorManager mm = MonitorManager.getInstance();
    List<Map<String, Object>> monitors = new ArrayList<Map<String, Object>>();
    for (int i = 0; i < mm.getMonitors().size(); i++) {
        Map<String, Object> monitorMap = new HashMap<String, Object>();
        Monitor monitor = mm.getMonitor(i);
        monitorMap.put("name", monitor.getName());
        monitorMap.put("type", monitor.getType());
        monitorMap.put("lastHit", monitor.getLastHit());
        monitorMap.put("raised", monitor.isRaised());
        monitorMap.put("changed", monitor.getStateChangeDt());
        monitorMap.put("hits", monitor.getAdditionalHitCount());
        String eventSource = null;
        EventThrowing source = monitor.getAlarmSource();
        if (source != null) {
            eventSource = source.getEventSourceName();
        }
        monitorMap.put("source", eventSource);
        monitorMap.put("severity", monitor.getAlarmSeverity());
        List<Map<String, Object>> triggers = new ArrayList<Map<String, Object>>();
        for (Iterator<Trigger> it = monitor.getTriggers().iterator(); it.hasNext(); ) {
            Trigger trigger = (Trigger) it.next();
            Map<String, Object> triggerMap = new HashMap<String, Object>();
            triggerMap.put("type", trigger.getType());
            triggerMap.put("eventCodes", trigger.getEventCodes());
            triggerMap.put("sources", trigger.getSourceList());
            triggerMap.put("severity", trigger.getSeverity());
            triggerMap.put("threshold", trigger.getThreshold());
            triggerMap.put("period", trigger.getPeriod());
            if (trigger.getAdapterFilters() != null) {
                List<Map<String, Object>> filters = new ArrayList<Map<String, Object>>();
                if (trigger.getSourceFiltering() != Trigger.SOURCE_FILTERING_NONE) {
                    for (Iterator<String> it1 = trigger.getAdapterFilters().keySet().iterator(); it1.hasNext(); ) {
                        Map<String, Object> adapter = new HashMap<String, Object>(2);
                        String adapterName = it1.next();
                        AdapterFilter af = (AdapterFilter) trigger.getAdapterFilters().get(adapterName);
                        adapter.put("name", adapterName);
                        if (trigger.isFilterOnLowerLevelObjects()) {
                            adapter.put("sources", af.getSubObjectList());
                        }
                        filters.add(adapter);
                    }
                }
                triggerMap.put("filterExclusive", trigger.isFilterExclusive());
                triggerMap.put("filters", filters);
            }
            triggers.add(triggerMap);
        }
        monitorMap.put("triggers", triggers);
        List<String> destinations = new ArrayList<String>();
        Set<String> d = monitor.getDestinationSet();
        for (Iterator<String> it = d.iterator(); it.hasNext(); ) {
            destinations.add(it.next());
        }
        monitorMap.put("destinations", destinations);
        monitors.add(monitorMap);
    }
    returnMap.put("monitors", monitors);
    returnMap.put("enabled", new Boolean(mm.isEnabled()));
    returnMap.put("severities", SeverityEnum.getNames());
    returnMap.put("eventTypes", EventTypeEnum.getNames());
    returnMap.put("destinations", mm.getDestinations().keySet());
    return Response.status(Response.Status.OK).entity(returnMap).build();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) MonitorManager(nl.nn.adapterframework.monitoring.MonitorManager) Monitor(nl.nn.adapterframework.monitoring.Monitor) EventThrowing(nl.nn.adapterframework.monitoring.EventThrowing) Trigger(nl.nn.adapterframework.monitoring.Trigger) AdapterFilter(nl.nn.adapterframework.monitoring.AdapterFilter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with MonitorManager

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

the class ShowMonitors method initForm.

public void initForm(DynaActionForm monitorForm) {
    MonitorManager mm = MonitorManager.getInstance();
    monitorForm.set("monitorManager", mm);
    List destinations = new ArrayList();
    for (int i = 0; i < mm.getMonitors().size(); i++) {
        Monitor m = mm.getMonitor(i);
        Set d = m.getDestinationSet();
        for (Iterator it = d.iterator(); it.hasNext(); ) {
            destinations.add(i + "," + it.next());
        }
    }
    String[] selDest = new String[destinations.size()];
    selDest = (String[]) destinations.toArray(selDest);
    monitorForm.set("selDestinations", selDest);
    monitorForm.set("enabled", new Boolean(mm.isEnabled()));
    monitorForm.set("eventTypes", EventTypeEnum.getEnumList());
    monitorForm.set("severities", SeverityEnum.getEnumList());
}
Also used : MonitorManager(nl.nn.adapterframework.monitoring.MonitorManager) Monitor(nl.nn.adapterframework.monitoring.Monitor) Set(java.util.Set) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with MonitorManager

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

the class EditMonitorExecute method performAction.

public String performAction(DynaActionForm monitorForm, String action, int index, int triggerIndex, HttpServletResponse response) {
    MonitorManager mm = MonitorManager.getInstance();
    if (index >= 0) {
        Monitor monitor = mm.getMonitor(index);
        if (action.equals("createTrigger")) {
            int triggerCount = monitor.getTriggers().size();
            Trigger trigger = new Trigger();
            switch(triggerCount) {
                case 0:
                    trigger.setAlarm(true);
                case 1:
                    trigger.setAlarm(false);
                default:
                    trigger.setAlarm(true);
            }
            monitor.registerTrigger(trigger);
        } else if (action.equals("deleteTrigger")) {
            monitor.getTriggers().remove(triggerIndex);
            return determineExitForward(monitorForm);
        } else if (action.equals("OK") || action.equals("Apply")) {
            Monitor formMonitor = (Monitor) monitorForm.get("monitor");
            monitor.setName(formMonitor.getName());
            monitor.setTypeEnum(formMonitor.getTypeEnum());
            monitor.setDestinations(formMonitor.getDestinations());
            if (action.equals("OK")) {
                return determineExitForward(monitorForm);
            }
        }
    }
    return "self";
}
Also used : MonitorManager(nl.nn.adapterframework.monitoring.MonitorManager) Monitor(nl.nn.adapterframework.monitoring.Monitor) Trigger(nl.nn.adapterframework.monitoring.Trigger)

Example 5 with MonitorManager

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

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