github.com/wtfutil/wtf@v0.43.0/modules/newrelic/client/legacy_alert_policies.go (about) 1 package newrelic 2 3 import ( 4 "strconv" 5 ) 6 7 // LegacyAlertPolicyLinks describes object links for Alert Policies. 8 type LegacyAlertPolicyLinks struct { 9 NotificationChannels []int `json:"notification_channels,omitempty"` 10 Servers []int `json:"servers,omitempty"` 11 } 12 13 // LegacyAlertPolicyCondition describes conditions that trigger an LegacyAlertPolicy. 14 type LegacyAlertPolicyCondition struct { 15 ID int `json:"id,omitempty"` 16 Enabled bool `json:"enabled,omitempty"` 17 Severity string `json:"severity,omitempty"` 18 Threshold float64 `json:"threshold,omitempty"` 19 TriggerMinutes int `json:"trigger_minutes,omitempty"` 20 Type string `json:"type,omitempty"` 21 } 22 23 // LegacyAlertPolicy describes a New Relic alert policy. 24 type LegacyAlertPolicy struct { 25 Conditions []LegacyAlertPolicyCondition `json:"conditions,omitempty"` 26 Enabled bool `json:"enabled,omitempty"` 27 ID int `json:"id,omitempty"` 28 Links LegacyAlertPolicyLinks `json:"links,omitempty"` 29 IncidentPreference string `json:"incident_preference,omitempty"` 30 Name string `json:"name,omitempty"` 31 } 32 33 // LegacyAlertPolicyFilter provides filters for LegacyAlertPolicyOptions. 34 type LegacyAlertPolicyFilter struct { 35 Name string 36 } 37 38 // LegacyAlertPolicyOptions is an optional means of filtering when calling 39 // GetLegacyAlertPolicies. 40 type LegacyAlertPolicyOptions struct { 41 Filter LegacyAlertPolicyFilter 42 Page int 43 } 44 45 func (o *LegacyAlertPolicyOptions) String() string { 46 if o == nil { 47 return "" 48 } 49 return encodeGetParams(map[string]interface{}{ 50 "filter[name]": o.Filter.Name, 51 "page": o.Page, 52 }) 53 } 54 55 // GetLegacyAlertPolicy will return the LegacyAlertPolicy with particular ID. 56 func (c *Client) GetLegacyAlertPolicy(id int) (*LegacyAlertPolicy, error) { 57 resp := &struct { 58 LegacyAlertPolicy *LegacyAlertPolicy `json:"alert_policy,omitempty"` 59 }{} 60 err := c.doGet("alert_policies/"+strconv.Itoa(id)+".json", nil, resp) 61 if err != nil { 62 return nil, err 63 } 64 return resp.LegacyAlertPolicy, nil 65 } 66 67 // GetLegacyAlertPolicies will return a slice of LegacyAlertPolicy items, 68 // optionally filtering by LegacyAlertPolicyOptions. 69 func (c *Client) GetLegacyAlertPolicies(options *LegacyAlertPolicyOptions) ([]LegacyAlertPolicy, error) { 70 resp := &struct { 71 LegacyAlertPolicies []LegacyAlertPolicy `json:"alert_policies,omitempty"` 72 }{} 73 err := c.doGet("alert_policies.json", options, resp) 74 if err != nil { 75 return nil, err 76 } 77 return resp.LegacyAlertPolicies, nil 78 }