From e6c7095c6b92abbe33cf2322833a805604519303 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Thu, 21 Feb 2019 10:06:35 +1100 Subject: [PATCH] Add valueMaps and rangeMaps support These allow you to specify custom text instead of displayed values Change-Id: I7e5c6067c0b0d26edc18120283bad30887df0663 --- grafana_dashboards/schema/panel/singlestat.py | 14 +++++++++++ tests/schema/fixtures/dashboard-0017.json | 24 +++++++++++++++++++ tests/schema/fixtures/dashboard-0017.yaml | 12 ++++++++++ 3 files changed, 50 insertions(+) diff --git a/grafana_dashboards/schema/panel/singlestat.py b/grafana_dashboards/schema/panel/singlestat.py index 7c81fb7..ffa37fd 100644 --- a/grafana_dashboards/schema/panel/singlestat.py +++ b/grafana_dashboards/schema/panel/singlestat.py @@ -47,6 +47,18 @@ class Singlestat(Base): v.Required('thresholdMarkers', default=False): v.All(bool), } + valuemap = { + v.Required('op', default='='): v.Any(str), + v.Required('value'): v.Any(int), + v.Required('text'): v.Any(str) + } + + rangemap = { + v.Required('from'): v.Any(int), + v.Required('to'): v.Any(int), + v.Required('text'): v.Any(str), + } + singlestat = { v.Required('colorBackground', default=False): v.All(bool), v.Required('colorValue', default=False): v.All(bool), @@ -76,6 +88,8 @@ class Singlestat(Base): v.Optional('hideTimeOverride'): v.All(bool), v.Optional('timeFrom'): v.All(v.Match(r'[1-9]+[0-9]*[smhdw]')), v.Optional('timeShift'): v.All(v.Match(r'[1-9]+[0-9]*[smhdw]')), + v.Optional('valueMaps'): v.All([valuemap]), + v.Optional('rangeMaps'): v.All([rangemap]), } singlestat.update(self.base) return v.Schema(singlestat) diff --git a/tests/schema/fixtures/dashboard-0017.json b/tests/schema/fixtures/dashboard-0017.json index 1bace55..8742c8e 100644 --- a/tests/schema/fixtures/dashboard-0017.json +++ b/tests/schema/fixtures/dashboard-0017.json @@ -25,6 +25,18 @@ "postfixFontSize": "50%", "prefix": "", "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": 2, + "text": "TWOTHREE", + "to": 3 + }, + { + "from": 4, + "text": "FOURFIVE", + "to": 5 + } + ], "span": 12, "sparkline": { "fillColor": "rgba(31, 118, 189, 0.18)", @@ -39,6 +51,18 @@ "title": "no title (click here)", "type": "singlestat", "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "OK", + "value": 0 + }, + { + "op": "=", + "text": "NOT OK", + "value": 1 + } + ], "valueName": "avg" } ], diff --git a/tests/schema/fixtures/dashboard-0017.yaml b/tests/schema/fixtures/dashboard-0017.yaml index 04fb383..04bfbec 100644 --- a/tests/schema/fixtures/dashboard-0017.yaml +++ b/tests/schema/fixtures/dashboard-0017.yaml @@ -15,3 +15,15 @@ dashboard: show: true thresholdLabels: false thresholdMarkers: true + valueMaps: + - value: 0 + text: 'OK' + - value: 1 + text: 'NOT OK' + rangeMaps: + - from: 2 + to: 3 + text: 'TWOTHREE' + - from: 4 + to: 5 + text: 'FOURFIVE'