use of org.graylog2.contentpacks.model.entities.WidgetEntity in project graylog2-server by Graylog2.
the class DashboardWidgetConverter method createHistogramWidget.
private List<WidgetEntity> createHistogramWidget() {
final WidgetConfigDTO widgetConfigDTO = defaultWidgetConfig();
final WidgetEntity.Builder widgetEntityBuilder = aggregationWidgetBuilder().config(widgetConfigDTO);
final Optional<String> query = config.getOptionalString("query");
query.ifPresent(s -> widgetEntityBuilder.query(ElasticsearchQueryString.of(s)));
return ImmutableList.of(widgetEntityBuilder.build());
}
use of org.graylog2.contentpacks.model.entities.WidgetEntity 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());
}
use of org.graylog2.contentpacks.model.entities.WidgetEntity in project graylog2-server by Graylog2.
the class DashboardWidgetConverter method createQuickValueWidgets.
private List<WidgetEntity> createQuickValueWidgets() {
final List<WidgetEntity> result = new ArrayList<>(2);
final WidgetEntity.Builder widgetEntityBuilder = aggregationWidgetBuilder();
final boolean showChart = config.getOptionalBoolean("show_pie_chart").orElse(false);
final boolean showTable = config.getOptionalBoolean("show_data_table").orElse(!showChart);
final String field = config.getString("field");
final String stackedFields = config.getOptionalString("stacked_fields").orElse("");
final Integer limit = config.getOptionalInteger("limit").orElse(5);
final Integer dataTableLimit = config.getOptionalInteger("data_table_limit").orElse(15);
final String sortOrder = config.getOptionalString("sort_order").orElse("desc");
SortConfigDTO.Direction dir = sortOrder.matches("desc") ? SortConfigDTO.Direction.Descending : SortConfigDTO.Direction.Ascending;
AggregationConfigDTO.Builder aggregationConfigBuilder = AggregationConfigDTO.Builder.builder().columnPivots(Collections.emptyList()).series(ImmutableList.of(SeriesDTO.Builder.create().config(SeriesConfigDTO.empty()).function("count()").build())).sort(ImmutableList.of(PivotSortConfig.create(field, dir)));
final Optional<String> query = config.getOptionalString("query");
query.ifPresent(s -> widgetEntityBuilder.query(ElasticsearchQueryString.of(s)));
if (showChart) {
result.add(widgetEntityBuilder.config(aggregationConfigBuilder.rowPivots(genPivotForPie(field, stackedFields, limit)).visualization("pie").build()).build());
}
if (showTable) {
result.add(widgetEntityBuilder.config(aggregationConfigBuilder.visualization("table").rowPivots(genPivotForPie(field, stackedFields, dataTableLimit)).build()).id(UUID.randomUUID().toString()).build());
}
return result;
}
use of org.graylog2.contentpacks.model.entities.WidgetEntity in project graylog2-server by Graylog2.
the class DashboardWidgetConverter method createQuickValueHistogramWidgets.
private List<WidgetEntity> createQuickValueHistogramWidgets() {
final List<WidgetEntity> result = new ArrayList<>(2);
final WidgetEntity.Builder widgetEntityBuilder = aggregationWidgetBuilder();
final String stackedFields = config.getOptionalString("stacked_fields").orElse("");
final String field = config.getString("field");
final int limit = config.getOptionalInteger("limit").orElse(5);
final String sortOrder = config.getOptionalString("sort_order").orElse("desc");
SortConfigDTO.Direction dir = sortOrder.matches("desc") ? SortConfigDTO.Direction.Descending : SortConfigDTO.Direction.Ascending;
AggregationConfigDTO.Builder aggregationConfigBuilder = AggregationConfigDTO.Builder.builder().columnPivots(Collections.emptyList()).series(ImmutableList.of(SeriesDTO.Builder.create().config(SeriesConfigDTO.empty()).function("count()").build())).sort(ImmutableList.of(PivotSortConfig.create(field, dir)));
final Optional<String> query = config.getOptionalString("query");
query.ifPresent(s -> widgetEntityBuilder.query(ElasticsearchQueryString.of(s)));
result.add(widgetEntityBuilder.config(aggregationConfigBuilder.visualization("bar").visualizationConfig(BarVisualizationConfigDTO.Builder.builder().barmode(BarVisualizationConfigDTO.BarMode.stack).build()).rollup(false).rowPivots(Collections.singletonList(PivotDTO.Builder.builder().field("timestamp").type("time").config(TimeHistogramConfigDTO.Builder.builder().interval(AutoIntervalDTO.Builder.builder().build()).build()).build())).columnPivots(genPivotForPie(field, stackedFields, limit)).build()).id(UUID.randomUUID().toString()).build());
return result;
}
use of org.graylog2.contentpacks.model.entities.WidgetEntity 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);
}
}
}
Aggregations