github.com/wtfutil/wtf@v0.43.0/modules/newrelic/client/key_transactions.go (about) 1 package newrelic 2 3 import ( 4 "strconv" 5 "time" 6 ) 7 8 // KeyTransactionsFilter is the filtering component of KeyTransactionsOptions. 9 type KeyTransactionsFilter struct { 10 Name string 11 IDs []int 12 } 13 14 // KeyTransactionsOptions provides a filtering mechanism for GetKeyTransactions. 15 type KeyTransactionsOptions struct { 16 Filter KeyTransactionsFilter 17 Page int 18 } 19 20 // KeyTransactionLinks link KeyTransactions to the objects to which they 21 // pertain. 22 type KeyTransactionLinks struct { 23 Application int `json:"application,omitempty"` 24 } 25 26 // KeyTransaction represents a New Relic Key Transaction. 27 type KeyTransaction struct { 28 ID int `json:"id,omitempty"` 29 Name string `json:"name,omitempty"` 30 TransactionName string `json:"transaction_name,omitempty"` 31 HealthStatus string `json:"health_status,omitempty"` 32 Reporting bool `json:"reporting,omitempty"` 33 LastReportedAt time.Time `json:"last_reported_at,omitempty"` 34 ApplicationSummary ApplicationSummary `json:"application_summary,omitempty"` 35 EndUserSummary EndUserSummary `json:"end_user_summary,omitempty"` 36 Links KeyTransactionLinks `json:"links,omitempty"` 37 } 38 39 // GetKeyTransactions will return a slice of New Relic Key Transactions, 40 // optionally filtered by KeyTransactionsOptions. 41 func (c *Client) GetKeyTransactions(opt *KeyTransactionsOptions) ([]KeyTransaction, error) { 42 resp := &struct { 43 KeyTransactions []KeyTransaction `json:"key_transactions,omitempty"` 44 }{} 45 path := "key_transactions.json" 46 err := c.doGet(path, opt, resp) 47 if err != nil { 48 return nil, err 49 } 50 return resp.KeyTransactions, nil 51 } 52 53 // GetKeyTransaction will return a single New Relic Key Transaction for the 54 // given id. 55 func (c *Client) GetKeyTransaction(id int) (*KeyTransaction, error) { 56 resp := &struct { 57 KeyTransaction *KeyTransaction `json:"key_transaction,omitempty"` 58 }{} 59 path := "key_transactions/" + strconv.Itoa(id) + ".json" 60 err := c.doGet(path, nil, resp) 61 if err != nil { 62 return nil, err 63 } 64 return resp.KeyTransaction, nil 65 } 66 67 func (o *KeyTransactionsOptions) String() string { 68 if o == nil { 69 return "" 70 } 71 return encodeGetParams(map[string]interface{}{ 72 "filter[name]": o.Filter.Name, 73 "filter[ids]": o.Filter.IDs, 74 "page": o.Page, 75 }) 76 }