From 11ce972975d20c5295e7fd83f66290548e1871a8 Mon Sep 17 00:00:00 2001 From: Bastien Fiorentino Date: Thu, 21 Jan 2021 17:36:17 +0100 Subject: [PATCH 1/2] Add table panel for grafana version 7 Because of the complete rewriting of table panel in grafana 7 the solution used in other libsonnet file (to have a pluginVersion attribute to switch between grafana versions) is not viable for this panel. So I've added a brand new libsonnet file that should live along with the old one (table_panel.libsonnet) to allow retro compatibility This file is a copy of https://github.com/BastienF/grafonnet-lib/blob/master/grafonnet-7.0/panel/table.libsonnet --- grafonnet/table_panel_grafana7.libsonnet | 134 +++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 grafonnet/table_panel_grafana7.libsonnet diff --git a/grafonnet/table_panel_grafana7.libsonnet b/grafonnet/table_panel_grafana7.libsonnet new file mode 100644 index 00000000..981d1ea2 --- /dev/null +++ b/grafonnet/table_panel_grafana7.libsonnet @@ -0,0 +1,134 @@ +// This file was generated by https://github.com/grafana/dashboard-spec + +{ + new( + datasource='default', + description=null, + repeat=null, + repeatDirection=null, + title=null, + transparent=false, + ):: { + [if datasource != null then 'datasource']: datasource, + [if description != null then 'description']: description, + [if repeat != null then 'repeat']: repeat, + [if repeatDirection != null then 'repeatDirection']: repeatDirection, + [if title != null then 'title']: title, + [if transparent != null then 'transparent']: transparent, + type: 'table', + + setFieldConfig( + displayName=null, + max=null, + min=null, + thresholdMode='absolute', + noValue=null, + unit='short', + width=null, + ):: self {} + + { fieldConfig+: { defaults+: { [if displayName != null then 'displayName']: displayName } } } + + { fieldConfig+: { defaults+: { [if max != null then 'max']: max } } } + + { fieldConfig+: { defaults+: { [if min != null then 'min']: min } } } + + { fieldConfig+: { defaults+: { thresholds+: { [if thresholdMode != null then 'mode']: thresholdMode } } } } + + { fieldConfig+: { defaults+: { [if noValue != null then 'noValue']: noValue } } } + + { fieldConfig+: { defaults+: { [if unit != null then 'unit']: unit } } } + + { fieldConfig+: { defaults+: { custom+: { [if width != null then 'width']: width } } } } + , + + setGridPos( + h=8, + w=12, + x=null, + y=null, + ):: self {} + + { gridPos+: { [if h != null then 'h']: h } } + + { gridPos+: { [if w != null then 'w']: w } } + + { gridPos+: { [if x != null then 'x']: x } } + + { gridPos+: { [if y != null then 'y']: y } } + , + + setOptions( + showHeader=true, + ):: self {} + + { options+: { [if showHeader != null then 'showHeader']: showHeader } } + , + + + addDataLink( + targetBlank=true, + title=null, + url=null, + ):: self {} + + { fieldConfig+: { defaults+: { links+: [ + { + [if targetBlank != null then 'targetBlank']: targetBlank, + [if title != null then 'title']: title, + [if url != null then 'url']: url, + }, + ] } } }, + + addPanelLink( + targetBlank=true, + title=null, + url=null, + ):: self {} + + { links+: [ + { + [if targetBlank != null then 'targetBlank']: targetBlank, + [if title != null then 'title']: title, + [if url != null then 'url']: url, + }, + ] }, + + addMapping( + from=null, + id=null, + operator=null, + text=null, + to=null, + type=null, + value=null, + ):: self {} + + { fieldConfig+: { defaults+: { mappings+: [ + { + [if from != null then 'from']: from, + [if id != null then 'id']: id, + [if operator != null then 'operator']: operator, + [if text != null then 'text']: text, + [if to != null then 'to']: to, + [if type != null then 'type']: type, + [if value != null then 'value']: value, + }, + ] } } }, + + addOverride( + matcher=null, + properties=null, + ):: self {} + + { fieldConfig+: { overrides+: [ + { + [if matcher != null then 'matcher']: matcher, + [if properties != null then 'properties']: properties, + }, + ] } }, + + addThresholdStep( + color=null, + value=null, + ):: self {} + + { fieldConfig+: { defaults+: { thresholds+: { steps+: [ + { + [if color != null then 'color']: color, + [if value != null then 'value']: value, + }, + ] } } } }, + + addTarget( + target + ):: self {} + + { targets+: [ + target, + ] }, + + }, +} From 1ea02fe9a413d4485375e895ac4f1871bf5db6d2 Mon Sep 17 00:00:00 2001 From: Bastien Fiorentino Date: Tue, 9 Mar 2021 14:21:28 +0100 Subject: [PATCH 2/2] Add timeFrom to table panel + add displayMode to fieldConfig --- grafonnet/table_panel_grafana7.libsonnet | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/grafonnet/table_panel_grafana7.libsonnet b/grafonnet/table_panel_grafana7.libsonnet index 981d1ea2..20aa6926 100644 --- a/grafonnet/table_panel_grafana7.libsonnet +++ b/grafonnet/table_panel_grafana7.libsonnet @@ -8,6 +8,7 @@ repeatDirection=null, title=null, transparent=false, + timeFrom=null, ):: { [if datasource != null then 'datasource']: datasource, [if description != null then 'description']: description, @@ -15,6 +16,7 @@ [if repeatDirection != null then 'repeatDirection']: repeatDirection, [if title != null then 'title']: title, [if transparent != null then 'transparent']: transparent, + [if timeFrom != null then 'timeFrom']: timeFrom, type: 'table', setFieldConfig( @@ -25,6 +27,7 @@ noValue=null, unit='short', width=null, + displayMode=null, ):: self {} + { fieldConfig+: { defaults+: { [if displayName != null then 'displayName']: displayName } } } + { fieldConfig+: { defaults+: { [if max != null then 'max']: max } } } @@ -33,6 +36,7 @@ + { fieldConfig+: { defaults+: { [if noValue != null then 'noValue']: noValue } } } + { fieldConfig+: { defaults+: { [if unit != null then 'unit']: unit } } } + { fieldConfig+: { defaults+: { custom+: { [if width != null then 'width']: width } } } } + + { fieldConfig+: { defaults+: { custom+: { [if displayMode != null then 'displayMode']: displayMode } } } } , setGridPos(