Search in sources :

Example 6 with WidgetEntity

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

the class EntityConverter method convert.

public ViewEntity convert(DashboardEntity dashboardEntity, Map<String, ValueReference> parameters) {
    this.parameters = parameters;
    this.dashboardEntity = dashboardEntity;
    final String queryId = UUID.randomUUID().toString();
    final Map<DashboardWidgetEntity, List<WidgetEntity>> widgets = convertWidgets();
    final Map<String, WidgetPositionDTO> widgetPositionMap = DashboardEntity.positionMap(parameters, widgets);
    final Titles titles = DashboardEntity.widgetTitles(widgets, parameters);
    final Map<String, Set<String>> widgetMapping = new HashMap<>();
    final Set<SearchTypeEntity> searchTypes = new HashSet<>();
    createSearchTypes(widgets, widgetMapping, searchTypes);
    SearchEntity searchEntity;
    try {
        searchEntity = createSearchEntity(queryId, searchTypes);
    } catch (InvalidRangeParametersException e) {
        throw new IllegalArgumentException("The provided entity does not have a valid TimeRange", e);
    }
    final ViewStateEntity viewStateEntity = ViewStateEntity.builder().widgets(widgets.values().stream().flatMap(Collection::stream).collect(Collectors.toSet())).titles(titles).widgetMapping(widgetMapping).widgetPositions(widgetPositionMap).build();
    final Map<String, ViewStateEntity> viewStateEntityMap = ImmutableMap.of(queryId, viewStateEntity);
    return ViewEntity.builder().search(searchEntity).state(viewStateEntityMap).title(dashboardEntity.title()).properties(Collections.emptySet()).description(dashboardEntity.description()).requires(Collections.emptyMap()).summary(ValueReference.of("Converted Dashboard")).createdAt(DateTime.now(DateTimeZone.UTC)).type(ViewEntity.Type.DASHBOARD).build();
}
Also used : ViewStateEntity(org.graylog2.contentpacks.model.entities.ViewStateEntity) SearchTypeEntity(org.graylog2.contentpacks.model.entities.SearchTypeEntity) HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) HashMap(java.util.HashMap) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) Titles(org.graylog.plugins.views.search.views.Titles) SearchEntity(org.graylog2.contentpacks.model.entities.SearchEntity) DashboardWidgetEntity(org.graylog2.contentpacks.model.entities.DashboardWidgetEntity) Collection(java.util.Collection) List(java.util.List) WidgetPositionDTO(org.graylog.plugins.views.search.views.WidgetPositionDTO) HashSet(java.util.HashSet)

Example 7 with WidgetEntity

use of org.graylog2.contentpacks.model.entities.WidgetEntity 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 8 with WidgetEntity

use of org.graylog2.contentpacks.model.entities.WidgetEntity 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)7 DashboardWidgetEntity (org.graylog2.contentpacks.model.entities.DashboardWidgetEntity)7 WidgetEntity (org.graylog2.contentpacks.model.entities.WidgetEntity)6 AggregationConfigDTO (org.graylog.plugins.views.search.views.widgets.aggregation.AggregationConfigDTO)5 ArrayList (java.util.ArrayList)2 SortConfigDTO (org.graylog.plugins.views.search.views.widgets.aggregation.sort.SortConfigDTO)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Titles (org.graylog.plugins.views.search.views.Titles)1 WidgetConfigDTO (org.graylog.plugins.views.search.views.WidgetConfigDTO)1 WidgetPositionDTO (org.graylog.plugins.views.search.views.WidgetPositionDTO)1 PivotDTO (org.graylog.plugins.views.search.views.widgets.aggregation.PivotDTO)1 SearchEntity (org.graylog2.contentpacks.model.entities.SearchEntity)1 SearchTypeEntity (org.graylog2.contentpacks.model.entities.SearchTypeEntity)1 ViewStateEntity (org.graylog2.contentpacks.model.entities.ViewStateEntity)1 WidgetConfig (org.graylog2.contentpacks.model.entities.WidgetConfig)1