-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv.go
59 lines (54 loc) · 1.17 KB
/
csv.go
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
package main
import (
"encoding/csv"
"fmt"
"log"
"os"
)
func (data *LocalData) writeCSV() {
var rows [][]string
outputCSV := fmt.Sprintf("dashboards_%d.csv", data.AccountId)
f, err := os.Create(outputCSV)
if err != nil {
log.Printf("Error opening csv: %v", err)
}
// Make rows
rows = append(rows, []string{
"guid",
"name",
"permalink",
"createdBy",
"chartId",
"chartName",
"nrqlAccountId",
"nrqlQuery",
})
for _, dashboard := range data.DashboardMap {
//log.Printf("Found Dashboard %s, page=%v", dashboard.Guid, dashboard.IsPage)
for _, widgetId := range dashboard.WidgetIds {
widget := dashboard.WidgetMap[widgetId]
for _, query := range widget.NrqlQueries {
rows = append(rows, []string{
dashboard.Guid,
dashboard.Name,
dashboard.Permalink,
dashboard.CreatedBy,
fmt.Sprintf("%d", widgetId),
widget.Title,
fmt.Sprintf("%d", query.AccountId),
query.Query,
})
}
}
}
// Write CSV
log.Printf("Writing csv %s with %d entries", outputCSV, len(rows)-1)
w := csv.NewWriter(f)
err = w.WriteAll(rows)
if err != nil {
log.Printf("Error writing %s: %v", outputCSV, err)
}
w.Flush()
f.Sync()
f.Close()
}