-
Notifications
You must be signed in to change notification settings - Fork 2
/
do-object-list.go
115 lines (108 loc) · 2.63 KB
/
do-object-list.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
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
// Backup tool for Grafana.
// Copyright (C) 2016-2017 Alexander I.Grafov <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ॐ तारे तुत्तारे तुरे स्व
package main
import (
"fmt"
"os"
"github.com/grafana-tools/sdk"
)
func doObjectList(opts ...option) {
var (
cmd = initCommand(opts...)
)
if cmd.applyForBoards {
listDashboards(cmd)
}
if cmd.applyForDs {
listDatasources(cmd)
}
if cmd.applyForUsers {
listUsers(cmd)
}
}
func listDashboards(cmd *command) {
var (
foundBoards []sdk.FoundBoard
err error
)
if foundBoards, err = cmd.grafana.SearchDashboards(cmd.boardTitle, cmd.starred, cmd.tags...); err != nil {
fmt.Fprintf(os.Stderr, fmt.Sprintf("%s\n", err))
return
}
for _, meta := range foundBoards {
select {
case <-cancel:
exitBySignal()
default:
fmt.Printf("<%d> \"%s\" %v ", meta.ID, meta.Title, meta.Tags)
if meta.IsStarred {
fmt.Print("*")
}
fmt.Println()
}
if cmd.verbose {
fmt.Printf("Found %d dashboards.\n", len(foundBoards))
}
}
}
func listDatasources(cmd *command) {
var (
datasources []sdk.Datasource
err error
)
if datasources, err = cmd.grafana.GetAllDatasources(); err != nil {
fmt.Fprintf(os.Stderr, fmt.Sprintf("%s\n", err))
return
}
for _, ds := range datasources {
select {
case <-cancel:
exitBySignal()
default:
fmt.Printf("<%d> \"%s\" (%s) %s\n", ds.ID, ds.Name, ds.Type, ds.URL)
}
if cmd.verbose {
fmt.Printf("Found %d datasources.\n", len(datasources))
}
}
}
func listUsers(cmd *command) {
var (
allUsers []sdk.User
err error
)
if allUsers, err = cmd.grafana.GetAllUsers(); err != nil {
fmt.Fprintf(os.Stderr, fmt.Sprintf("%s\n", err))
return
}
for _, user := range allUsers {
select {
case <-cancel:
exitBySignal()
default:
fmt.Printf("%s \"%s\" <%s>", user.Login, user.Name, user.Email)
if user.IsGrafanaAdmin {
fmt.Print(" admin")
}
fmt.Println()
}
if cmd.verbose {
fmt.Printf("Found %d users.\n", len(allUsers))
}
}
}