github.com/wtfutil/wtf@v0.43.0/modules/newrelic/client/alert_events.go (about) 1 package newrelic 2 3 // AlertEvent describes a triggered event. 4 type AlertEvent struct { 5 ID int `json:"id,omitempty"` 6 EventType string `json:"event_type,omitempty"` 7 Product string `json:"product,omitempty"` 8 EntityType string `json:"entity_type,omitempty"` 9 EntityGroupID int `json:"entity_group_id,omitempty"` 10 EntityID int `json:"entity_id,omitempty"` 11 Priority string `json:"priority,omitempty"` 12 Description string `json:"description,omitempty"` 13 Timestamp int64 `json:"timestamp,omitempty"` 14 IncidentID int `json:"incident_id"` 15 } 16 17 // AlertEventFilter provides filters for AlertEventOptions when calling 18 // GetAlertEvents. 19 type AlertEventFilter struct { 20 // TODO: New relic restricts these options 21 Product string 22 EntityType string 23 EntityGroupID int 24 EntityID int 25 EventType string 26 } 27 28 // AlertEventOptions is an optional means of filtering AlertEvents when 29 // calling GetAlertEvents. 30 type AlertEventOptions struct { 31 Filter AlertEventFilter 32 Page int 33 } 34 35 func (o *AlertEventOptions) String() string { 36 if o == nil { 37 return "" 38 } 39 return encodeGetParams(map[string]interface{}{ 40 "filter[product]": o.Filter.Product, 41 "filter[entity_type]": o.Filter.EntityType, 42 "filter[entity_group_id]": o.Filter.EntityGroupID, 43 "filter[entity_id]": o.Filter.EntityID, 44 "filter[event_type]": o.Filter.EventType, 45 "page": o.Page, 46 }) 47 } 48 49 // GetAlertEvents will return a slice of recent AlertEvent items triggered, 50 // optionally filtering by AlertEventOptions. 51 func (c *Client) GetAlertEvents(options *AlertEventOptions) ([]AlertEvent, error) { 52 resp := &struct { 53 RecentEvents []AlertEvent `json:"recent_events,omitempty"` 54 }{} 55 err := c.doGet("alerts_events.json", options, resp) 56 if err != nil { 57 return nil, err 58 } 59 return resp.RecentEvents, nil 60 }