forked from nordcloud/go-pingdom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_types.go
104 lines (92 loc) · 3.08 KB
/
integration_types.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package pingdomext
import (
"encoding/json"
"fmt"
"strconv"
)
// IntegrationProvider represents a Pingdom integration provider.
type IntegrationProvider struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
}
// WebHookIntegration represents a Pingdom WebHook integration.
type WebHookIntegration struct {
Active bool `json:"active"`
ProviderID int `json:"provider_id"`
UserData *WebHookData `json:"user_data"`
}
// WebHookData represents a WebHook data in the WebHook integration.
type WebHookData struct {
Name string `json:"name"`
URL string `json:"url"`
}
/*
// LibratoIntegration represents a Pingdom Librato integration.
type LibratoIntegration struct {
Active bool `json:"active"`
ProviderID int `json:"provider_id"`
UserData *LibratoData `json:"user_data"`
}
// LibratoData represents a Librato data in the Librato integration.
type LibratoData struct {
Name string `json:"name"`
Email string `json:"email"`
ApiToken string `json:"apiToken"`
}
*/
// PostParams returns a map of parameters for an WebHook integration that can be sent along.
func (wi *WebHookIntegration) PostParams() map[string]string {
dataJSON, err := json.Marshal(wi.UserData)
fmt.Println(err)
m := map[string]string{
"active": strconv.FormatBool(wi.Active),
"provider_id": strconv.Itoa(wi.ProviderID),
"data_json": string(dataJSON),
}
return m
}
// Valid determines whether the WebHook integration contains valid fields. This can be
// used to guard against sending illegal values to the Pingdom API.
func (wi *WebHookIntegration) Valid() error {
if wi.ProviderID != 1 && wi.ProviderID != 2 {
return fmt.Errorf("Invalid value for `provider`. Must contain available provider id")
}
if wi.UserData.Name == "" {
return fmt.Errorf("Invalid value for `name`. Must contain non-empty string")
}
if wi.UserData.URL == "" {
return fmt.Errorf("Invalid value for `url`. Must contain non-empty string")
}
return nil
}
/*
// PostParams returns a map of parameters for an Librato integration that can be sent along.
func (li *LibratoIntegration) PostParams() map[string]string {
dataJSON, err := toJsonNoEscape(li.UserData)
fmt.Println(err)
m := map[string]string{
"active": strconv.FormatBool(li.Active),
"provider_id": strconv.Itoa(li.ProviderID),
"data_json": string(dataJSON),
}
return m
}
// Valid determines whether the Librato integration contains valid fields. This can be
// used to guard against sending illegal values to the Pingdom API.
func (li *LibratoIntegration) Valid() error {
if li.ProviderID != 1 && li.ProviderID != 2 {
return fmt.Errorf("Invalid value for `provider`. Must contain available provider")
}
if li.UserData.Name == "" {
return fmt.Errorf("Invalid value for `name`. Must contain non-empty string")
}
if li.UserData.ApiToken == "" {
return fmt.Errorf("Invalid value for `api token`. Must contain non-empty string")
}
if li.UserData.Email == "" {
return fmt.Errorf("Invalid value for `email`. Must contain non-empty string")
}
return nil
}
*/