Search in sources :

Example 1 with WidgetConfig

use of org.graylog2.contentpacks.model.entities.WidgetConfig 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)

Example 2 with WidgetConfig

use of org.graylog2.contentpacks.model.entities.WidgetConfig in project graylog2-server by Graylog2.

the class DashboardWidgetConverter method createMapWidget.

private List<WidgetEntity> createMapWidget() {
    final String field = config.getString("field");
    final PivotDTO fieldPivot = PivotDTO.Builder.builder().type("values").config(ValueConfigDTO.Builder.builder().build()).field(field).build();
    final AggregationConfigDTO widgetConfig = AggregationConfigDTO.Builder.builder().series(ImmutableList.of(createSeriesDTO("count", ""))).visualization("map").rowPivots(ImmutableList.of(fieldPivot)).columnPivots(Collections.emptyList()).sort(Collections.emptyList()).build();
    final WidgetEntity.Builder widgetEntityBuilder = aggregationWidgetBuilder().config(widgetConfig);
    final Optional<String> query = config.getOptionalString("query");
    query.ifPresent(s -> widgetEntityBuilder.query(ElasticsearchQueryString.of(s)));
    return ImmutableList.of(widgetEntityBuilder.build());
}
Also used : AggregationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.AggregationConfigDTO) WidgetEntity(org.graylog2.contentpacks.model.entities.WidgetEntity) DashboardWidgetEntity(org.graylog2.contentpacks.model.entities.DashboardWidgetEntity) PivotDTO(org.graylog.plugins.views.search.views.widgets.aggregation.PivotDTO) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)

Example 3 with WidgetConfig

use of org.graylog2.contentpacks.model.entities.WidgetConfig in project graylog2-server by Graylog2.

the class DashboardWidgetConverter method convert.

public List<WidgetEntity> convert(DashboardWidgetEntity dashboardWidgetEntity, Map<String, ValueReference> parameters) {
    this.dashboardWidgetEntity = dashboardWidgetEntity;
    this.config = new WidgetConfig(dashboardWidgetEntity.configuration(), parameters);
    this.parameters = parameters;
    final String type = dashboardWidgetEntity.type().asString(parameters);
    switch(type.toUpperCase(Locale.ENGLISH)) {
        case "SEARCH_RESULT_CHART":
            return createHistogramWidget();
        case "FIELD_CHART":
            return createFieldChartWidget();
        case "STACKED_CHART":
            return createStackedChartWidget();
        case "STATS_COUNT":
            return createStatsCountWidget();
        case "QUICKVALUES":
            return createQuickValueWidgets();
        case "STREAM_SEARCH_RESULT_COUNT":
        case "SEARCH_RESULT_COUNT":
            return createSearchResultCount();
        case "QUICKVALUES_HISTOGRAM":
            return createQuickValueHistogramWidgets();
        case "ORG.GRAYLOG.PLUGINS.MAP.WIDGET.STRATEGY.MAPWIDGETSTRATEGY":
            return createMapWidget();
        default:
            {
                throw new RuntimeException("The provided entity does not have a valid Widget type: " + type);
            }
    }
}
Also used : WidgetConfig(org.graylog2.contentpacks.model.entities.WidgetConfig) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)

Example 4 with WidgetConfig

use of org.graylog2.contentpacks.model.entities.WidgetConfig in project graylog2-server by Graylog2.

the class DashboardWidgetConverter method createStatsCountWidget.

private List<WidgetEntity> createStatsCountWidget() {
    final String function = config.getString("stats_function");
    final String field = config.getString("field");
    final boolean trend = config.getBoolean("trend");
    final boolean lowerIsBetter = config.getBoolean("lower_is_better");
    final AggregationConfigDTO widgetConfig = AggregationConfigDTO.Builder.builder().series(ImmutableList.of(createSeriesDTO(function, field))).visualization("numeric").visualizationConfig(NumberVisualizationConfigDTO.Builder.builder().trend(trend).trendPreference(lowerIsBetter ? NumberVisualizationConfigDTO.TrendPreference.LOWER : NumberVisualizationConfigDTO.TrendPreference.HIGHER).build()).rowPivots(Collections.emptyList()).columnPivots(Collections.emptyList()).sort(Collections.emptyList()).build();
    final WidgetEntity.Builder widgetEntityBuilder = aggregationWidgetBuilder().config(widgetConfig);
    final Optional<String> query = config.getOptionalString("query");
    query.ifPresent(s -> widgetEntityBuilder.query(ElasticsearchQueryString.of(s)));
    return ImmutableList.of(widgetEntityBuilder.build());
}
Also used : AggregationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.AggregationConfigDTO) WidgetEntity(org.graylog2.contentpacks.model.entities.WidgetEntity) DashboardWidgetEntity(org.graylog2.contentpacks.model.entities.DashboardWidgetEntity) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)

Example 5 with WidgetConfig

use of org.graylog2.contentpacks.model.entities.WidgetConfig in project graylog2-server by Graylog2.

the class DashboardWidgetConverter method createSearchResultCount.

private List<WidgetEntity> createSearchResultCount() {
    final boolean trend = config.getBoolean("trend");
    final boolean lowerIsBetter = config.getBoolean("lower_is_better");
    final AggregationConfigDTO widgetConfig = AggregationConfigDTO.Builder.builder().series(ImmutableList.of(createSeriesDTO("count", ""))).visualization("numeric").visualizationConfig(NumberVisualizationConfigDTO.Builder.builder().trend(trend).trendPreference(lowerIsBetter ? NumberVisualizationConfigDTO.TrendPreference.LOWER : NumberVisualizationConfigDTO.TrendPreference.HIGHER).build()).rowPivots(Collections.emptyList()).columnPivots(Collections.emptyList()).sort(Collections.emptyList()).build();
    final WidgetEntity.Builder widgetEntityBuilder = aggregationWidgetBuilder().config(widgetConfig);
    return ImmutableList.of(widgetEntityBuilder.build());
}
Also used : AggregationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.AggregationConfigDTO) WidgetEntity(org.graylog2.contentpacks.model.entities.WidgetEntity) DashboardWidgetEntity(org.graylog2.contentpacks.model.entities.DashboardWidgetEntity)

Aggregations

ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)3 AggregationConfigDTO (org.graylog.plugins.views.search.views.widgets.aggregation.AggregationConfigDTO)3 DashboardWidgetEntity (org.graylog2.contentpacks.model.entities.DashboardWidgetEntity)3 WidgetEntity (org.graylog2.contentpacks.model.entities.WidgetEntity)3 ImmutableList (com.google.common.collect.ImmutableList)1 BasicDBObject (com.mongodb.BasicDBObject)1 List (java.util.List)1 Map (java.util.Map)1 PivotDTO (org.graylog.plugins.views.search.views.widgets.aggregation.PivotDTO)1 WidgetConfig (org.graylog2.contentpacks.model.entities.WidgetConfig)1 NotFoundException (org.graylog2.database.NotFoundException)1