forked from amnk/dd2tf
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmonitors.go
54 lines (46 loc) · 1008 Bytes
/
monitors.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
//go:generate go-bindata -o tpl.go tmpl
package main
import (
"errors"
"strconv"
"github.com/zorkian/go-datadog-api"
)
type Monitor struct {
}
func (m Monitor) getElement(client datadog.Client, id interface{}) (interface{}, error) {
var idInt int
switch v := id.(type) {
case string:
var err error
idInt, err = strconv.Atoi(v)
if (err != nil) {
return "", err
}
case int:
idInt = v
default:
return "", errors.New("unsupported id type, should be string or int")
}
mon, err := client.GetMonitor(idInt)
return mon, err
}
func (m Monitor) getAsset() string {
return "tmpl/monitor.tmpl"
}
func (m Monitor) getName() string {
return "monitors"
}
func (m Monitor) String() string {
return m.getName()
}
func (m Monitor) getAllElements(client datadog.Client) ([]Item, error) {
var ids []Item
monitors, err := client.GetMonitors()
if err != nil {
return nil, err
}
for _, elem := range monitors {
ids = append(ids, Item{id: *elem.Id, d: Monitor{}})
}
return ids, nil
}