- Diagnose: add source_filter param threaded through entries_in_window, search, _diagnose, and DiagnoseRequest — clicking diagnose on a dashboard source now scopes both keyword and window hits to that source - QuickCapture: read route.query.source; show scope badge with clear ✕; auto-run when source param is present without a query - DashboardView: pass source= (not q=) when navigating to diagnose - collect_cluster_logs.sh: auto-discover Docker containers on all nodes (Heimdall non-watched, Navi, Strahl via SSH); collect Cass Plex logs via SSH; write to per-node dirs for directory-mode ingest - turnstone-cluster.service: add --reload for hot-reload during dev
286 lines
9.8 KiB
Vue
286 lines
9.8 KiB
Vue
<template>
|
|
<div>
|
|
<!-- Input row -->
|
|
<div class="flex gap-3 mb-6">
|
|
<input
|
|
v-model="query"
|
|
type="text"
|
|
placeholder='e.g. "plex stopped playing audio around 2pm"'
|
|
class="flex-1 bg-surface-raised border border-surface-border rounded px-4 py-2.5 text-sm text-text-primary placeholder-text-dim focus:outline-none focus:border-accent transition-colors"
|
|
@keydown.enter="run()"
|
|
/>
|
|
<button
|
|
:disabled="loading || (!query.trim() && !sourceScope)"
|
|
@click="run()"
|
|
class="px-6 py-2.5 rounded bg-accent text-white text-sm font-semibold hover:bg-blue-400 transition-colors disabled:opacity-50"
|
|
>
|
|
<span v-if="loading">Searching…</span>
|
|
<span v-else>Go</span>
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Source scope badge -->
|
|
<div v-if="sourceScope" class="flex items-center gap-2 mb-4 text-xs">
|
|
<span class="text-text-dim">Scoped to:</span>
|
|
<span class="font-mono text-accent bg-accent/10 border border-accent/20 rounded px-2 py-0.5">{{ sourceScope }}</span>
|
|
<button
|
|
@click="sourceScope = null"
|
|
class="text-text-dim hover:text-text-primary ml-1"
|
|
title="Clear scope"
|
|
>✕</button>
|
|
</div>
|
|
|
|
<!-- Error -->
|
|
<div v-if="error" class="mb-4 p-3 rounded bg-red-900/30 border border-red-700/40 text-sev-error text-sm">
|
|
{{ error }}
|
|
</div>
|
|
|
|
<!-- Summary header -->
|
|
<div v-if="summary" class="mb-4 rounded border border-surface-border bg-surface-raised p-4">
|
|
<div class="flex flex-wrap gap-x-6 gap-y-1 text-xs text-text-dim">
|
|
<span class="text-text-muted font-medium">{{ summary.total }} entr{{ summary.total !== 1 ? 'ies' : 'y' }}</span>
|
|
<span v-if="summary.window_start">
|
|
{{ fmtTs(summary.window_start) }} → {{ fmtTs(summary.window_end) }}
|
|
</span>
|
|
<span v-if="!summary.time_detected" class="italic">(last 60 min — no time detected)</span>
|
|
<span
|
|
v-for="(count, sev) in nonZeroSeverity"
|
|
:key="String(sev)"
|
|
:class="sevClass(String(sev))"
|
|
>{{ count }} {{ sev }}</span>
|
|
</div>
|
|
<div class="flex flex-wrap gap-x-4 gap-y-1 text-xs text-text-dim mt-2">
|
|
<span v-for="(count, src) in summary.by_source" :key="String(src)">
|
|
{{ String(src).split(':').pop() }} ({{ count }})
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- LLM reasoning card -->
|
|
<div
|
|
v-if="reasoning"
|
|
class="mb-4 rounded border border-accent/30 bg-accent/5 p-4"
|
|
>
|
|
<div class="flex items-center gap-2 mb-2 text-xs text-text-dim font-medium uppercase tracking-wide">
|
|
<span>⚡</span>
|
|
<span>Diagnosis</span>
|
|
</div>
|
|
<p class="text-sm text-text-primary leading-relaxed whitespace-pre-wrap">{{ reasoning }}</p>
|
|
</div>
|
|
|
|
<!-- Log stream -->
|
|
<div v-if="entries.length" class="rounded border border-surface-border overflow-hidden mb-4">
|
|
<LogEntryRow v-for="entry in entries" :key="entry.entry_id" :entry="entry" />
|
|
</div>
|
|
|
|
<!-- Zero state -->
|
|
<div v-else-if="ranOnce && !loading" class="text-center text-text-dim py-12">
|
|
<p class="mb-1">No log evidence found for "{{ lastQuery }}"</p>
|
|
<p class="text-sm">Check the Sources tab to confirm data is ingested, or try a broader description.</p>
|
|
</div>
|
|
|
|
<!-- Save CTAs -->
|
|
<div v-if="entries.length && !saved" class="mt-2 flex items-center gap-4">
|
|
<button
|
|
@click="saveQuick"
|
|
:disabled="saving"
|
|
class="px-4 py-2 bg-accent text-surface text-sm rounded font-medium hover:opacity-90 transition-opacity disabled:opacity-40"
|
|
>
|
|
{{ saving ? 'Saving…' : 'Save as incident' }}
|
|
</button>
|
|
<button
|
|
v-if="!showDetails"
|
|
@click="showDetails = true"
|
|
class="text-text-dim hover:text-text-primary text-sm underline underline-offset-2"
|
|
>
|
|
add details…
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Inline details panel -->
|
|
<div v-if="showDetails && !saved" class="mt-4 rounded border border-surface-border bg-surface-raised p-4 space-y-3">
|
|
<div class="flex flex-wrap gap-3">
|
|
<div>
|
|
<label class="block text-xs text-text-dim mb-1">Severity</label>
|
|
<select
|
|
v-model="detailSeverity"
|
|
class="bg-surface border border-surface-border rounded px-3 py-1.5 text-sm text-text-primary focus:outline-none focus:border-accent"
|
|
>
|
|
<option value="low">Low</option>
|
|
<option value="medium">Medium</option>
|
|
<option value="high">High</option>
|
|
<option value="critical">Critical</option>
|
|
</select>
|
|
</div>
|
|
<div class="flex-1 min-w-48">
|
|
<label class="block text-xs text-text-dim mb-1">Notes <span class="text-text-dim">(optional)</span></label>
|
|
<input
|
|
v-model="detailNotes"
|
|
type="text"
|
|
placeholder="Any extra context…"
|
|
class="w-full bg-surface border border-surface-border rounded px-3 py-1.5 text-sm text-text-primary placeholder-text-dim focus:outline-none focus:border-accent"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div class="flex gap-3">
|
|
<button
|
|
@click="saveWithDetails"
|
|
:disabled="saving"
|
|
class="px-4 py-2 bg-accent text-surface text-sm rounded font-medium hover:opacity-90 transition-opacity disabled:opacity-40"
|
|
>
|
|
{{ saving ? 'Saving…' : 'Save' }}
|
|
</button>
|
|
<button @click="showDetails = false" class="text-text-dim hover:text-text-primary text-sm">Cancel</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Saved confirmation -->
|
|
<div v-if="saved" class="mt-2 text-sm text-green-400">
|
|
Saved —
|
|
<RouterLink to="/incidents" class="underline underline-offset-2 hover:text-green-300">view in Incidents</RouterLink>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ref, computed, onMounted, watch } from 'vue'
|
|
import { useRoute, RouterLink } from 'vue-router'
|
|
import LogEntryRow from '@/components/LogEntryRow.vue'
|
|
import type { LogEntry } from '@/stores/search'
|
|
|
|
const BASE = import.meta.env.BASE_URL.replace(/\/$/, '')
|
|
const route = useRoute()
|
|
|
|
interface Summary {
|
|
total: number
|
|
window_start: string | null
|
|
window_end: string | null
|
|
time_detected: boolean
|
|
by_severity: Record<string, number>
|
|
by_source: Record<string, number>
|
|
}
|
|
|
|
const query = ref('')
|
|
const sourceScope = ref<string | null>(null)
|
|
const entries = ref<LogEntry[]>([])
|
|
const summary = ref<Summary | null>(null)
|
|
const reasoning = ref<string | null>(null)
|
|
const loading = ref(false)
|
|
const error = ref<string | null>(null)
|
|
const ranOnce = ref(false)
|
|
const lastQuery = ref('')
|
|
const saved = ref(false)
|
|
const saving = ref(false)
|
|
const showDetails = ref(false)
|
|
const detailSeverity = ref('medium')
|
|
const detailNotes = ref('')
|
|
let capturedSince: string | null = null
|
|
let capturedUntil: string | null = null
|
|
|
|
onMounted(() => {
|
|
const s = route.query.source
|
|
if (typeof s === 'string' && s.trim()) sourceScope.value = s
|
|
const q = route.query.q
|
|
if (typeof q === 'string' && q.trim()) {
|
|
query.value = q
|
|
run()
|
|
} else if (sourceScope.value) {
|
|
run()
|
|
}
|
|
})
|
|
|
|
watch(() => route.query.source, (newS) => {
|
|
sourceScope.value = typeof newS === 'string' && newS.trim() ? newS : null
|
|
})
|
|
|
|
watch(() => route.query.q, (newQ) => {
|
|
if (typeof newQ === 'string' && newQ.trim() && newQ !== lastQuery.value) {
|
|
query.value = newQ
|
|
run()
|
|
}
|
|
})
|
|
|
|
async function run() {
|
|
if (!query.value.trim() && !sourceScope.value) return
|
|
loading.value = true
|
|
error.value = null
|
|
ranOnce.value = true
|
|
lastQuery.value = query.value
|
|
saved.value = false
|
|
showDetails.value = false
|
|
try {
|
|
const res = await fetch(`${BASE}/api/diagnose`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ query: query.value || sourceScope.value, source: sourceScope.value }),
|
|
})
|
|
if (!res.ok) throw new Error(`API returned ${res.status}`)
|
|
const data = await res.json()
|
|
entries.value = data.entries
|
|
summary.value = data.summary
|
|
reasoning.value = data.reasoning ?? null
|
|
capturedSince = data.summary.window_start
|
|
capturedUntil = data.summary.window_end
|
|
} catch (e) {
|
|
error.value = e instanceof Error ? e.message : String(e)
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
async function saveQuick() {
|
|
saving.value = true
|
|
try { await postIncident('medium', '') }
|
|
catch (e) { error.value = e instanceof Error ? e.message : 'Failed to save incident' }
|
|
finally { saving.value = false }
|
|
}
|
|
|
|
async function saveWithDetails() {
|
|
saving.value = true
|
|
try { await postIncident(detailSeverity.value, detailNotes.value) }
|
|
catch (e) { error.value = e instanceof Error ? e.message : 'Failed to save incident' }
|
|
finally { saving.value = false }
|
|
}
|
|
|
|
async function postIncident(severity: string, notes: string) {
|
|
const res = await fetch(`${BASE}/api/incidents`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
label: lastQuery.value,
|
|
started_at: capturedSince,
|
|
ended_at: capturedUntil,
|
|
severity,
|
|
notes,
|
|
}),
|
|
})
|
|
if (!res.ok) throw new Error(await res.text())
|
|
saved.value = true
|
|
showDetails.value = false
|
|
}
|
|
|
|
const nonZeroSeverity = computed(() => {
|
|
if (!summary.value) return {}
|
|
return Object.fromEntries(
|
|
Object.entries(summary.value.by_severity).filter(([, v]) => v > 0)
|
|
)
|
|
})
|
|
|
|
function sevClass(sev: string): string {
|
|
return ({
|
|
CRITICAL: 'text-sev-critical',
|
|
ERROR: 'text-sev-error',
|
|
WARN: 'text-sev-warn',
|
|
INFO: 'text-sev-info',
|
|
} as Record<string, string>)[sev] ?? 'text-text-dim'
|
|
}
|
|
|
|
function fmtTs(iso: string | null): string {
|
|
if (!iso) return '—'
|
|
try {
|
|
return new Date(iso).toLocaleString(undefined, {
|
|
month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit',
|
|
})
|
|
} catch { return iso }
|
|
}
|
|
</script>
|