forked from TheQuestionru/newrelic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
key_transactions.go
76 lines (68 loc) · 2.29 KB
/
key_transactions.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
package newrelic
import (
"strconv"
"time"
)
// KeyTransactionsFilter is the filtering component of KeyTransactionsOptions.
type KeyTransactionsFilter struct {
Name string
IDs []int
}
// KeyTransactionsOptions provides a filtering mechanism for GetKeyTransactions.
type KeyTransactionsOptions struct {
Filter KeyTransactionsFilter
Page int
}
// KeyTransactionLinks link KeyTransactions to the objects to which they
// pertain.
type KeyTransactionLinks struct {
Application int `json:"application,omitempty"`
}
// KeyTransaction represents a New Relic Key Transaction.
type KeyTransaction struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
TransactionName string `json:"transaction_name,omitempty"`
HealthStatus string `json:"health_status,omitempty"`
Reporting bool `json:"reporting,omitempty"`
LastReportedAt time.Time `json:"last_reported_at,omitempty"`
ApplicationSummary ApplicationSummary `json:"application_summary,omitempty"`
EndUserSummary EndUserSummary `json:"end_user_summary,omitempty"`
Links KeyTransactionLinks `json:"links,omitempty"`
}
// GetKeyTransactions will return a slice of New Relic Key Transactions,
// optionally filtered by KeyTransactionsOptions.
func (c *Client) GetKeyTransactions(opt *KeyTransactionsOptions) ([]KeyTransaction, error) {
resp := &struct {
KeyTransactions []KeyTransaction `json:"key_transactions,omitempty"`
}{}
path := "key_transactions.json"
err := c.doGet(path, opt, resp)
if err != nil {
return nil, err
}
return resp.KeyTransactions, nil
}
// GetKeyTransaction will return a single New Relic Key Transaction for the
// given id.
func (c *Client) GetKeyTransaction(id int) (*KeyTransaction, error) {
resp := &struct {
KeyTransaction *KeyTransaction `json:"key_transaction,omitempty"`
}{}
path := "key_transactions/" + strconv.Itoa(id) + ".json"
err := c.doGet(path, nil, resp)
if err != nil {
return nil, err
}
return resp.KeyTransaction, nil
}
func (o *KeyTransactionsOptions) String() string {
if o == nil {
return ""
}
return encodeGetParams(map[string]interface{}{
"filter[name]": o.Filter.Name,
"filter[ids]": o.Filter.IDs,
"page": o.Page,
})
}