Skip to content

Commit bbba7fe

Browse files
committed
feat(azure): extract individual records from Azure Event Hub logs
Parse Azure logs with 'records' array structure and send each record as a separate log entry for better indexing and security analysis. Maintains backward compatibility for logs without records array.
1 parent c971157 commit bbba7fe

1 file changed

Lines changed: 46 additions & 15 deletions

File tree

plugins/azure/main.go

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -282,23 +282,54 @@ func processPartition(pc *azeventhubs.ProcessorPartitionClient, groupName string
282282
continue
283283
}
284284

285-
jsonLog, err := json.Marshal(logData)
286-
if err != nil {
287-
_ = catcher.Error("cannot encode log to JSON", err, map[string]any{
288-
"group": groupName,
289-
"partitionID": pc.PartitionID(),
285+
if records, ok := logData["records"].([]any); ok && len(records) > 0 {
286+
for _, record := range records {
287+
recordMap, ok := record.(map[string]any)
288+
if !ok {
289+
_ = catcher.Error("invalid record format in records array", nil, map[string]any{
290+
"group": groupName,
291+
"partitionID": pc.PartitionID(),
292+
})
293+
continue
294+
}
295+
296+
jsonLog, err := json.Marshal(recordMap)
297+
if err != nil {
298+
_ = catcher.Error("cannot encode record to JSON", err, map[string]any{
299+
"group": groupName,
300+
"partitionID": pc.PartitionID(),
301+
})
302+
continue
303+
}
304+
305+
plugins.EnqueueLog(&plugins.Log{
306+
Id: uuid.New().String(),
307+
TenantId: defaultTenant,
308+
DataType: "azure",
309+
DataSource: groupName,
310+
Timestamp: time.Now().UTC().Format(time.RFC3339Nano),
311+
Raw: string(jsonLog),
312+
})
313+
}
314+
} else {
315+
jsonLog, err := json.Marshal(logData)
316+
if err != nil {
317+
_ = catcher.Error("cannot encode log to JSON", err, map[string]any{
318+
"group": groupName,
319+
"partitionID": pc.PartitionID(),
320+
})
321+
continue
322+
}
323+
324+
plugins.EnqueueLog(&plugins.Log{
325+
Id: uuid.New().String(),
326+
TenantId: defaultTenant,
327+
DataType: "azure",
328+
DataSource: groupName,
329+
Timestamp: time.Now().UTC().Format(time.RFC3339Nano),
330+
Raw: string(jsonLog),
290331
})
291-
continue
292332
}
293-
294-
plugins.EnqueueLog(&plugins.Log{
295-
Id: uuid.New().String(),
296-
TenantId: defaultTenant,
297-
DataType: "azure",
298-
DataSource: groupName,
299-
Timestamp: time.Now().UTC().Format(time.RFC3339Nano),
300-
Raw: string(jsonLog),
301-
})
302333
}
303334

304335
if err := pc.UpdateCheckpoint(context.Background(), events[len(events)-1], nil); err != nil {

0 commit comments

Comments
 (0)