UNPKG

log-analyzer-vibes

Version:

A security log analyzer with prescriptive intelligence

28 lines (22 loc) 704 B
export function analyzeSecurity(logs) { const insights = { totalRequests: logs.length, errors: 0, notFound: 0, suspiciousIPs: [] }; const ipCount = {}; logs.forEach(log => { if (log.line.includes('404')) insights.notFound++; if (log.type === 'error') insights.errors++; const ipMatch = log.line.match(/\b\d{1,3}(\.\d{1,3}){3}\b/); if (ipMatch) { const ip = ipMatch[0]; ipCount[ip] = (ipCount[ip] || 0) + 1; } }); for (const [ip, count] of Object.entries(ipCount)) { if (count > 50) insights.suspiciousIPs.push(ip); } return insights; }