forked from MD-Creative-Production/Sentinel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenai.provider.ts
More file actions
76 lines (66 loc) · 2.52 KB
/
Copy pathopenai.provider.ts
File metadata and controls
76 lines (66 loc) · 2.52 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
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
import { AIProvider } from './ai-provider.interface';
import { ThreatSummary } from '../interfaces/threat-summary.interface';
export class OpenAIProvider implements AIProvider {
name = 'openai';
constructor(private apiKey: string) {}
async analyzeThreat(event: any): Promise<ThreatSummary> {
// Minimal, efficient implementation: lightweight local heuristic + optional remote call.
// For now provide a deterministic lightweight summary so the framework is usable without network.
const title = event.title || event.alert || 'Security event';
const description = event.description || JSON.stringify(event).slice(0, 200);
// Simple heuristic severity mapping
const severity = this.heuristicSeverity(event);
const score = this.heuristicScore(severity);
return {
title,
description,
severity,
score,
indicators: this.extractIndicators(event),
recommendedActions: this.suggestRemediations(severity),
confidence: 0.5,
raw: event,
};
}
async healthCheck(): Promise<boolean> {
// If API key configured, assume provider can be used; otherwise still usable in local-only mode.
return typeof this.apiKey === 'string' && this.apiKey.length > 0;
}
private heuristicSeverity(event: any): 'low' | 'medium' | 'high' | 'critical' {
const s = (event.severity || '').toString().toLowerCase();
if (s.includes('crit') || s === '4') return 'critical';
if (s.includes('high') || s === '3') return 'high';
if (s.includes('medium') || s === '2') return 'medium';
return 'low';
}
private heuristicScore(sev: string): number {
switch (sev) {
case 'critical':
return 0.95;
case 'high':
return 0.8;
case 'medium':
return 0.5;
default:
return 0.2;
}
}
private extractIndicators(event: any): string[] {
const indicators: string[] = [];
if (event.ip) indicators.push(`ip:${event.ip}`);
if (event.user) indicators.push(`user:${event.user}`);
if (event.filename) indicators.push(`file:${event.filename}`);
return indicators;
}
private suggestRemediations(sev: string): string[] {
if (sev === 'critical')
return [
'Isolate affected hosts',
'Rotate credentials',
'Initiate incident response playbook',
];
if (sev === 'high') return ['Block indicators', 'Notify on-call', 'Collect forensic artifacts'];
if (sev === 'medium') return ['Investigate logs', 'Raise ticket for review'];
return ['Monitor and gather additional context'];
}
}