-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathingestionClient.ts
More file actions
43 lines (37 loc) · 1.65 KB
/
ingestionClient.ts
File metadata and controls
43 lines (37 loc) · 1.65 KB
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
import { processEvents } from "./processEvents";
import logger from "./logger";
import { DefaultAzureCredential } from "@azure/identity";
import { isAggregateLogsUploadError, LogsIngestionClient } from "@azure/monitor-ingestion";
export class IngestionClient {
private client: LogsIngestionClient;
private credential: DefaultAzureCredential;
private dceUrl: string;
private dcrRuleId: string;
constructor(dceurl: string, dcrRuleId: string) {
this.dceUrl = dceurl;
this.dcrRuleId = dcrRuleId;
this.credential = new DefaultAzureCredential();
this.client = new LogsIngestionClient(this.dceUrl, this.credential);
}
public async ingest(data: Object[], sourceType: string, sourceIp: string): Promise<void> {
const processedEvents = await processEvents(data, sourceType, sourceIp);
logger.info("Ingesting %d events", processedEvents.length);
if (processedEvents.length === 0) {
logger.warn("No events to ingest");
return;
}
await this.client.upload(this.dcrRuleId, "Custom-RawEventIngestionSentinel", processedEvents, { maxConcurrency: 5 }).then(() =>{
logger.info("Ingested %d logs", processedEvents.length);
}).catch((e) => {
const aggregateErrors = isAggregateLogsUploadError(e) ? e.errors : [];
if (aggregateErrors.length > 0) {
logger.warn("Some logs have failed to complete ingestion");
for (const error of aggregateErrors) {
logger.error(error);
}
} else {
logger.error(e);
}
});
}
}