diff --git a/grafana_dashboards/schema/template/__init__.py b/grafana_dashboards/schema/template/__init__.py index 08b35e3..f2cc51a 100644 --- a/grafana_dashboards/schema/template/__init__.py +++ b/grafana_dashboards/schema/template/__init__.py @@ -20,6 +20,7 @@ from grafana_dashboards.schema.template.datasource import Datasource from grafana_dashboards.schema.template.interval import Interval from grafana_dashboards.schema.template.query import Query +from grafana_dashboards.schema.template.textbox import Textbox class Template(object): @@ -52,6 +53,8 @@ def f(data): schema = Datasource().get_schema() if template["type"] == "adhoc": schema = Adhoc().get_schema() + if template["type"] == "textbox": + schema = Textbox().get_schema() res["list"].append(schema(template)) diff --git a/grafana_dashboards/schema/template/base.py b/grafana_dashboards/schema/template/base.py index 0eb83f2..6e5d819 100644 --- a/grafana_dashboards/schema/template/base.py +++ b/grafana_dashboards/schema/template/base.py @@ -66,7 +66,13 @@ def __init__(self): self.base = { v.Required("name"): v.All(str, v.Length(min=1)), v.Required("type"): v.Any( - "query", "interval", "custom", "datasource", "adhoc", "constant" + "query", + "interval", + "custom", + "datasource", + "adhoc", + "constant", + "textbox", ), v.Optional("description"): v.All(str), } diff --git a/grafana_dashboards/schema/template/textbox.py b/grafana_dashboards/schema/template/textbox.py new file mode 100644 index 0000000..eae7ca8 --- /dev/null +++ b/grafana_dashboards/schema/template/textbox.py @@ -0,0 +1,29 @@ +# Copyright 2018 Delivery Hero SE. +# +# 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.template.base import Base + + +class Textbox(Base): + def get_schema(self): + query = { + v.Optional("hide"): v.All(int, v.Range(min=0, max=2)), + v.Optional("label", default=""): v.All(str), + v.Optional("name"): v.All(str), + v.Optional("query"): v.All(str), + } + query.update(self.base) + return v.Schema(query)