use of org.opennms.netmgt.config.kscReports.Graph in project opennms by OpenNMS.
the class KscReportsMigrator method execute.
/* (non-Javadoc)
* @see org.opennms.upgrade.api.OnmsUpgrade#execute()
*/
@Override
public void execute() throws OnmsUpgradeException {
log("Fixing KSC Reports.\n");
boolean changed = false;
List<SnmpInterface> interfacesToMerge = getInterfacesToMerge();
for (Integer reportId : KSC_PerformanceReportFactory.getInstance().getReportList().keySet()) {
Report report = KSC_PerformanceReportFactory.getInstance().getReportByIndex(reportId);
log(" Checking report %s\n", report.getTitle());
for (Graph graph : report.getGraphs()) {
for (SnmpInterface intf : interfacesToMerge) {
final String resourceId = graph.getResourceId().orElse(null);
if (intf.shouldUpdate(resourceId)) {
changed = true;
log(" replacing resource ID %s with %s for %s\n", graph.getResourceId(), intf.getNewResourceId(), graph.getTitle());
graph.setResourceId(intf.getNewResourceId().toString());
}
}
}
}
if (changed) {
log("Updating the KSC reports configuration file.\n");
try {
KSC_PerformanceReportFactory.getInstance().saveCurrent();
} catch (Exception e) {
log("Warning: can't save KSC Reports because %s\n", e.getMessage());
}
if (isOpennmsRunning()) {
log("In case the OpenNMS WebUI can't see the changes, go to Reports -> KSC Performance, Nodes, Domains and click on 'Request a Reload of KSC Reports Configuration'\n");
}
} else {
log("No incomplete interface names detected.\n");
}
}
use of org.opennms.netmgt.config.kscReports.Graph in project opennms by OpenNMS.
the class CustomReportController method handleRequestInternal.
/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
// Get Form Variables
Report report = KscReportEditor.getFromSession(request.getSession(), true).getWorkingReport();
if (report == null) {
throw new IllegalStateException("There is no working report");
}
// int report_index = getReportFactory().getWorkingReportIndex();
// String number_graphs[] = {"1", "2", "3", "4", "5", "6"};
ArrayList<KscResultSet> resultSets = new ArrayList<KscResultSet>(report.getGraphs().size());
for (int i = 0; i < report.getGraphs().size(); i++) {
final int index = i;
Graph current_graph = report.getGraphs().get(index);
PrefabGraph display_graph = getResourceService().getPrefabGraph(current_graph.getGraphtype());
OnmsResource resource = getKscReportService().getResourceFromGraph(current_graph);
Calendar begin_time = Calendar.getInstance();
Calendar end_time = Calendar.getInstance();
KSC_PerformanceReportFactory.getBeginEndTime(current_graph.getTimespan(), begin_time, end_time);
KscResultSet resultSet = new KscResultSet(current_graph.getTitle(), begin_time.getTime(), end_time.getTime(), resource, display_graph);
resultSets.add(resultSet);
}
ModelAndView modelAndView = new ModelAndView("KSC/customReport");
modelAndView.addObject("showTimeSpan", report.getShowTimespanButton());
modelAndView.addObject("showGraphType", report.getShowGraphtypeButton());
modelAndView.addObject("graphsPerLine", report.getGraphsPerLine());
modelAndView.addObject("title", report.getTitle());
modelAndView.addObject("resultSets", resultSets);
return modelAndView;
}
use of org.opennms.netmgt.config.kscReports.Graph in project opennms by OpenNMS.
the class KscReportEditor method getNewGraph.
/**
* Create a new blank graph & initialize it
*
* @return a {@link org.opennms.netmgt.config.kscReports.Graph} object.
*/
private static Graph getNewGraph() {
Graph new_graph = new Graph();
new_graph.setTitle("");
//new_graph.setGraphtype("mib2.bits");
new_graph.setTimespan("7_day");
return new_graph;
}
use of org.opennms.netmgt.config.kscReports.Graph in project opennms by OpenNMS.
the class KscRestService method addKscReport.
@POST
@Consumes(MediaType.APPLICATION_XML)
public Response addKscReport(@Context final UriInfo uriInfo, final KscReport kscReport) {
writeLock();
try {
LOG.debug("addKscReport: Adding KSC Report {}", kscReport);
Report report = m_kscReportFactory.getReportByIndex(kscReport.getId());
if (report != null) {
throw getException(Status.CONFLICT, "Invalid request: Existing KSC report found with ID: {}.", Integer.toString(kscReport.getId()));
}
report = new Report();
report.setId(kscReport.getId());
report.setTitle(kscReport.getLabel());
if (kscReport.getShowGraphtypeButton() != null) {
report.setShowGraphtypeButton(kscReport.getShowGraphtypeButton());
}
if (kscReport.getShowTimespanButton() != null) {
report.setShowTimespanButton(kscReport.getShowTimespanButton());
}
if (kscReport.getGraphsPerLine() != null) {
report.setGraphsPerLine(kscReport.getGraphsPerLine());
}
if (kscReport.hasGraphs()) {
for (KscGraph kscGraph : kscReport.getGraphs()) {
final Graph graph = kscGraph.buildGraph();
report.addGraph(graph);
}
}
m_kscReportFactory.addReport(report);
try {
m_kscReportFactory.saveCurrent();
} catch (final Exception e) {
throw getException(Status.BAD_REQUEST, e.getMessage());
}
return Response.created(getRedirectUri(uriInfo, kscReport.getId())).build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.config.kscReports.Graph in project opennms by OpenNMS.
the class KscRestService method addGraph.
@PUT
@Path("{kscReportId}")
@Transactional
public Response addGraph(@PathParam("kscReportId") final Integer kscReportId, @QueryParam("title") final String title, @QueryParam("reportName") final String reportName, @QueryParam("resourceId") final String resourceId, @QueryParam("timespan") String timespan) {
writeLock();
try {
if (kscReportId == null || reportName == null || reportName == "" || resourceId == null || resourceId == "") {
throw getException(Status.BAD_REQUEST, "Invalid request: reportName and resourceId cannot be empty!");
}
final Report report = m_kscReportFactory.getReportByIndex(kscReportId);
if (report == null) {
throw getException(Status.NOT_FOUND, "Invalid request: No KSC report found with ID: {}.", Integer.toString(kscReportId));
}
final Graph graph = new Graph();
if (title != null) {
graph.setTitle(title);
}
boolean found = false;
for (final String valid : KSC_PerformanceReportFactory.TIMESPAN_OPTIONS) {
if (valid.equals(timespan)) {
found = true;
break;
}
}
if (!found) {
LOG.debug("invalid timespan ('{}'), setting to '7_day' instead.", timespan);
timespan = "7_day";
}
graph.setGraphtype(reportName);
graph.setResourceId(resourceId);
graph.setTimespan(timespan);
report.addGraph(graph);
m_kscReportFactory.setReport(kscReportId, report);
try {
m_kscReportFactory.saveCurrent();
} catch (final Exception e) {
throw getException(Status.INTERNAL_SERVER_ERROR, "Cannot save report with Id {} : {} ", kscReportId.toString(), e.getMessage());
}
return Response.noContent().build();
} finally {
writeUnlock();
}
}
Aggregations