diff --git a/grafana_dashboards/schema/panel/graph.py b/grafana_dashboards/schema/panel/graph.py index f3297b8..ada6f78 100644 --- a/grafana_dashboards/schema/panel/graph.py +++ b/grafana_dashboards/schema/panel/graph.py @@ -115,6 +115,7 @@ class Graph(Base): graph = { v.Required('bars', default=False): v.All(bool), + v.Optional('datasource'): v.All(str), v.Required('fill', default=1): v.All(int), v.Optional('hideTimeOverride'): v.All(bool), v.Optional('leftYAxisLabel'): v.All(str, v.Length(min=1)), diff --git a/grafana_dashboards/schema/panel/singlestat.py b/grafana_dashboards/schema/panel/singlestat.py index 9b7d6a5..f8b48e4 100644 --- a/grafana_dashboards/schema/panel/singlestat.py +++ b/grafana_dashboards/schema/panel/singlestat.py @@ -62,6 +62,7 @@ class Singlestat(Base): v.Match(r'^[1-9]?[0]{1}%$|^1[0-9]?[0]{1}%$|^200%$')), v.Required('valueName', default='avg'): v.Any( 'avg', 'current', 'max', 'min', 'total'), + v.Optional('datasource'): v.All(str), v.Optional('decimals'): v.All(int, v.Range(min=0, max=12)), v.Optional('hideTimeOverride'): v.All(bool), v.Optional('timeFrom'): v.All(v.Match(r'[1-9]+[0-9]*[smhdw]')), diff --git a/grafana_dashboards/schema/template/query.py b/grafana_dashboards/schema/template/query.py index b0573a0..c55cbc8 100644 --- a/grafana_dashboards/schema/template/query.py +++ b/grafana_dashboards/schema/template/query.py @@ -25,6 +25,7 @@ class Query(Base): v.Required('multi', default=False): v.All(bool), v.Required('query', default=''): v.All(str), v.Required('refresh', default=False): v.All(bool), + v.Optional('datasource'): v.All(str), } query.update(self.base) return v.Schema(query) diff --git a/tests/schema/fixtures/dashboard-0019.json b/tests/schema/fixtures/dashboard-0019.json new file mode 100644 index 0000000..da730fe --- /dev/null +++ b/tests/schema/fixtures/dashboard-0019.json @@ -0,0 +1,43 @@ +{ + "dashboard": { + "new-dashboard": { + "rows": [ + { + "collapse": false, + "editable": true, + "height": "250px", + "panels": [ + { + "bars": false, + "datasource": "graphite", + "editable": true, + "error": false, + "fill": 1, + "lines": true, + "linewidth": 2, + "percentage": false, + "pointradius": 5, + "points": false, + "span": 12, + "stack": false, + "steppedLine": false, + "targets": [], + "title": "no title (click here)", + "type": "graph", + "x-axis": true, + "y-axis": true + } + ], + "showTitle": false, + "title": "New row" + } + ], + "templating": { + "enabled": false, + "list": [] + }, + "timezone": "utc", + "title": "New dashboard" + } + } +} diff --git a/tests/schema/fixtures/dashboard-0019.yaml b/tests/schema/fixtures/dashboard-0019.yaml new file mode 100644 index 0000000..5aa35cd --- /dev/null +++ b/tests/schema/fixtures/dashboard-0019.yaml @@ -0,0 +1,9 @@ +dashboard: + title: New dashboard + rows: + - title: New row + height: 250px + panels: + - title: no title (click here) + type: graph + datasource: graphite diff --git a/tests/schema/fixtures/dashboard-0020.json b/tests/schema/fixtures/dashboard-0020.json new file mode 100644 index 0000000..274f044 --- /dev/null +++ b/tests/schema/fixtures/dashboard-0020.json @@ -0,0 +1,48 @@ +{ + "dashboard": { + "new-dashboard": { + "rows": [ + { + "collapse": false, + "editable": true, + "height": "250px", + "panels": [ + { + "colorBackground": false, + "colorValue": false, + "datasource": "graphite", + "editable": true, + "error": false, + "maxDataPoints": 100, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "span": 12, + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false + }, + "targets": [], + "thresholds": "", + "title": "no title (click here)", + "type": "singlestat", + "valueFontSize": "80%", + "valueName": "avg" + } + ], + "showTitle": false, + "title": "New row" + } + ], + "templating": { + "enabled": false, + "list": [] + }, + "timezone": "utc", + "title": "New dashboard" + } + } +} diff --git a/tests/schema/fixtures/dashboard-0020.yaml b/tests/schema/fixtures/dashboard-0020.yaml new file mode 100644 index 0000000..c0e635f --- /dev/null +++ b/tests/schema/fixtures/dashboard-0020.yaml @@ -0,0 +1,9 @@ +dashboard: + title: New dashboard + rows: + - title: New row + height: 250px + panels: + - title: no title (click here) + type: singlestat + datasource: graphite diff --git a/tests/schema/fixtures/dashboard-0021.json b/tests/schema/fixtures/dashboard-0021.json new file mode 100644 index 0000000..95c375b --- /dev/null +++ b/tests/schema/fixtures/dashboard-0021.json @@ -0,0 +1,57 @@ +{ + "dashboard": { + "new-dashboard": { + "rows": [ + { + "collapse": false, + "editable": true, + "height": "250px", + "panels": [ + { + "bars": false, + "datasource": "graphite", + "editable": true, + "error": false, + "fill": 1, + "lines": true, + "linewidth": 2, + "percentage": false, + "pointradius": 5, + "points": false, + "span": 12, + "stack": false, + "steppedLine": false, + "targets": [ + { + "target": "$hostname.Cpu.cpu_prct_used" + } + ], + "title": "no title (click here)", + "type": "graph", + "x-axis": true, + "y-axis": true + } + ], + "showTitle": false, + "title": "New row" + } + ], + "templating": { + "enabled": true, + "list": [ + { + "datasource": "graphite", + "includeAll": false, + "multi": false, + "name": "hostname", + "query": "node*", + "refresh": true, + "type": "query" + } + ] + }, + "timezone": "utc", + "title": "New dashboard" + } + } +} diff --git a/tests/schema/fixtures/dashboard-0021.yaml b/tests/schema/fixtures/dashboard-0021.yaml new file mode 100644 index 0000000..8f75a46 --- /dev/null +++ b/tests/schema/fixtures/dashboard-0021.yaml @@ -0,0 +1,17 @@ +dashboard: + templating: + - name: hostname + type: query + datasource: graphite + query: node* + refresh: true + title: New dashboard + rows: + - title: New row + height: 250px + panels: + - title: no title (click here) + type: graph + datasource: graphite + targets: + - target: $hostname.Cpu.cpu_prct_used