File: alert.go

package info (click to toggle)
golang-github-centurylinkcloud-clc-sdk 0.0.2%2Bgit20161004.f62483c-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 236 kB
  • sloc: sh: 18; makefile: 13
file content (80 lines) | stat: -rw-r--r-- 1,882 bytes parent folder | download | duplicates (2)
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
77
78
79
80
package alert

import (
	"fmt"

	"github.com/CenturyLinkCloud/clc-sdk/api"
)

func New(client api.HTTP) *Service {
	return &Service{
		client: client,
		config: client.Config(),
	}
}

type Service struct {
	client api.HTTP
	config *api.Config
}

func (s *Service) Get(id string) (*Alert, error) {
	url := fmt.Sprintf("%s/alertPolicies/%s/%s", s.config.BaseURL, s.config.Alias, id)
	resp := &Alert{}
	err := s.client.Get(url, resp)
	return resp, err
}

func (s *Service) GetAll() (*Alerts, error) {
	url := fmt.Sprintf("%s/alertPolicies/%s", s.config.BaseURL, s.config.Alias)
	resp := &Alerts{}
	err := s.client.Get(url, resp)
	return resp, err
}

func (s *Service) Create(alert Alert) (*Alert, error) {
	url := fmt.Sprintf("%s/alertPolicies/%s", s.config.BaseURL, s.config.Alias)
	resp := &Alert{}
	err := s.client.Post(url, alert, resp)
	return resp, err
}

func (s *Service) Update(id string, alert Alert) (*Alert, error) {
	url := fmt.Sprintf("%s/alertPolicies/%s/%s", s.config.BaseURL, s.config.Alias, id)
	resp := &Alert{}
	err := s.client.Put(url, alert, resp)
	return resp, err
}

func (s *Service) Delete(id string) error {
	url := fmt.Sprintf("%s/alertPolicies/%s/%s", s.config.BaseURL, s.config.Alias, id)
	return s.client.Delete(url, nil)
}

type Alerts struct {
	Items []Alert   `json:"items"`
	Links api.Links `json:"links"`
}

type Alert struct {
	ID       string    `json:"id,omitempty"`
	Name     string    `json:"name,omitempty"`
	Actions  []Action  `json:"actions,omitempty"`
	Triggers []Trigger `json:"triggers,omitempty"`
	Links    api.Links `json:"links,omitempty"`
}

type Action struct {
	Action  string  `json:"action"`
	Setting Setting `json:"settings"`
}

type Setting struct {
	Recipients []string `json:"recipients"`
}

type Trigger struct {
	Metric    string  `json:"metric"`
	Duration  string  `json:"duration"`
	Threshold float64 `json:"threshold"`
}