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();
}
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();
}
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;
}
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();
}
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();
}
Aggregations