/
table_azure_stream_analytics_job.go
318 lines (292 loc) · 11 KB
/
table_azure_stream_analytics_job.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
package azure
import (
"context"
"github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/monitor/mgmt/insights"
"github.com/Azure/azure-sdk-for-go/services/streamanalytics/mgmt/2016-03-01/streamanalytics"
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
)
//// TABLE DEFINITION
func tableAzureStreamAnalyticsJob(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "azure_stream_analytics_job",
Description: "Azure Stream Analytics Job",
Get: &plugin.GetConfig{
KeyColumns: plugin.AllColumns([]string{"name", "resource_group"}),
Hydrate: getStreamAnalyticsJob,
IgnoreConfig: &plugin.IgnoreConfig{
ShouldIgnoreErrorFunc: isNotFoundError([]string{"ResourceNotFound", "ResourceGroupNotFound", "Invalid input"}),
},
},
List: &plugin.ListConfig{
Hydrate: listStreamAnalyticsJobs,
},
Columns: azureColumns([]*plugin.Column{
{
Name: "name",
Description: "The resource name.",
Type: proto.ColumnType_STRING,
},
{
Name: "id",
Description: "The resource identifier.",
Type: proto.ColumnType_STRING,
Transform: transform.FromGo(),
},
{
Name: "job_id",
Description: "A GUID uniquely identifying the streaming job.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("StreamingJobProperties.JobID"),
},
{
Name: "job_state",
Description: "Describes the state of the streaming job.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("StreamingJobProperties.JobState"),
},
{
Name: "provisioning_state",
Description: "Describes the provisioning status of the streaming job.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("StreamingJobProperties.ProvisioningState"),
},
{
Name: "type",
Description: "The resource type.",
Type: proto.ColumnType_STRING,
},
{
Name: "compatibility_level",
Description: "Controls certain runtime behaviors of the streaming job.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("StreamingJobProperties.CompatibilityLevel"),
},
{
Name: "created_date",
Description: "Specifies the time when the stream analytics job was created.",
Type: proto.ColumnType_TIMESTAMP,
Transform: transform.FromField("StreamingJobProperties.CreatedDate").Transform(convertDateToTime),
},
{
Name: "data_locale",
Description: "The data locale of the stream analytics job.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("StreamingJobProperties.DataLocale"),
},
{
Name: "etag",
Description: "An unique read-only string that changes whenever the resource is updated.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("StreamingJobProperties.Etag"),
},
{
Name: "events_late_arrival_max_delay_in_seconds",
Description: "The maximum tolerable delay in seconds where events arriving late could be included.",
Type: proto.ColumnType_INT,
Transform: transform.FromField("StreamingJobProperties.EventsLateArrivalMaxDelayInSeconds"),
},
{
Name: "events_out_of_order_max_delay_in_seconds",
Description: "The maximum tolerable delay in seconds where out-of-order events can be adjusted to be back in order.",
Type: proto.ColumnType_INT,
Transform: transform.FromField("StreamingJobProperties.EventsOutOfOrderMaxDelayInSeconds"),
},
{
Name: "events_out_of_order_policy",
Description: "Indicates the policy to apply to events that arrive out of order in the input event stream.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("StreamingJobProperties.EventsOutOfOrderPolicy"),
},
{
Name: "last_output_event_time",
Description: "Indicating the last output event time of the streaming job or null indicating that output has not yet been produced.",
Type: proto.ColumnType_TIMESTAMP,
Transform: transform.FromField("StreamingJobProperties.LastOutputEventTime").Transform(convertDateToTime),
},
{
Name: "output_error_policy",
Description: "Indicates the policy to apply to events that arrive at the output and cannot be written to the external storage due to being malformed (missing column values, column values of wrong type or size).",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("StreamingJobProperties.OutputErrorPolicy"),
},
{
Name: "output_start_mode",
Description: "This property should only be utilized when it is desired that the job be started immediately upon creation.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("StreamingJobProperties.OutputStartMode"),
},
{
Name: "output_start_time",
Description: "Indicates the starting point of the output event stream, or null to indicate that the output event stream will start whenever the streaming job is started.",
Type: proto.ColumnType_TIMESTAMP,
Transform: transform.FromField("StreamingJobProperties.OutputStartTime").Transform(convertDateToTime),
},
{
Name: "sku_name",
Description: "Describes the sku name of the streaming job.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("StreamingJobProperties.Sku.Name"),
},
{
Name: "diagnostic_settings",
Description: "A list of active diagnostic settings for the streaming job.",
Type: proto.ColumnType_JSON,
Hydrate: listStreamAnalyticsJobDiagnosticSettings,
Transform: transform.FromValue(),
},
{
Name: "functions",
Description: "A list of one or more functions for the streaming job.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("StreamingJobProperties.functions"),
},
{
Name: "inputs",
Description: "A list of one or more inputs to the streaming job.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("StreamingJobProperties.Inputs"),
},
{
Name: "outputs",
Description: "A list of one or more outputs for the streaming job.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("StreamingJobProperties.Outputs"),
},
{
Name: "transformation",
Description: "Indicates the query and the number of streaming units to use for the streaming job.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("StreamingJobProperties.Transformation"),
},
// Steampipe standard columns
{
Name: "title",
Description: ColumnDescriptionTitle,
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Name"),
},
{
Name: "tags",
Description: ColumnDescriptionTags,
Type: proto.ColumnType_JSON,
},
{
Name: "akas",
Description: ColumnDescriptionAkas,
Type: proto.ColumnType_JSON,
Transform: transform.FromField("ID").Transform(idToAkas),
},
// Azure standard columns
{
Name: "region",
Description: ColumnDescriptionRegion,
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Location").Transform(formatRegion).Transform(toLower),
},
{
Name: "resource_group",
Description: ColumnDescriptionResourceGroup,
Type: proto.ColumnType_STRING,
Transform: transform.FromField("ID").Transform(extractResourceGroupFromID),
},
}),
}
}
//// LIST FUNCTION
func listStreamAnalyticsJobs(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
return nil, err
}
subscriptionID := session.SubscriptionID
streamingJobsClient := streamanalytics.NewStreamingJobsClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
streamingJobsClient.Authorizer = session.Authorizer
result, err := streamingJobsClient.List(context.Background(), "")
if err != nil {
return nil, err
}
for _, streamingJob := range result.Values() {
d.StreamListItem(ctx, streamingJob)
// Check if context has been cancelled or if the limit has been hit (if specified)
// if there is a limit, it will return the number of rows required to reach this limit
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
for result.NotDone() {
err = result.NextWithContext(ctx)
if err != nil {
return nil, err
}
for _, streamingJob := range result.Values() {
d.StreamListItem(ctx, streamingJob)
// Check if context has been cancelled or if the limit has been hit (if specified)
// if there is a limit, it will return the number of rows required to reach this limit
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
}
return nil, err
}
//// HYDRATE FUNCTIONS
func getStreamAnalyticsJob(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("getStrestreamingJobamAnalyticsJob")
// Create session
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
return nil, err
}
subscriptionID := session.SubscriptionID
streamingJobsClient := streamanalytics.NewStreamingJobsClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
streamingJobsClient.Authorizer = session.Authorizer
name := d.EqualsQuals["name"].GetStringValue()
resourceGroup := d.EqualsQuals["resource_group"].GetStringValue()
// Return nil, if no input provide
if name == "" || resourceGroup == "" {
return nil, nil
}
op, err := streamingJobsClient.Get(ctx, resourceGroup, name, "")
if err != nil {
return nil, err
}
return op, nil
}
func listStreamAnalyticsJobDiagnosticSettings(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("listStreamAnalyticsJobDiagnosticSettings")
id := *h.Item.(streamanalytics.StreamingJob).ID
// Create session
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
return nil, err
}
subscriptionID := session.SubscriptionID
client := insights.NewDiagnosticSettingsClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
client.Authorizer = session.Authorizer
op, err := client.List(ctx, id)
if err != nil {
return nil, err
}
// If we return the API response directly, the output only gives
// the contents of DiagnosticSettings
var diagnosticSettings []map[string]interface{}
for _, i := range *op.Value {
objectMap := make(map[string]interface{})
if i.ID != nil {
objectMap["id"] = i.ID
}
if i.Name != nil {
objectMap["name"] = i.Name
}
if i.Type != nil {
objectMap["type"] = i.Type
}
if i.DiagnosticSettings != nil {
objectMap["properties"] = i.DiagnosticSettings
}
diagnosticSettings = append(diagnosticSettings, objectMap)
}
return diagnosticSettings, nil
}