Skip to content

Commit

Permalink
add support for template variable presets
Browse files Browse the repository at this point in the history
  • Loading branch information
laurmurclar committed Sep 28, 2020
1 parent f15a593 commit 5fc6918
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 36 deletions.
24 changes: 21 additions & 3 deletions dashboard-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function convert(key, value) {
result += assignmentString(key, value);
} else if (key === "widgets") {
result += convertWidgets(value);
} else if (key === "template_variable_presets") {
result += convertTemplateVariablePresets(value);
} else {
throw `Conversion for "${key}" not found`;
}
Expand Down Expand Up @@ -124,8 +126,7 @@ function convertRequests(name, requests) {
result += convertMapping(key, value);
} else if (key === "conditional_formats") {
result += convertConditionalFormats(key, value);
}
else {
} else {
result += assignmentString(key, value);
}
});
Expand Down Expand Up @@ -158,4 +159,21 @@ function convertConditionalFormats(name, conditionalFormats) {
result += "}\n";
}
return result;
}
}

function convertTemplateVariablePresets(presets) {
let result = "";
for (let preset of presets) {
result += "template_variable_preset {\n";

Object.entries(preset).forEach(([key, value]) => {
if (key == "template_variables") {
result += convertArrayOfObjects(key, value);
} else {
result += assignmentString(key, value);
}
});
result += "}\n";
}
return result;
}
2 changes: 1 addition & 1 deletion examples/screenboard.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "datadog_dashboard" "hi" {
resource "datadog_dashboard" "sb" {
title = "Laura's Screenboard 7 Sep 2020 13:18"
description = ""
widget {
Expand Down
41 changes: 20 additions & 21 deletions examples/timeboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
{
"q": "avg:system.cpu.user{*}",
"display_type": "line",
"style": {
"palette": "dog_classic",
"line_type": "solid",
"line_width": "normal"
}
"style": { "palette": "dog_classic", "line_type": "solid", "line_width": "normal" }
}
],
"yaxis": {
Expand All @@ -38,33 +34,36 @@
"q": "avg:datadog.agent.running{*}",
"aggregator": "avg",
"conditional_formats": [
{
"comparator": "<=",
"value": 1,
"palette": "white_on_green"
},
{
"comparator": ">",
"value": 1,
"palette": "white_on_yellow"
},
{
"comparator": ">=",
"value": 3,
"palette": "white_on_red"
}
{ "comparator": "<", "value": 1, "palette": "white_on_red" },
{ "comparator": ">=", "value": 1, "palette": "white_on_green" }
]
}
],
"title": "Avg of datadog.agent.running over *",
"time": {},
"autoscale": true,
"precision": 2
}
}
],
"template_variables": [],
"template_variables": [
{ "name": "major", "default": "*", "prefix": "agent_version_major" },
{ "name": "minor", "default": "*", "prefix": "agent_version_minor" },
{ "name": "patch", "default": "*", "prefix": "agent_version_patch" }
],
"layout_type": "ordered",
"is_read_only": false,
"notify_list": [],
"template_variable_presets": [
{ "name": ">= 7", "template_variables": [{ "name": "major", "value": "7" }] },
{
"name": "Latest",
"template_variables": [
{ "name": "major", "value": "7" },
{ "name": "minor", "value": "21" },
{ "name": "patch", "value": "1" }
]
}
],
"id": "hww-tah-72j"
}
56 changes: 45 additions & 11 deletions examples/timeboard.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "datadog_dashboard" "hi" {
resource "datadog_dashboard" "tb" {
title = "Laura's Timeboard 21 Aug 2020 16:30"
description = ""
widget {
Expand Down Expand Up @@ -30,27 +30,61 @@ resource "datadog_dashboard" "hi" {
q = "avg:datadog.agent.running{*}"
aggregator = "avg"
conditional_formats {
comparator = "<="
comparator = "<"
value = 1
palette = "white_on_green"
}
conditional_formats {
comparator = ">"
value = 1
palette = "white_on_yellow"
palette = "white_on_red"
}
conditional_formats {
comparator = ">="
value = 3
palette = "white_on_red"
value = 1
palette = "white_on_green"
}
}
title = "Avg of datadog.agent.running over *"
title = "Avg of datadog.agent.running over *"
time = {
}
autoscale = true
precision = 2
}
}
template_variable {
name = "major"
default = "*"
prefix = "agent_version_major"
}
template_variable {
name = "minor"
default = "*"
prefix = "agent_version_minor"
}
template_variable {
name = "patch"
default = "*"
prefix = "agent_version_patch"
}
layout_type = "ordered"
is_read_only = false
notify_list = []
template_variable_preset {
name = ">= 7"
template_variable {
name = "major"
value = "7"
}
}
template_variable_preset {
name = "Latest"
template_variable {
name = "major"
value = "7"
}
template_variable {
name = "minor"
value = "21"
}
template_variable {
name = "patch"
value = "1"
}
}
}

0 comments on commit 5fc6918

Please sign in to comment.