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