-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
131 lines (104 loc) · 3.44 KB
/
main.go
File metadata and controls
131 lines (104 loc) · 3.44 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package main
import (
"encoding/json"
"flag"
"fmt"
"strconv"
"strings"
"sync"
)
func main() {
var (
dashMap = make(map[string]map[string]string)
metricSearchResults = make(map[string][]string)
monitorSearchResults = make(map[string][]string)
searchWaitGrp = new(sync.WaitGroup)
dashDetails = flag.String("dash-details", "", "String: Get details for a specific dashboard by ID")
dashList = flag.Bool("dash-list", false, "Bool: Will list all DataDog dashboards.")
metricFind = flag.String("find-metric", "", "String: Search our DataDog dashboards for the provided metric name to see if it is in use")
monitorList = flag.Bool("monitor-list", false, "Bool: Will list all DataDog monitors.")
)
flag.Parse()
if *metricFind != "" {
searchWaitGrp.Add(1)
go func() {
fmt.Println("\nSearching for your metric across all & monitors.")
metricSearchResults = FindMetric(*metricFind)
fmt.Println("\n4. Feast your eyes upon the dashboards and monitors using your metric.")
jsonMetrics, err := json.MarshalIndent(metricSearchResults, "", " ")
if err != nil {
fmt.Println("ERROR: \n ", err)
}
fmt.Println(string(jsonMetrics))
var dashIds []string
for dashId, _ := range metricSearchResults {
dashIds = append(dashIds, dashId)
}
details := make(map[string]string)
for _, name := range dashIds {
details = GetDashboardDetails(name)
jsonDetails, _ := json.MarshalIndent(details, "", " ")
fmt.Println(string(jsonDetails))
}
searchWaitGrp.Done()
}()
searchWaitGrp.Add(1)
go func() {
monitors := GetMonitors()
monitorsWaitGrp := new(sync.WaitGroup)
for _, monitor := range monitors {
monitorsWaitGrp.Add(1)
go func() {
if strings.Contains(monitor.GetQuery(), *metricFind) {
monitorSearchResults[monitor.GetName()] = append(monitorSearchResults[monitor.GetName()], monitor.GetQuery())
}
monitorsWaitGrp.Done()
}()
monitorsWaitGrp.Wait()
}
searchWaitGrp.Done()
}()
searchWaitGrp.Wait()
jsonMonitors, err := json.MarshalIndent(monitorSearchResults, "", " ")
if err != nil {
fmt.Println("ERROR: ", err)
}
fmt.Println(string(jsonMonitors))
} else if *dashList != false {
dashMap = GetDashboards()
fmt.Println("Here is the list of dashboards in an attractive JSON format: ")
jsonDashboards, _ := json.MarshalIndent(dashMap, "", " ")
fmt.Println(string(jsonDashboards))
} else if *dashDetails != "" {
details := GetDashboardDetails(*dashDetails)
jsonDetails, err := json.MarshalIndent(details, "", " ")
if err != nil {
fmt.Println("ERROR: \n ", err)
}
fmt.Println("Here are the high-level details: ")
fmt.Println(string(jsonDetails))
// fmt.Println("Widget ID's and expressions are: ")
// fmt.Println(string(expressionJson))
} else if *monitorList != false {
var (
monitorMap = make(map[string]map[string]string)
monitorId string
)
monitors := GetMonitors()
for _, monitor := range monitors {
monitorId = strconv.FormatInt(monitor.GetId(), 10)
monitorCreatorName := monitor.Creator.GetName()
monitorMap[monitor.GetName()] = map[string]string{
"ID": monitorId,
"Creator": monitorCreatorName,
"Query": monitor.GetQuery(),
}
}
jsonMonitors, err := json.MarshalIndent(monitorMap, "", " ")
if err != nil {
fmt.Printf("ERROR: %v\n", err)
}
fmt.Println("Here are all of the monitors & some info: \n")
fmt.Println(string(jsonMonitors))
}
}