在現代資安與系統維運中,事件數量已遠超過人力可負荷的範圍。
AI Agent的角色,正是自動完成大量例行分析與初步分類,讓工程師能將時間投入在
決策與防禦策略上。
express
模擬 Suricata / Wazuh 的事件輸出。使用 express
建立一個簡單的 HTTP 伺服器。
import express from "express";
const app = express();
建立 /api/events
路由,回傳模擬的安全事件資料
app.get("/api/events", (req, res) => {
res.json([
{
id: 1,
type: "Suspicious Login",
ip: "203.0.113.55",
location: "Russia",
severity: "high",
desc: "Multiple failed login attempts detected."
},
{
id: 2,
type: "Data Exfiltration",
ip: "198.51.100.42",
location: "USA",
severity: "critical",
desc: "Large outbound data transfer detected."
}
]);
});
啟動在 3000 port,啟動後可在瀏覽器驗證 API。
app.listen(3000, () => console.log("伺服器起動: http://localhost:3000"));
node-fetch
:用來呼叫本地 API。dotenv
:載入 .env
中的金鑰(GEMINI_API_KEY)。GoogleGenerativeAI
:Google 提供的 Gemini SDK。import fetch from "node-fetch";
import dotenv from "dotenv";
import { GoogleGenerativeAI } from "@google/generative-ai";
dotenv.config();
const API_KEY = process.env.GEMINI_API_KEY;
const genAI = new GoogleGenerativeAI(API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-2.5-flash" });
AI Agent 會自動抓取事件資料、生成分析報告