forked from spaceapegames/go-wavefront
-
Notifications
You must be signed in to change notification settings - Fork 12
/
externallinks.go
92 lines (78 loc) · 2.4 KB
/
externallinks.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
package wavefront
import (
"fmt"
)
type ExternalLink struct {
ID *string `json:"id,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
CreatorId string `json:"creatorId,omitempty"`
UpdaterId string `json:"updaterId,omitempty"`
UpdatedEpochMillis int `json:"updatedEpochMillis,omitempty"`
CreatedEpochMillis int `json:"createdEpochMillis,omitempty"`
Template string `json:"template"`
MetricFilterRegex string `json:"metricFilterRegex,omitempty"`
SourceFilterRegex string `json:"sourceFilterRegex,omitempty"`
PointTagFilterRegexes map[string]string `json:"pointTagFilterRegexes,omitempty"`
IsLogIntegration bool `json:"isLogIntegration,omitempty"`
}
const baseExtLinkPath = "/api/v2/extlink"
type ExternalLinks struct {
client Wavefronter
}
func (c *Client) ExternalLinks() *ExternalLinks {
return &ExternalLinks{client: c}
}
func (e ExternalLinks) Find(conditions []*SearchCondition) (
results []*ExternalLink, err error) {
err = doSearch(conditions, "extlink", e.client, &results)
return
}
func (e ExternalLinks) Get(link *ExternalLink) error {
if link.ID == nil || *link.ID == "" {
return fmt.Errorf("id must be specified")
}
return doRest(
"GET",
fmt.Sprintf("%s/%s", baseExtLinkPath, *link.ID),
e.client,
doResponse(link))
}
func (e ExternalLinks) Create(link *ExternalLink) error {
if link.Name == "" || link.Description == "" || link.Template == "" {
return fmt.Errorf("externa link name, description, and template must be specified")
}
return doRest(
"POST",
baseExtLinkPath,
e.client,
doPayload(link),
doResponse(link))
}
func (e ExternalLinks) Update(link *ExternalLink) error {
if link.ID == nil || *link.ID == "" {
return fmt.Errorf("id must be specified")
}
return doRest(
"PUT",
fmt.Sprintf("%s/%s", baseExtLinkPath, *link.ID),
e.client,
doPayload(link),
doResponse(link))
}
func (e ExternalLinks) Delete(link *ExternalLink) error {
if *link.ID == "" {
return fmt.Errorf("id must be specified")
}
err := doRest(
"DELETE",
fmt.Sprintf("%s/%s", baseExtLinkPath, *link.ID),
e.client)
if err != nil {
return err
}
// Clear out the id to prevent re-submission
empty := ""
link.ID = &empty
return nil
}