-
Notifications
You must be signed in to change notification settings - Fork 131
/
data_dbaas_logs_output_graylog_stream.go
204 lines (189 loc) · 5.3 KB
/
data_dbaas_logs_output_graylog_stream.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package ovh
import (
"fmt"
"log"
"net/url"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceDbaasLogsOutputGraylogStream() *schema.Resource {
return &schema.Resource{
Read: func(d *schema.ResourceData, meta interface{}) error {
return dataSourceDbaasLogsOutputGraylogStreamRead(d, meta)
},
Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Description: "The service name",
Required: true,
},
"title": {
Type: schema.TypeString,
Description: "Stream description",
Required: true,
},
// computed
"can_alert": {
Type: schema.TypeBool,
Description: "Indicates if the current user can create alert on the stream",
Computed: true,
},
"cold_storage_compression": {
Type: schema.TypeString,
Description: "Cold storage compression method",
Computed: true,
},
"cold_storage_content": {
Type: schema.TypeString,
Description: "ColdStorage content",
Computed: true,
},
"cold_storage_enabled": {
Type: schema.TypeBool,
Description: "Is Cold storage enabled?",
Computed: true,
},
"cold_storage_notify_enabled": {
Type: schema.TypeBool,
Description: "Notify on new Cold storage archive",
Computed: true,
},
"cold_storage_retention": {
Type: schema.TypeInt,
Description: "Cold storage retention in year",
Computed: true,
},
"cold_storage_target": {
Type: schema.TypeString,
Description: "ColdStorage destination",
Computed: true,
},
"created_at": {
Type: schema.TypeString,
Description: "Stream creation",
Computed: true,
},
"description": {
Type: schema.TypeString,
Description: "Stream description",
Computed: true,
},
"indexing_enabled": {
Type: schema.TypeBool,
Description: "Enable ES indexing",
Computed: true,
},
"indexing_max_size": {
Type: schema.TypeInt,
Description: "Maximum indexing size (in GB)",
Computed: true,
},
"indexing_notify_enabled": {
Type: schema.TypeBool,
Description: "If set, notify when size is near 80, 90 or 100 % of the maximum configured setting",
Computed: true,
},
"is_editable": {
Type: schema.TypeBool,
Description: "Indicates if you are allowed to edit entry",
Computed: true,
},
"is_shareable": {
Type: schema.TypeBool,
Description: "Indicates if you are allowed to share entry",
Computed: true,
},
"nb_alert_condition": {
Type: schema.TypeInt,
Description: "Number of alert condition",
Computed: true,
},
"nb_archive": {
Type: schema.TypeInt,
Description: "Number of coldstored archives",
Computed: true,
},
"parent_stream_id": {
Type: schema.TypeString,
Description: "Parent stream ID",
Computed: true,
},
"pause_indexing_on_max_size": {
Type: schema.TypeBool,
Description: "If set, pause indexing when maximum size is reach",
Computed: true,
},
"retention_id": {
Type: schema.TypeString,
Description: "Retention ID",
Computed: true,
},
"stream_id": {
Type: schema.TypeString,
Description: "Stream ID",
Computed: true,
},
"updated_at": {
Type: schema.TypeString,
Description: "Stream last update",
Computed: true,
},
"web_socket_enabled": {
Type: schema.TypeBool,
Description: "Enable Websocket",
Computed: true,
},
},
}
}
func dataSourceDbaasLogsOutputGraylogStreamRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
serviceName := d.Get("service_name").(string)
titleFilter := d.Get("title").(string)
log.Printf("[DEBUG] Will read dbaas logs output graylog streams")
res := []string{}
endpoint := fmt.Sprintf(
"/dbaas/logs/%s/output/graylog/stream",
url.PathEscape(serviceName),
)
if err := config.OVHClient.Get(endpoint, &res); err != nil {
return fmt.Errorf("Error calling Get %s:\n\t %q", endpoint, err)
}
streams := []*DbaasLogsOutputGraylogStream{}
for _, id := range res {
log.Printf("[DEBUG] Will read dbaas logs output graylog stream id : %s/%s", serviceName, id)
endpoint := fmt.Sprintf(
"/dbaas/logs/%s/output/graylog/stream/%s",
url.PathEscape(serviceName),
url.PathEscape(id),
)
stream := &DbaasLogsOutputGraylogStream{}
if err := config.OVHClient.Get(endpoint, &stream); err != nil {
return fmt.Errorf("Error calling Get %s:\n\t %q", endpoint, err)
}
log.Printf("[INFO]Comparing : %s ? %s",
strings.ToLower(stream.Title),
strings.ToLower(titleFilter),
)
if strings.ToLower(stream.Title) == strings.ToLower(titleFilter) {
streams = append(streams, stream)
}
}
if len(streams) == 0 {
return fmt.Errorf("Your query returned no results. " +
"Please change your search criteria and try again.")
}
if len(streams) > 1 {
return fmt.Errorf("Your query returned more than one result. " +
"Please change your search criteria and try again.")
}
for k, v := range streams[0].ToMap() {
if k != "stream_id" {
d.Set(k, v)
} else {
d.Set("stream_id", fmt.Sprint(v))
d.SetId(fmt.Sprint(v))
}
}
return nil
}