Search in sources :

Example 1 with ITrigger

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

the class ShowMonitors method updateTrigger.

@PUT
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/{monitorName}/triggers/{trigger}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateTrigger(@PathParam("configuration") String configName, @PathParam("monitorName") String monitorName, @PathParam("trigger") int index, Map<String, Object> json) throws ApiException {
    MonitorManager mm = getMonitorManager(configName);
    Monitor monitor = mm.findMonitor(monitorName);
    if (monitor == null) {
        throw new ApiException("Monitor not found!", Status.NOT_FOUND);
    }
    ITrigger trigger = monitor.getTrigger(index);
    if (trigger == null) {
        throw new ApiException("Trigger not found!", Status.NOT_FOUND);
    }
    handleTrigger(trigger, json);
    return Response.status(Status.OK).build();
}
Also used : MonitorManager(nl.nn.adapterframework.monitoring.MonitorManager) Monitor(nl.nn.adapterframework.monitoring.Monitor) ITrigger(nl.nn.adapterframework.monitoring.ITrigger) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 2 with ITrigger

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

the class ShowMonitors method getTriggers.

@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/{monitorName}/triggers/{triggerId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getTriggers(@PathParam("configuration") String configName, @PathParam("monitorName") String monitorName, @PathParam("triggerId") Integer id) throws ApiException {
    MonitorManager mm = getMonitorManager(configName);
    Monitor monitor = mm.findMonitor(monitorName);
    if (monitor == null) {
        throw new ApiException("Monitor not found!", Status.NOT_FOUND);
    }
    Map<String, Object> returnMap = new HashMap<>();
    if (id != null) {
        ITrigger trigger = monitor.getTrigger(id);
        if (trigger == null) {
            throw new ApiException("Trigger not found!", Status.NOT_FOUND);
        } else {
            returnMap.put("trigger", mapTrigger(trigger));
        }
    }
    returnMap.put("severities", EnumUtils.getEnumList(SeverityEnum.class));
    returnMap.put("events", mm.getEvents());
    EntityTag etag = new EntityTag(returnMap.hashCode() + "");
    Response.ResponseBuilder response = null;
    // Verify if it matched with etag available in http request
    response = request.evaluatePreconditions(etag);
    // If ETag matches the response will be non-null;
    if (response != null) {
        return response.tag(etag).build();
    }
    return Response.status(Status.OK).entity(returnMap).tag(etag).build();
}
Also used : Response(javax.ws.rs.core.Response) MonitorManager(nl.nn.adapterframework.monitoring.MonitorManager) Monitor(nl.nn.adapterframework.monitoring.Monitor) SeverityEnum(nl.nn.adapterframework.monitoring.SeverityEnum) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) EntityTag(javax.ws.rs.core.EntityTag) ITrigger(nl.nn.adapterframework.monitoring.ITrigger) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with ITrigger

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

the class ShowMonitors method mapMonitor.

private Map<String, Object> mapMonitor(Monitor monitor) {
    Map<String, Object> monitorMap = new HashMap<String, Object>();
    monitorMap.put("name", monitor.getName());
    monitorMap.put("type", monitor.getType());
    monitorMap.put("destinations", monitor.getDestinationSet());
    monitorMap.put("lastHit", monitor.getLastHit());
    boolean isRaised = monitor.isRaised();
    monitorMap.put("raised", isRaised);
    monitorMap.put("changed", monitor.getStateChangeDt());
    monitorMap.put("hits", monitor.getAdditionalHitCount());
    if (isRaised) {
        Map<String, Object> alarm = new HashMap<>();
        alarm.put("severity", monitor.getAlarmSeverity());
        EventThrowing source = monitor.getAlarmSource();
        if (source != null) {
            String name = "";
            if (source.getAdapter() != null) {
                name = String.format("%s / %s", source.getAdapter().getName(), source.getEventSourceName());
            } else {
                name = source.getEventSourceName();
            }
            alarm.put("source", name);
        }
        monitorMap.put("alarm", alarm);
    }
    List<Map<String, Object>> triggers = new ArrayList<Map<String, Object>>();
    List<ITrigger> listOfTriggers = monitor.getTriggers();
    for (ITrigger trigger : listOfTriggers) {
        Map<String, Object> map = mapTrigger(trigger);
        map.put("id", listOfTriggers.indexOf(trigger));
        triggers.add(map);
    }
    monitorMap.put("triggers", triggers);
    List<String> destinations = new ArrayList<>();
    Set<String> d = monitor.getDestinationSet();
    for (Iterator<String> it = d.iterator(); it.hasNext(); ) {
        destinations.add(it.next());
    }
    monitorMap.put("destinations", destinations);
    return monitorMap;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ITrigger(nl.nn.adapterframework.monitoring.ITrigger) EventThrowing(nl.nn.adapterframework.monitoring.EventThrowing) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with ITrigger

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

the class ShowMonitors method updateTrigger.

@POST
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/{monitorName}/triggers")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateTrigger(@PathParam("configuration") String configName, @PathParam("monitorName") String monitorName, Map<String, Object> json) {
    MonitorManager mm = getMonitorManager(configName);
    Monitor monitor = mm.findMonitor(monitorName);
    if (monitor == null) {
        throw new ApiException("Monitor not found!", Status.NOT_FOUND);
    }
    ITrigger trigger = SpringUtils.createBean(mm.getApplicationContext(), Trigger.class);
    handleTrigger(trigger, json);
    monitor.registerTrigger(trigger);
    monitor.configure();
    return Response.status(Status.OK).build();
}
Also used : MonitorManager(nl.nn.adapterframework.monitoring.MonitorManager) Monitor(nl.nn.adapterframework.monitoring.Monitor) ITrigger(nl.nn.adapterframework.monitoring.ITrigger) 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 5 with ITrigger

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

the class ShowMonitors method deleteTrigger.

@DELETE
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/{monitorName}/triggers/{trigger}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteTrigger(@PathParam("configuration") String configurationName, @PathParam("monitorName") String monitorName, @PathParam("trigger") int index) throws ApiException {
    MonitorManager mm = getMonitorManager(configurationName);
    Monitor monitor = mm.findMonitor(monitorName);
    if (monitor == null) {
        throw new ApiException("Monitor not found!", Status.NOT_FOUND);
    }
    ITrigger trigger = monitor.getTrigger(index);
    if (trigger == null) {
        throw new ApiException("Trigger not found!", Status.NOT_FOUND);
    }
    log.info("removing trigger [" + trigger + "]");
    monitor.removeTrigger(trigger);
    return Response.status(Status.OK).build();
}
Also used : MonitorManager(nl.nn.adapterframework.monitoring.MonitorManager) Monitor(nl.nn.adapterframework.monitoring.Monitor) ITrigger(nl.nn.adapterframework.monitoring.ITrigger) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces)

Aggregations

ITrigger (nl.nn.adapterframework.monitoring.ITrigger)5 RolesAllowed (javax.annotation.security.RolesAllowed)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 Monitor (nl.nn.adapterframework.monitoring.Monitor)4 MonitorManager (nl.nn.adapterframework.monitoring.MonitorManager)4 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Consumes (javax.ws.rs.Consumes)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 EntityTag (javax.ws.rs.core.EntityTag)1 Response (javax.ws.rs.core.Response)1 EventThrowing (nl.nn.adapterframework.monitoring.EventThrowing)1 SeverityEnum (nl.nn.adapterframework.monitoring.SeverityEnum)1