github.com/wtfutil/wtf@v0.43.0/modules/newrelic/client/notification_channels.go (about) 1 package newrelic 2 3 import ( 4 "strconv" 5 ) 6 7 // NotificationChannelLinks describes object links for notification channels. 8 type NotificationChannelLinks struct { 9 NotificationChannels []int `json:"notification_channels,omitempty"` 10 User int `json:"user,omitempty"` 11 } 12 13 // NotificationChannel describes a New Relic notification channel. 14 type NotificationChannel struct { 15 ID int `json:"id,omitempty"` 16 Type string `json:"type,omitempty"` 17 DowntimeOnly bool `json:"downtime_only,omitempty"` 18 URL string `json:"url,omitempty"` 19 Name string `json:"name,omitempty"` 20 Description string `json:"description,omitempty"` 21 Email string `json:"email,omitempty"` 22 Subdomain string `json:"subdomain,omitempty"` 23 Service string `json:"service,omitempty"` 24 MobileAlerts bool `json:"mobile_alerts,omitempty"` 25 EmailAlerts bool `json:"email_alerts,omitempty"` 26 Room string `json:"room,omitempty"` 27 Links NotificationChannelLinks `json:"links,omitempty"` 28 } 29 30 // NotificationChannelsFilter provides filters for 31 // NotificationChannelsOptions. 32 type NotificationChannelsFilter struct { 33 Type []string 34 IDs []int 35 } 36 37 // NotificationChannelsOptions is an optional means of filtering when calling 38 // GetNotificationChannels. 39 type NotificationChannelsOptions struct { 40 Filter NotificationChannelsFilter 41 Page int 42 } 43 44 func (o *NotificationChannelsOptions) String() string { 45 if o == nil { 46 return "" 47 } 48 return encodeGetParams(map[string]interface{}{ 49 "filter[type]": o.Filter.Type, 50 "filter[ids]": o.Filter.IDs, 51 "page": o.Page, 52 }) 53 } 54 55 // GetNotificationChannel will return the NotificationChannel with particular ID. 56 func (c *Client) GetNotificationChannel(id int) (*NotificationChannel, error) { 57 resp := &struct { 58 NotificationChannel *NotificationChannel `json:"notification_channel,omitempty"` 59 }{} 60 err := c.doGet("notification_channels/"+strconv.Itoa(id)+".json", nil, resp) 61 if err != nil { 62 return nil, err 63 } 64 return resp.NotificationChannel, nil 65 } 66 67 // GetNotificationChannels will return a slice of NotificationChannel items, 68 // optionally filtering by NotificationChannelsOptions. 69 func (c *Client) GetNotificationChannels(options *NotificationChannelsOptions) ([]NotificationChannel, error) { 70 resp := &struct { 71 NotificationChannels []NotificationChannel `json:"notification_channels,omitempty"` 72 }{} 73 err := c.doGet("notification_channels.json", options, resp) 74 if err != nil { 75 return nil, err 76 } 77 return resp.NotificationChannels, nil 78 }