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