Search in sources :

Example 1 with Dashboard

use of org.graylog2.dashboards.Dashboard in project graylog2-server by Graylog2.

the class DashboardWidgetsResource method updateDescription.

@Deprecated
@PUT
@Timed
@ApiOperation(value = "Update description of a widget")
@Path("/{widgetId}/description")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Dashboard not found."), @ApiResponse(code = 404, message = "Widget not found.") })
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.DASHBOARD_WIDGET_UPDATE)
public void updateDescription(@ApiParam(name = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId, @ApiParam(name = "widgetId", required = true) @PathParam("widgetId") String widgetId, @ApiParam(name = "JSON body", required = true) @Valid UpdateWidgetRequest uwr) throws ValidationException, NotFoundException {
    checkPermission(RestPermissions.DASHBOARDS_EDIT, dashboardId);
    final Dashboard dashboard = dashboardService.load(dashboardId);
    final DashboardWidget widget = dashboard.getWidget(widgetId);
    if (widget == null) {
        final String msg = "Widget " + widgetId + " on dashboard " + dashboardId + " not found.";
        LOG.error(msg);
        throw new javax.ws.rs.NotFoundException(msg);
    }
    dashboardService.updateWidgetDescription(dashboard, widget, uwr.description());
    LOG.info("Updated description of widget <" + widgetId + "> on dashboard <" + dashboardId + ">. Reason: REST request.");
}
Also used : DashboardWidget(org.graylog2.dashboards.widgets.DashboardWidget) Dashboard(org.graylog2.dashboards.Dashboard) NotFoundException(org.graylog2.database.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with Dashboard

use of org.graylog2.dashboards.Dashboard in project graylog2-server by Graylog2.

the class DashboardWidgetsResource method getWidget.

@GET
@Timed
@ApiOperation(value = "Get a widget")
@Path("/{widgetId}")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Dashboard not found."), @ApiResponse(code = 404, message = "Widget not found.") })
@Produces(MediaType.APPLICATION_JSON)
public WidgetSummary getWidget(@ApiParam(name = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId, @ApiParam(name = "widgetId", required = true) @PathParam("widgetId") String widgetId) throws NotFoundException {
    checkPermission(RestPermissions.DASHBOARDS_READ, dashboardId);
    final Dashboard dashboard = dashboardService.load(dashboardId);
    final DashboardWidget widget = dashboard.getWidget(widgetId);
    return WidgetSummary.create(widget.getId(), widget.getDescription(), widget.getType(), widget.getCacheTime(), widget.getCreatorUserId(), widget.getConfig());
}
Also used : DashboardWidget(org.graylog2.dashboards.widgets.DashboardWidget) Dashboard(org.graylog2.dashboards.Dashboard) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with Dashboard

use of org.graylog2.dashboards.Dashboard in project graylog2-server by Graylog2.

the class DashboardsResource method update.

@PUT
@Timed
@ApiOperation(value = "Update the settings of a dashboard.")
@Produces(MediaType.APPLICATION_JSON)
@Path("/{dashboardId}")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Dashboard not found.") })
@AuditEvent(type = AuditEventTypes.DASHBOARD_UPDATE)
public void update(@ApiParam(name = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId, @ApiParam(name = "JSON body", required = true) UpdateDashboardRequest cr) throws ValidationException, NotFoundException {
    checkPermission(RestPermissions.DASHBOARDS_EDIT, dashboardId);
    final Dashboard dashboard = dashboardService.load(dashboardId);
    if (cr.title() != null) {
        dashboard.setTitle(cr.title());
    }
    if (cr.description() != null) {
        dashboard.setDescription(cr.description());
    }
    // Validations are happening here.
    dashboardService.save(dashboard);
}
Also used : Dashboard(org.graylog2.dashboards.Dashboard) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with Dashboard

use of org.graylog2.dashboards.Dashboard in project graylog2-server by Graylog2.

the class DashboardsResource method create.

@POST
@Timed
@ApiOperation(value = "Create a dashboard")
@RequiresPermissions(RestPermissions.DASHBOARDS_CREATE)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.DASHBOARD_CREATE)
public Response create(@ApiParam(name = "JSON body", required = true) CreateDashboardRequest cr) throws ValidationException {
    // Create dashboard.
    final Dashboard dashboard = dashboardService.create(cr.title(), cr.description(), getCurrentUser().getName(), Tools.nowUTC());
    final String id = dashboardService.save(dashboard);
    final Map<String, String> result = ImmutableMap.of("dashboard_id", id);
    final URI dashboardUri = getUriBuilderToSelf().path(DashboardsResource.class, "get").build(id);
    return Response.created(dashboardUri).entity(result).build();
}
Also used : Dashboard(org.graylog2.dashboards.Dashboard) URI(java.net.URI) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 5 with Dashboard

use of org.graylog2.dashboards.Dashboard in project graylog2-server by Graylog2.

the class BundleExporter method exportDashboardWidgets.

private List<DashboardWidget> exportDashboardWidgets(final org.graylog2.dashboards.Dashboard dashboard) {
    final ImmutableList.Builder<DashboardWidget> dashboardWidgetBuilder = ImmutableList.builder();
    // Add all widgets of this dashboard.
    final Map<String, Object> fields = dashboard.getFields();
    @SuppressWarnings("unchecked") final Map<String, Object> positions = (Map<String, Object>) dashboard.asMap().get("positions");
    if (fields.containsKey(DashboardImpl.EMBEDDED_WIDGETS)) {
        @SuppressWarnings("unchecked") final List<BasicDBObject> embeddedWidgets = (List<BasicDBObject>) fields.get(DashboardImpl.EMBEDDED_WIDGETS);
        for (BasicDBObject widgetFields : embeddedWidgets) {
            org.graylog2.dashboards.widgets.DashboardWidget widget;
            try {
                widget = dashboardWidgetCreator.fromPersisted(widgetFields);
            } catch (Exception e) {
                LOG.warn("Error while exporting widgets of dashboard " + dashboard.getId(), e);
                continue;
            }
            final DashboardWidget dashboardWidgetDescription = new DashboardWidget();
            final Map<String, Object> widgetConfig = widget.getConfig();
            dashboardWidgetDescription.setDescription(widget.getDescription());
            dashboardWidgetDescription.setType(widget.getType());
            dashboardWidgetDescription.setConfiguration(widgetConfig);
            dashboardWidgetDescription.setCacheTime(widget.getCacheTime());
            // Mark referenced streams for export
            final Object streamId = widgetConfig.get("stream_id");
            if (streamId instanceof String && streamSet.add((String) streamId)) {
                LOG.debug("Adding stream {} to export list", streamId);
            }
            @SuppressWarnings("unchecked") final Map<String, Integer> widgetPosition = (Map<String, Integer>) positions.get(widget.getId());
            if (widgetPosition != null) {
                final int row = widgetPosition.getOrDefault("row", 0);
                final int col = widgetPosition.getOrDefault("col", 0);
                final int height = widgetPosition.getOrDefault("height", 0);
                final int width = widgetPosition.getOrDefault("width", 0);
                dashboardWidgetDescription.setRow(row);
                dashboardWidgetDescription.setCol(col);
                dashboardWidgetDescription.setHeight(height);
                dashboardWidgetDescription.setWidth(width);
            } else {
                LOG.debug("Couldn't find position for widget {} on dashboard {}, using defaults (0, 0, 0, 0).", widget.getId(), dashboard.getTitle());
                dashboardWidgetDescription.setRow(0);
                dashboardWidgetDescription.setCol(0);
                dashboardWidgetDescription.setHeight(0);
                dashboardWidgetDescription.setWidth(0);
            }
            dashboardWidgetBuilder.add(dashboardWidgetDescription);
        }
    }
    return dashboardWidgetBuilder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) NotFoundException(org.graylog2.database.NotFoundException) BasicDBObject(com.mongodb.BasicDBObject) BasicDBObject(com.mongodb.BasicDBObject) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)11 ApiOperation (io.swagger.annotations.ApiOperation)11 Produces (javax.ws.rs.Produces)11 Dashboard (org.graylog2.dashboards.Dashboard)11 ApiResponses (io.swagger.annotations.ApiResponses)10 Path (javax.ws.rs.Path)9 AuditEvent (org.graylog2.audit.jersey.AuditEvent)9 DashboardWidget (org.graylog2.dashboards.widgets.DashboardWidget)8 NotFoundException (org.graylog2.database.NotFoundException)6 PUT (javax.ws.rs.PUT)5 BasicDBObject (com.mongodb.BasicDBObject)3 InvalidWidgetConfigurationException (org.graylog2.dashboards.widgets.InvalidWidgetConfigurationException)3 InvalidRangeParametersException (org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException)3 URI (java.net.URI)2 List (java.util.List)2 BadRequestException (javax.ws.rs.BadRequestException)2 Consumes (javax.ws.rs.Consumes)2 DELETE (javax.ws.rs.DELETE)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2