-
Notifications
You must be signed in to change notification settings - Fork 191
/
opsgenie_policy_client.go
61 lines (50 loc) · 1.88 KB
/
opsgenie_policy_client.go
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
package client
import (
"errors"
"github.com/AcalephStorage/consul-alerts/Godeps/_workspace/src/github.com/opsgenie/opsgenie-go-sdk/logging"
policy "github.com/AcalephStorage/consul-alerts/Godeps/_workspace/src/github.com/opsgenie/opsgenie-go-sdk/policy"
)
const (
enablePolicyURL = "/v1/json/alert/policy/enable"
disablePolicyURL = "/v1/json/alert/policy/disable"
)
// OpsGeniePolicyClient is the data type to make Policy API requests.
type OpsGeniePolicyClient struct {
OpsGenieClient
}
// SetOpsGenieClient sets the embedded OpsGenieClient type of the OpsGeniePolicyClient.
func (cli *OpsGeniePolicyClient) SetOpsGenieClient(ogCli OpsGenieClient) {
cli.OpsGenieClient = ogCli
}
// Enable method enables an Policy at OpsGenie.
func (cli *OpsGeniePolicyClient) Enable(req policy.EnablePolicyRequest) (*policy.EnablePolicyResponse, error) {
req.APIKey = cli.apiKey
resp, err := cli.sendRequest(cli.buildPostRequest(enablePolicyURL, req))
if resp == nil {
return nil, err
}
defer resp.Body.Close()
var enablePolicyResp policy.EnablePolicyResponse
if err = resp.Body.FromJsonTo(&enablePolicyResp); err != nil {
message := "Server response can not be parsed, " + err.Error()
logging.Logger().Warn(message)
return nil, errors.New(message)
}
return &enablePolicyResp, nil
}
// Disable method disables an Policy at OpsGenie.
func (cli *OpsGeniePolicyClient) Disable(req policy.DisablePolicyRequest) (*policy.DisablePolicyResponse, error) {
req.APIKey = cli.apiKey
resp, err := cli.sendRequest(cli.buildPostRequest(disablePolicyURL, req))
if resp == nil {
return nil, err
}
defer resp.Body.Close()
var disablePolicyResp policy.DisablePolicyResponse
if err = resp.Body.FromJsonTo(&disablePolicyResp); err != nil {
message := "Server response can not be parsed, " + err.Error()
logging.Logger().Warn(message)
return nil, errors.New(message)
}
return &disablePolicyResp, nil
}