Search in sources :

Example 1 with EventThrowing

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

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 AdapterFilter (nl.nn.adapterframework.monitoring.AdapterFilter)1 EventThrowing (nl.nn.adapterframework.monitoring.EventThrowing)1 Monitor (nl.nn.adapterframework.monitoring.Monitor)1 MonitorManager (nl.nn.adapterframework.monitoring.MonitorManager)1 Trigger (nl.nn.adapterframework.monitoring.Trigger)1