feat: adiciona informacoes de reinicio e melhora SLA global
All checks were successful
All checks were successful
- Agente Rust: captura LastBootTime, uptime e contagem de boots - Backend: extrai campos do extended (bootInfo, discos, RAM, etc) antes de salvar - Frontend /devices: exibe secao de ultimo reinicio - SLA global: adiciona campos de modo, threshold de alerta e status de pausa - Corrige acento em "destinatario" -> "destinatario" em automations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
d32b94c22d
commit
f39bd46c2b
7 changed files with 338 additions and 19 deletions
|
|
@ -331,9 +331,59 @@ async function getMachineLastHeartbeat(
|
|||
return hb?.lastHeartbeatAt ?? fallback ?? null
|
||||
}
|
||||
|
||||
// Campos do inventory que sao muito grandes e nao devem ser persistidos
|
||||
// para evitar OOM no Convex (documentos de ~100KB cada)
|
||||
const INVENTORY_BLOCKLIST = new Set(["software", "extended"])
|
||||
// Campo software é muito grande e é tratado separadamente via machineSoftware
|
||||
|
||||
// Extrai campos importantes do extended antes de bloqueá-lo
|
||||
function extractFromExtended(extended: unknown): JsonRecord {
|
||||
const result: JsonRecord = {}
|
||||
const sanitizedExtended = sanitizeRecord(extended)
|
||||
if (!sanitizedExtended) return result
|
||||
|
||||
// Extrair dados do Windows
|
||||
const windows = sanitizeRecord(sanitizedExtended["windows"])
|
||||
if (windows) {
|
||||
const windowsFields: JsonRecord = {}
|
||||
// bootInfo - informacoes de reinicio
|
||||
if (windows["bootInfo"]) {
|
||||
windowsFields["bootInfo"] = windows["bootInfo"] as JsonValue
|
||||
}
|
||||
// osInfo - informacoes do sistema operacional
|
||||
if (windows["osInfo"]) {
|
||||
windowsFields["osInfo"] = windows["osInfo"] as JsonValue
|
||||
}
|
||||
// cpu, baseboard, bios, memoryModules, videoControllers, disks
|
||||
for (const key of ["cpu", "baseboard", "bios", "memoryModules", "videoControllers", "disks", "bitLocker", "tpm", "secureBoot", "deviceGuard", "firewallProfiles", "windowsUpdate", "computerSystem", "azureAdStatus", "battery", "thermal", "networkAdapters", "monitors", "chassis", "defender", "hotfix"]) {
|
||||
if (windows[key]) {
|
||||
windowsFields[key] = windows[key] as JsonValue
|
||||
}
|
||||
}
|
||||
if (Object.keys(windowsFields).length > 0) {
|
||||
result["windows"] = windowsFields
|
||||
}
|
||||
}
|
||||
|
||||
// Extrair dados do Linux
|
||||
const linux = sanitizeRecord(sanitizedExtended["linux"])
|
||||
if (linux) {
|
||||
const linuxFields: JsonRecord = {}
|
||||
for (const key of ["lsblk", "smart", "lspci", "lsusb", "dmidecode"]) {
|
||||
if (linux[key]) {
|
||||
linuxFields[key] = linux[key] as JsonValue
|
||||
}
|
||||
}
|
||||
if (Object.keys(linuxFields).length > 0) {
|
||||
result["linux"] = linuxFields
|
||||
}
|
||||
}
|
||||
|
||||
// Extrair dados do macOS
|
||||
const macos = sanitizeRecord(sanitizedExtended["macos"])
|
||||
if (macos) {
|
||||
result["macos"] = macos as JsonValue
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
function mergeInventory(current: JsonRecord | null | undefined, patch: Record<string, unknown>): JsonRecord {
|
||||
const sanitizedPatch = sanitizeRecord(patch)
|
||||
|
|
@ -341,9 +391,10 @@ function mergeInventory(current: JsonRecord | null | undefined, patch: Record<st
|
|||
return current ? { ...current } : {}
|
||||
}
|
||||
const base: JsonRecord = current ? { ...current } : {}
|
||||
|
||||
for (const [key, value] of Object.entries(sanitizedPatch)) {
|
||||
// Filtrar campos volumosos que causam OOM
|
||||
if (INVENTORY_BLOCKLIST.has(key)) continue
|
||||
// Filtrar software (extended já foi processado em sanitizeInventoryPayload)
|
||||
if (key === "software") continue
|
||||
if (value === undefined) continue
|
||||
if (isObject(value) && isObject(base[key])) {
|
||||
base[key] = mergeInventory(base[key] as JsonRecord, value as Record<string, unknown>)
|
||||
|
|
@ -393,9 +444,20 @@ function ensureString(value: unknown): string | null {
|
|||
function sanitizeInventoryPayload(value: unknown): JsonRecord | null {
|
||||
const record = sanitizeRecord(value)
|
||||
if (!record) return null
|
||||
for (const blocked of INVENTORY_BLOCKLIST) {
|
||||
delete record[blocked]
|
||||
|
||||
// Extrair campos importantes do extended antes de deletá-lo
|
||||
if (record["extended"]) {
|
||||
const extractedExtended = extractFromExtended(record["extended"])
|
||||
if (Object.keys(extractedExtended).length > 0) {
|
||||
record["extended"] = extractedExtended
|
||||
} else {
|
||||
delete record["extended"]
|
||||
}
|
||||
}
|
||||
|
||||
// Deletar apenas software (extended já foi processado acima)
|
||||
delete record["software"]
|
||||
|
||||
return record
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -200,7 +200,11 @@ export default defineSchema({
|
|||
name: v.string(),
|
||||
description: v.optional(v.string()),
|
||||
timeToFirstResponse: v.optional(v.number()), // minutes
|
||||
responseMode: v.optional(v.string()), // "business" | "calendar"
|
||||
timeToResolution: v.optional(v.number()), // minutes
|
||||
solutionMode: v.optional(v.string()), // "business" | "calendar"
|
||||
alertThreshold: v.optional(v.number()), // 0.1 a 0.95
|
||||
pauseStatuses: v.optional(v.array(v.string())), // Status que pausam SLA
|
||||
}).index("by_tenant_name", ["tenantId", "name"]),
|
||||
|
||||
tickets: defineTable({
|
||||
|
|
|
|||
|
|
@ -9,6 +9,26 @@ function normalizeName(value: string) {
|
|||
return value.trim();
|
||||
}
|
||||
|
||||
function normalizeMode(value?: string): "business" | "calendar" {
|
||||
if (value === "business") return "business";
|
||||
return "calendar";
|
||||
}
|
||||
|
||||
function normalizeThreshold(value?: number): number {
|
||||
if (value === undefined || value === null) return 0.8;
|
||||
if (value < 0.1) return 0.1;
|
||||
if (value > 0.95) return 0.95;
|
||||
return value;
|
||||
}
|
||||
|
||||
const VALID_PAUSE_STATUSES = ["PAUSED", "PENDING", "AWAITING_ATTENDANCE"] as const;
|
||||
|
||||
function normalizePauseStatuses(statuses?: string[]): string[] {
|
||||
if (!statuses || statuses.length === 0) return ["PAUSED"];
|
||||
const filtered = statuses.filter((s) => VALID_PAUSE_STATUSES.includes(s as typeof VALID_PAUSE_STATUSES[number]));
|
||||
return filtered.length > 0 ? filtered : ["PAUSED"];
|
||||
}
|
||||
|
||||
type AnyCtx = QueryCtx | MutationCtx;
|
||||
|
||||
async function ensureUniqueName(ctx: AnyCtx, tenantId: string, name: string, excludeId?: Id<"slaPolicies">) {
|
||||
|
|
@ -35,7 +55,11 @@ export const list = query({
|
|||
name: policy.name,
|
||||
description: policy.description ?? "",
|
||||
timeToFirstResponse: policy.timeToFirstResponse ?? null,
|
||||
responseMode: policy.responseMode ?? "calendar",
|
||||
timeToResolution: policy.timeToResolution ?? null,
|
||||
solutionMode: policy.solutionMode ?? "calendar",
|
||||
alertThreshold: policy.alertThreshold ?? 0.8,
|
||||
pauseStatuses: policy.pauseStatuses ?? ["PAUSED"],
|
||||
}));
|
||||
},
|
||||
});
|
||||
|
|
@ -47,9 +71,14 @@ export const create = mutation({
|
|||
name: v.string(),
|
||||
description: v.optional(v.string()),
|
||||
timeToFirstResponse: v.optional(v.number()),
|
||||
responseMode: v.optional(v.string()),
|
||||
timeToResolution: v.optional(v.number()),
|
||||
solutionMode: v.optional(v.string()),
|
||||
alertThreshold: v.optional(v.number()),
|
||||
pauseStatuses: v.optional(v.array(v.string())),
|
||||
},
|
||||
handler: async (ctx, { tenantId, actorId, name, description, timeToFirstResponse, timeToResolution }) => {
|
||||
handler: async (ctx, args) => {
|
||||
const { tenantId, actorId, name, description, timeToFirstResponse, responseMode, timeToResolution, solutionMode, alertThreshold, pauseStatuses } = args;
|
||||
await requireAdmin(ctx, actorId, tenantId);
|
||||
const trimmed = normalizeName(name);
|
||||
if (trimmed.length < 2) {
|
||||
|
|
@ -68,7 +97,11 @@ export const create = mutation({
|
|||
name: trimmed,
|
||||
description,
|
||||
timeToFirstResponse,
|
||||
responseMode: normalizeMode(responseMode),
|
||||
timeToResolution,
|
||||
solutionMode: normalizeMode(solutionMode),
|
||||
alertThreshold: normalizeThreshold(alertThreshold),
|
||||
pauseStatuses: normalizePauseStatuses(pauseStatuses),
|
||||
});
|
||||
return id;
|
||||
},
|
||||
|
|
@ -82,9 +115,14 @@ export const update = mutation({
|
|||
name: v.string(),
|
||||
description: v.optional(v.string()),
|
||||
timeToFirstResponse: v.optional(v.number()),
|
||||
responseMode: v.optional(v.string()),
|
||||
timeToResolution: v.optional(v.number()),
|
||||
solutionMode: v.optional(v.string()),
|
||||
alertThreshold: v.optional(v.number()),
|
||||
pauseStatuses: v.optional(v.array(v.string())),
|
||||
},
|
||||
handler: async (ctx, { policyId, tenantId, actorId, name, description, timeToFirstResponse, timeToResolution }) => {
|
||||
handler: async (ctx, args) => {
|
||||
const { policyId, tenantId, actorId, name, description, timeToFirstResponse, responseMode, timeToResolution, solutionMode, alertThreshold, pauseStatuses } = args;
|
||||
await requireAdmin(ctx, actorId, tenantId);
|
||||
const policy = await ctx.db.get(policyId);
|
||||
if (!policy || policy.tenantId !== tenantId) {
|
||||
|
|
@ -106,7 +144,11 @@ export const update = mutation({
|
|||
name: trimmed,
|
||||
description,
|
||||
timeToFirstResponse,
|
||||
responseMode: normalizeMode(responseMode),
|
||||
timeToResolution,
|
||||
solutionMode: normalizeMode(solutionMode),
|
||||
alertThreshold: normalizeThreshold(alertThreshold),
|
||||
pauseStatuses: normalizePauseStatuses(pauseStatuses),
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue