summaryrefslogtreecommitdiff
path: root/grafana_dashboards/schema/panel/singlestat.py
blob: cd0e20230855cf1e10313fcc687605151bd265d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright 2015 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import voluptuous as v

from grafana_dashboards.schema.panel.base import Base


class Singlestat(Base):

    def get_schema(self):
        # TODO(pabelanger): This is pretty ugly, there much be a better way to
        # set default values.
        sparkline_defaults = {
            'fillColor': 'rgba(31, 118, 189, 0.18)',
            'full': False,
            'lineColor': 'rgb(31, 120, 193)',
            'show': False,
        }
        sparkline = {
            v.Required(
                'fillColor', default=sparkline_defaults['fillColor']
            ): v.All(str),
            v.Required('full', default=False): v.All(bool),
            v.Required(
                'lineColor', default=sparkline_defaults['lineColor']
            ): v.All(str),
            v.Required('show', default=False): v.All(bool),
        }

        singlestat = {
            v.Required('colorBackground', default=False): v.All(bool),
            v.Required('colorValue', default=False): v.All(bool),
            v.Required('maxDataPoints', default=100): v.All(int),
            v.Required('postfix', default=''): v.All(str),
            # Support 0% to 200% by 10
            v.Required(
                'postfixFontSize', default='50%'): v.All(
                    v.Match(r'^[1-9]?[0]{1}%$|^1[0-9]?[0]{1}%$|^200%$')),
            v.Required('prefix', default=''): v.All(str),
            # Support 0% to 200% by 10
            v.Required(
                'prefixFontSize', default='50%'): v.All(
                    v.Match(r'^[1-9]?[0]{1}%$|^1[0-9]?[0]{1}%$|^200%$')),
            v.Required('sparkline', default=sparkline_defaults): sparkline,
            v.Required('targets', default=[]): v.All(list),
            v.Required('thresholds', default=''): v.All(str),
            # Support 0% to 200% by 10
            v.Required(
                'valueFontSize', default='80%'): v.All(
                    v.Match(r'^[1-9]?[0]{1}%$|^1[0-9]?[0]{1}%$|^200%$')),
            v.Required('valueName', default='avg'): v.All(
                'avg', 'current', 'max', 'min', 'total'),
            v.Optional('decimals'): v.All(int, v.Range(min=0, max=12)),
        }
        singlestat.update(self.base)
        return v.Schema(singlestat)