mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-11-18 19:46:18 +00:00
Update AppImage
This commit is contained in:
@@ -6,88 +6,165 @@ import { Button } from "./ui/button"
|
|||||||
import { Input } from "./ui/input"
|
import { Input } from "./ui/input"
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select"
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select"
|
||||||
import { ScrollArea } from "./ui/scroll-area"
|
import { ScrollArea } from "./ui/scroll-area"
|
||||||
import { FileText, Search, Download, AlertTriangle, Info, CheckCircle, XCircle } from "lucide-react"
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "./ui/tabs"
|
||||||
import { useState } from "react"
|
import {
|
||||||
|
FileText,
|
||||||
|
Search,
|
||||||
|
Download,
|
||||||
|
AlertTriangle,
|
||||||
|
Info,
|
||||||
|
CheckCircle,
|
||||||
|
XCircle,
|
||||||
|
Database,
|
||||||
|
Activity,
|
||||||
|
HardDrive,
|
||||||
|
Calendar,
|
||||||
|
RefreshCw,
|
||||||
|
} from "lucide-react"
|
||||||
|
import { useState, useEffect } from "react"
|
||||||
|
|
||||||
const systemLogs = [
|
interface Log {
|
||||||
{
|
timestamp: string
|
||||||
timestamp: "2024-01-15 14:32:15",
|
level: string
|
||||||
level: "info",
|
service: string
|
||||||
service: "pveproxy",
|
message: string
|
||||||
message: "User root@pam authenticated successfully",
|
source: string
|
||||||
source: "auth.log",
|
pid?: string
|
||||||
},
|
hostname?: string
|
||||||
{
|
}
|
||||||
timestamp: "2024-01-15 14:31:45",
|
|
||||||
level: "warning",
|
interface Backup {
|
||||||
service: "pvedaemon",
|
volid: string
|
||||||
message: "VM 101 high memory usage detected (85%)",
|
storage: string
|
||||||
source: "syslog",
|
vmid: string | null
|
||||||
},
|
type: string | null
|
||||||
{
|
size: number
|
||||||
timestamp: "2024-01-15 14:30:22",
|
size_human: string
|
||||||
level: "error",
|
created: string
|
||||||
service: "pve-cluster",
|
timestamp: number
|
||||||
message: "Failed to connect to cluster node pve-02",
|
}
|
||||||
source: "cluster.log",
|
|
||||||
},
|
interface Event {
|
||||||
{
|
upid: string
|
||||||
timestamp: "2024-01-15 14:29:18",
|
type: string
|
||||||
level: "info",
|
status: string
|
||||||
service: "pvestatd",
|
level: string
|
||||||
message: "Storage local: 1.25TB used, 750GB available",
|
node: string
|
||||||
source: "syslog",
|
user: string
|
||||||
},
|
vmid: string
|
||||||
{
|
starttime: string
|
||||||
timestamp: "2024-01-15 14:28:33",
|
endtime: string
|
||||||
level: "info",
|
duration: string
|
||||||
service: "pve-firewall",
|
}
|
||||||
message: "Blocked connection attempt from 192.168.1.50",
|
|
||||||
source: "firewall.log",
|
interface SystemLog {
|
||||||
},
|
timestamp: string
|
||||||
{
|
level: string
|
||||||
timestamp: "2024-01-15 14:27:45",
|
service: string
|
||||||
level: "warning",
|
message: string
|
||||||
service: "smartd",
|
source: string
|
||||||
message: "SMART warning: /dev/nvme0n1 temperature high (55°C)",
|
pid?: string
|
||||||
source: "smart.log",
|
hostname?: string
|
||||||
},
|
}
|
||||||
{
|
|
||||||
timestamp: "2024-01-15 14:26:12",
|
|
||||||
level: "info",
|
|
||||||
service: "pveproxy",
|
|
||||||
message: "Started backup job for VM 100",
|
|
||||||
source: "backup.log",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
timestamp: "2024-01-15 14:25:38",
|
|
||||||
level: "error",
|
|
||||||
service: "qemu-server",
|
|
||||||
message: "VM 102 failed to start: insufficient memory",
|
|
||||||
source: "qemu.log",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
timestamp: "2024-01-15 14:24:55",
|
|
||||||
level: "info",
|
|
||||||
service: "pvedaemon",
|
|
||||||
message: "VM 103 migrated successfully to node pve-01",
|
|
||||||
source: "migration.log",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
timestamp: "2024-01-15 14:23:17",
|
|
||||||
level: "warning",
|
|
||||||
service: "pve-ha-lrm",
|
|
||||||
message: "Resource VM:104 state changed to error",
|
|
||||||
source: "ha.log",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
export function SystemLogs() {
|
export function SystemLogs() {
|
||||||
|
const [logs, setLogs] = useState<SystemLog[]>([])
|
||||||
|
const [backups, setBackups] = useState<Backup[]>([])
|
||||||
|
const [events, setEvents] = useState<Event[]>([])
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
|
||||||
const [searchTerm, setSearchTerm] = useState("")
|
const [searchTerm, setSearchTerm] = useState("")
|
||||||
const [levelFilter, setLevelFilter] = useState("all")
|
const [levelFilter, setLevelFilter] = useState("all")
|
||||||
const [serviceFilter, setServiceFilter] = useState("all")
|
const [serviceFilter, setServiceFilter] = useState("all")
|
||||||
|
const [activeTab, setActiveTab] = useState("logs")
|
||||||
|
|
||||||
const filteredLogs = systemLogs.filter((log) => {
|
// Fetch data
|
||||||
|
useEffect(() => {
|
||||||
|
fetchAllData()
|
||||||
|
// Refresh every 30 seconds
|
||||||
|
const interval = setInterval(fetchAllData, 30000)
|
||||||
|
return () => clearInterval(interval)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const fetchAllData = async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true)
|
||||||
|
setError(null)
|
||||||
|
|
||||||
|
// Fetch logs, backups, and events in parallel
|
||||||
|
const [logsRes, backupsRes, eventsRes] = await Promise.all([
|
||||||
|
fetchSystemLogs(),
|
||||||
|
fetch("http://localhost:8008/api/backups"),
|
||||||
|
fetch("http://localhost:8008/api/events?limit=50"),
|
||||||
|
])
|
||||||
|
|
||||||
|
setLogs(logsRes)
|
||||||
|
|
||||||
|
if (backupsRes.ok) {
|
||||||
|
const backupsData = await backupsRes.json()
|
||||||
|
setBackups(backupsData.backups || [])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eventsRes.ok) {
|
||||||
|
const eventsData = await eventsRes.json()
|
||||||
|
setEvents(eventsData.events || [])
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("[v0] Error fetching system logs data:", err)
|
||||||
|
setError("Failed to connect to server")
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchSystemLogs = async (): Promise<SystemLog[]> => {
|
||||||
|
try {
|
||||||
|
const baseUrl =
|
||||||
|
typeof window !== "undefined" ? `${window.location.protocol}//${window.location.hostname}:8008` : ""
|
||||||
|
const apiUrl = `${baseUrl}/api/logs`
|
||||||
|
|
||||||
|
const response = await fetch(apiUrl, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
cache: "no-store",
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Flask server responded with status: ${response.status}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json()
|
||||||
|
return Array.isArray(data) ? data : data.logs || []
|
||||||
|
} catch (error) {
|
||||||
|
console.error("[v0] Failed to fetch system logs:", error)
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleDownloadLogs = async (type = "system") => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`http://localhost:8008/api/logs/download?type=${type}&lines=1000`)
|
||||||
|
if (response.ok) {
|
||||||
|
const blob = await response.blob()
|
||||||
|
const url = window.URL.createObjectURL(blob)
|
||||||
|
const a = document.createElement("a")
|
||||||
|
a.href = url
|
||||||
|
a.download = `proxmox_${type}.log`
|
||||||
|
document.body.appendChild(a)
|
||||||
|
a.click()
|
||||||
|
window.URL.revokeObjectURL(url)
|
||||||
|
document.body.removeChild(a)
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("[v0] Error downloading logs:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter logs
|
||||||
|
const filteredLogs = logs.filter((log) => {
|
||||||
const matchesSearch =
|
const matchesSearch =
|
||||||
log.message.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
log.message.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||||
log.service.toLowerCase().includes(searchTerm.toLowerCase())
|
log.service.toLowerCase().includes(searchTerm.toLowerCase())
|
||||||
@@ -100,10 +177,14 @@ export function SystemLogs() {
|
|||||||
const getLevelColor = (level: string) => {
|
const getLevelColor = (level: string) => {
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case "error":
|
case "error":
|
||||||
|
case "critical":
|
||||||
|
case "emergency":
|
||||||
|
case "alert":
|
||||||
return "bg-red-500/10 text-red-500 border-red-500/20"
|
return "bg-red-500/10 text-red-500 border-red-500/20"
|
||||||
case "warning":
|
case "warning":
|
||||||
return "bg-yellow-500/10 text-yellow-500 border-yellow-500/20"
|
return "bg-yellow-500/10 text-yellow-500 border-yellow-500/20"
|
||||||
case "info":
|
case "info":
|
||||||
|
case "notice":
|
||||||
return "bg-blue-500/10 text-blue-500 border-blue-500/20"
|
return "bg-blue-500/10 text-blue-500 border-blue-500/20"
|
||||||
default:
|
default:
|
||||||
return "bg-gray-500/10 text-gray-500 border-gray-500/20"
|
return "bg-gray-500/10 text-gray-500 border-gray-500/20"
|
||||||
@@ -113,10 +194,14 @@ export function SystemLogs() {
|
|||||||
const getLevelIcon = (level: string) => {
|
const getLevelIcon = (level: string) => {
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case "error":
|
case "error":
|
||||||
|
case "critical":
|
||||||
|
case "emergency":
|
||||||
|
case "alert":
|
||||||
return <XCircle className="h-3 w-3 mr-1" />
|
return <XCircle className="h-3 w-3 mr-1" />
|
||||||
case "warning":
|
case "warning":
|
||||||
return <AlertTriangle className="h-3 w-3 mr-1" />
|
return <AlertTriangle className="h-3 w-3 mr-1" />
|
||||||
case "info":
|
case "info":
|
||||||
|
case "notice":
|
||||||
return <Info className="h-3 w-3 mr-1" />
|
return <Info className="h-3 w-3 mr-1" />
|
||||||
default:
|
default:
|
||||||
return <CheckCircle className="h-3 w-3 mr-1" />
|
return <CheckCircle className="h-3 w-3 mr-1" />
|
||||||
@@ -124,17 +209,41 @@ export function SystemLogs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const logCounts = {
|
const logCounts = {
|
||||||
total: systemLogs.length,
|
total: logs.length,
|
||||||
error: systemLogs.filter((log) => log.level === "error").length,
|
error: logs.filter((log) => ["error", "critical", "emergency", "alert"].includes(log.level)).length,
|
||||||
warning: systemLogs.filter((log) => log.level === "warning").length,
|
warning: logs.filter((log) => log.level === "warning").length,
|
||||||
info: systemLogs.filter((log) => log.level === "info").length,
|
info: logs.filter((log) => ["info", "notice", "debug"].includes(log.level)).length,
|
||||||
}
|
}
|
||||||
|
|
||||||
const uniqueServices = [...new Set(systemLogs.map((log) => log.service))]
|
const uniqueServices = [...new Set(logs.map((log) => log.service))]
|
||||||
|
|
||||||
|
// Calculate backup statistics
|
||||||
|
const backupStats = {
|
||||||
|
total: backups.length,
|
||||||
|
totalSize: backups.reduce((sum, b) => sum + b.size, 0),
|
||||||
|
qemu: backups.filter((b) => b.type === "qemu").length,
|
||||||
|
lxc: backups.filter((b) => b.type === "lxc").length,
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatBytes = (bytes: number) => {
|
||||||
|
if (bytes === 0) return "0 B"
|
||||||
|
const k = 1024
|
||||||
|
const sizes = ["B", "KB", "MB", "GB", "TB"]
|
||||||
|
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||||
|
return `${(bytes / Math.pow(k, i)).toFixed(2)} ${sizes[i]}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loading && logs.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center justify-center h-64">
|
||||||
|
<RefreshCw className="h-8 w-8 animate-spin text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
{/* Log Statistics */}
|
{/* Statistics Cards */}
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
||||||
<Card className="bg-card border-border">
|
<Card className="bg-card border-border">
|
||||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
@@ -143,7 +252,7 @@ export function SystemLogs() {
|
|||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="text-2xl font-bold text-foreground">{logCounts.total}</div>
|
<div className="text-2xl font-bold text-foreground">{logCounts.total}</div>
|
||||||
<p className="text-xs text-muted-foreground mt-2">Last 24 hours</p>
|
<p className="text-xs text-muted-foreground mt-2">Last 200 entries</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
@@ -171,26 +280,41 @@ export function SystemLogs() {
|
|||||||
|
|
||||||
<Card className="bg-card border-border">
|
<Card className="bg-card border-border">
|
||||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
<CardTitle className="text-sm font-medium text-muted-foreground">Info</CardTitle>
|
<CardTitle className="text-sm font-medium text-muted-foreground">Backups</CardTitle>
|
||||||
<Info className="h-4 w-4 text-blue-500" />
|
<Database className="h-4 w-4 text-blue-500" />
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="text-2xl font-bold text-blue-500">{logCounts.info}</div>
|
<div className="text-2xl font-bold text-blue-500">{backupStats.total}</div>
|
||||||
<p className="text-xs text-muted-foreground mt-2">Normal operations</p>
|
<p className="text-xs text-muted-foreground mt-2">{formatBytes(backupStats.totalSize)}</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Log Filters and Search */}
|
{/* Main Content with Tabs */}
|
||||||
<Card className="bg-card border-border">
|
<Card className="bg-card border-border">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
<CardTitle className="text-foreground flex items-center">
|
<CardTitle className="text-foreground flex items-center">
|
||||||
<FileText className="h-5 w-5 mr-2" />
|
<Activity className="h-5 w-5 mr-2" />
|
||||||
System Logs
|
System Logs & Events
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
|
<Button variant="outline" size="sm" onClick={fetchAllData} disabled={loading}>
|
||||||
|
<RefreshCw className={`h-4 w-4 mr-2 ${loading ? "animate-spin" : ""}`} />
|
||||||
|
Refresh
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="flex flex-col sm:flex-row gap-4 mb-6">
|
<Tabs value={activeTab} onValueChange={setActiveTab}>
|
||||||
|
<TabsList className="grid w-full grid-cols-3">
|
||||||
|
<TabsTrigger value="logs">System Logs</TabsTrigger>
|
||||||
|
<TabsTrigger value="events">Recent Events</TabsTrigger>
|
||||||
|
<TabsTrigger value="backups">Backups</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
|
||||||
|
{/* System Logs Tab */}
|
||||||
|
<TabsContent value="logs" className="space-y-4">
|
||||||
|
<div className="flex flex-col sm:flex-row gap-4">
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
||||||
@@ -221,7 +345,7 @@ export function SystemLogs() {
|
|||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="all">All Services</SelectItem>
|
<SelectItem value="all">All Services</SelectItem>
|
||||||
{uniqueServices.map((service) => (
|
{uniqueServices.slice(0, 20).map((service) => (
|
||||||
<SelectItem key={service} value={service}>
|
<SelectItem key={service} value={service}>
|
||||||
{service}
|
{service}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
@@ -229,7 +353,11 @@ export function SystemLogs() {
|
|||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
|
||||||
<Button variant="outline" className="border-border bg-transparent">
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className="border-border bg-transparent"
|
||||||
|
onClick={() => handleDownloadLogs("system")}
|
||||||
|
>
|
||||||
<Download className="h-4 w-4 mr-2" />
|
<Download className="h-4 w-4 mr-2" />
|
||||||
Export
|
Export
|
||||||
</Button>
|
</Button>
|
||||||
@@ -240,7 +368,7 @@ export function SystemLogs() {
|
|||||||
{filteredLogs.map((log, index) => (
|
{filteredLogs.map((log, index) => (
|
||||||
<div
|
<div
|
||||||
key={index}
|
key={index}
|
||||||
className="flex items-start space-x-4 p-3 rounded-lg bg-card/50 border border-border/50"
|
className="flex items-start space-x-4 p-3 rounded-lg bg-card/50 border border-border/50 hover:bg-card/80 transition-colors"
|
||||||
>
|
>
|
||||||
<div className="flex-shrink-0">
|
<div className="flex-shrink-0">
|
||||||
<Badge variant="outline" className={getLevelColor(log.level)}>
|
<Badge variant="outline" className={getLevelColor(log.level)}>
|
||||||
@@ -255,7 +383,11 @@ export function SystemLogs() {
|
|||||||
<div className="text-xs text-muted-foreground font-mono">{log.timestamp}</div>
|
<div className="text-xs text-muted-foreground font-mono">{log.timestamp}</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="text-sm text-foreground mb-1">{log.message}</div>
|
<div className="text-sm text-foreground mb-1">{log.message}</div>
|
||||||
<div className="text-xs text-muted-foreground">Source: {log.source}</div>
|
<div className="text-xs text-muted-foreground">
|
||||||
|
Source: {log.source}
|
||||||
|
{log.pid && ` • PID: ${log.pid}`}
|
||||||
|
{log.hostname && ` • Host: ${log.hostname}`}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
@@ -268,6 +400,115 @@ export function SystemLogs() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
|
</TabsContent>
|
||||||
|
|
||||||
|
{/* Recent Events Tab */}
|
||||||
|
<TabsContent value="events" className="space-y-4">
|
||||||
|
<ScrollArea className="h-[600px] w-full rounded-md border border-border">
|
||||||
|
<div className="space-y-2 p-4">
|
||||||
|
{events.map((event, index) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className="flex items-start space-x-4 p-3 rounded-lg bg-card/50 border border-border/50 hover:bg-card/80 transition-colors"
|
||||||
|
>
|
||||||
|
<div className="flex-shrink-0">
|
||||||
|
<Badge variant="outline" className={getLevelColor(event.level)}>
|
||||||
|
{getLevelIcon(event.level)}
|
||||||
|
{event.status}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
<div className="flex items-center justify-between mb-1">
|
||||||
|
<div className="text-sm font-medium text-foreground">
|
||||||
|
{event.type}
|
||||||
|
{event.vmid && ` (VM/CT ${event.vmid})`}
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-muted-foreground">{event.duration}</div>
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-muted-foreground">
|
||||||
|
Node: {event.node} • User: {event.user}
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-muted-foreground mt-1">
|
||||||
|
Started: {event.starttime} • Ended: {event.endtime}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
|
||||||
|
{events.length === 0 && (
|
||||||
|
<div className="text-center py-8 text-muted-foreground">
|
||||||
|
<Activity className="h-12 w-12 mx-auto mb-4 opacity-50" />
|
||||||
|
<p>No recent events found</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</ScrollArea>
|
||||||
|
</TabsContent>
|
||||||
|
|
||||||
|
{/* Backups Tab */}
|
||||||
|
<TabsContent value="backups" className="space-y-4">
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 mb-4">
|
||||||
|
<Card className="bg-card/50 border-border">
|
||||||
|
<CardContent className="pt-6">
|
||||||
|
<div className="text-2xl font-bold text-foreground">{backupStats.qemu}</div>
|
||||||
|
<p className="text-xs text-muted-foreground mt-1">QEMU Backups</p>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
<Card className="bg-card/50 border-border">
|
||||||
|
<CardContent className="pt-6">
|
||||||
|
<div className="text-2xl font-bold text-foreground">{backupStats.lxc}</div>
|
||||||
|
<p className="text-xs text-muted-foreground mt-1">LXC Backups</p>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
<Card className="bg-card/50 border-border">
|
||||||
|
<CardContent className="pt-6">
|
||||||
|
<div className="text-2xl font-bold text-foreground">{formatBytes(backupStats.totalSize)}</div>
|
||||||
|
<p className="text-xs text-muted-foreground mt-1">Total Size</p>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ScrollArea className="h-[500px] w-full rounded-md border border-border">
|
||||||
|
<div className="space-y-2 p-4">
|
||||||
|
{backups.map((backup, index) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className="flex items-start space-x-4 p-3 rounded-lg bg-card/50 border border-border/50 hover:bg-card/80 transition-colors"
|
||||||
|
>
|
||||||
|
<div className="flex-shrink-0">
|
||||||
|
<HardDrive className="h-5 w-5 text-blue-500" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
<div className="flex items-center justify-between mb-1">
|
||||||
|
<div className="text-sm font-medium text-foreground">
|
||||||
|
{backup.type?.toUpperCase()} {backup.vmid && `VM ${backup.vmid}`}
|
||||||
|
</div>
|
||||||
|
<Badge variant="outline" className="bg-blue-500/10 text-blue-500 border-blue-500/20">
|
||||||
|
{backup.size_human}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-muted-foreground mb-1">Storage: {backup.storage}</div>
|
||||||
|
<div className="text-xs text-muted-foreground flex items-center">
|
||||||
|
<Calendar className="h-3 w-3 mr-1" />
|
||||||
|
{backup.created}
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-muted-foreground mt-1 font-mono truncate">{backup.volid}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
|
||||||
|
{backups.length === 0 && (
|
||||||
|
<div className="text-center py-8 text-muted-foreground">
|
||||||
|
<Database className="h-12 w-12 mx-auto mb-4 opacity-50" />
|
||||||
|
<p>No backups found</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</ScrollArea>
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -19,10 +19,24 @@ import re # Added for regex matching
|
|||||||
import select # Added for non-blocking read
|
import select # Added for non-blocking read
|
||||||
import shutil # Added for shutil.which
|
import shutil # Added for shutil.which
|
||||||
import xml.etree.ElementTree as ET # Added for XML parsing
|
import xml.etree.ElementTree as ET # Added for XML parsing
|
||||||
|
import math # Imported math for format_bytes function
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
CORS(app) # Enable CORS for Next.js frontend
|
CORS(app) # Enable CORS for Next.js frontend
|
||||||
|
|
||||||
|
# Helper function to format bytes into human-readable string
|
||||||
|
def format_bytes(size_in_bytes):
|
||||||
|
"""Converts bytes to a human-readable string (KB, MB, GB, TB)."""
|
||||||
|
if size_in_bytes is None:
|
||||||
|
return "N/A"
|
||||||
|
if size_in_bytes == 0:
|
||||||
|
return "0 B"
|
||||||
|
size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
|
||||||
|
i = int(math.floor(math.log(size_in_bytes, 1024)))
|
||||||
|
p = math.pow(1024, i)
|
||||||
|
s = round(size_in_bytes / p, 2)
|
||||||
|
return f"{s} {size_name[i]}"
|
||||||
|
|
||||||
# AGREGANDO FUNCIÓN PARA PARSEAR PROCESOS DE INTEL_GPU_TOP (SIN -J)
|
# AGREGANDO FUNCIÓN PARA PARSEAR PROCESOS DE INTEL_GPU_TOP (SIN -J)
|
||||||
def get_intel_gpu_processes_from_text():
|
def get_intel_gpu_processes_from_text():
|
||||||
"""Parse processes from intel_gpu_top text output (more reliable than JSON)"""
|
"""Parse processes from intel_gpu_top text output (more reliable than JSON)"""
|
||||||
@@ -989,11 +1003,6 @@ def get_proxmox_storage():
|
|||||||
storage_list = []
|
storage_list = []
|
||||||
lines = result.stdout.strip().split('\n')
|
lines = result.stdout.strip().split('\n')
|
||||||
|
|
||||||
# Skip header line
|
|
||||||
if len(lines) < 2:
|
|
||||||
print("[v0] No storage found in pvesm output")
|
|
||||||
return {'storage': []}
|
|
||||||
|
|
||||||
# Parse each storage line
|
# Parse each storage line
|
||||||
for line in lines[1:]: # Skip header
|
for line in lines[1:]: # Skip header
|
||||||
parts = line.split()
|
parts = line.split()
|
||||||
@@ -3300,9 +3309,21 @@ def api_vms():
|
|||||||
def api_logs():
|
def api_logs():
|
||||||
"""Get system logs"""
|
"""Get system logs"""
|
||||||
try:
|
try:
|
||||||
# Get recent system logs
|
limit = request.args.get('limit', '200')
|
||||||
result = subprocess.run(['journalctl', '-n', '100', '--output', 'json'],
|
priority = request.args.get('priority', None) # 0-7 (0=emerg, 3=err, 4=warning, 6=info)
|
||||||
capture_output=True, text=True, timeout=10)
|
service = request.args.get('service', None)
|
||||||
|
|
||||||
|
cmd = ['journalctl', '-n', limit, '--output', 'json', '--no-pager']
|
||||||
|
|
||||||
|
# Add priority filter if specified
|
||||||
|
if priority:
|
||||||
|
cmd.extend(['-p', priority])
|
||||||
|
|
||||||
|
# Add service filter if specified
|
||||||
|
if service:
|
||||||
|
cmd.extend(['-u', service])
|
||||||
|
|
||||||
|
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
|
||||||
|
|
||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
logs = []
|
logs = []
|
||||||
@@ -3310,26 +3331,193 @@ def api_logs():
|
|||||||
if line:
|
if line:
|
||||||
try:
|
try:
|
||||||
log_entry = json.loads(line)
|
log_entry = json.loads(line)
|
||||||
|
# Convert timestamp from microseconds to readable format
|
||||||
|
timestamp_us = int(log_entry.get('__REALTIME_TIMESTAMP', '0'))
|
||||||
|
timestamp = datetime.fromtimestamp(timestamp_us / 1000000).strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
|
# Map priority to level name
|
||||||
|
priority_map = {
|
||||||
|
'0': 'emergency', '1': 'alert', '2': 'critical', '3': 'error',
|
||||||
|
'4': 'warning', '5': 'notice', '6': 'info', '7': 'debug'
|
||||||
|
}
|
||||||
|
priority_num = str(log_entry.get('PRIORITY', '6'))
|
||||||
|
level = priority_map.get(priority_num, 'info')
|
||||||
|
|
||||||
logs.append({
|
logs.append({
|
||||||
'timestamp': log_entry.get('__REALTIME_TIMESTAMP', ''),
|
'timestamp': timestamp,
|
||||||
'level': log_entry.get('PRIORITY', '6'),
|
'level': level,
|
||||||
'service': log_entry.get('_SYSTEMD_UNIT', 'system'),
|
'service': log_entry.get('_SYSTEMD_UNIT', log_entry.get('SYSLOG_IDENTIFIER', 'system')),
|
||||||
'message': log_entry.get('MESSAGE', ''),
|
'message': log_entry.get('MESSAGE', ''),
|
||||||
'source': 'journalctl'
|
'source': 'journalctl',
|
||||||
|
'pid': log_entry.get('_PID', ''),
|
||||||
|
'hostname': log_entry.get('_HOSTNAME', '')
|
||||||
})
|
})
|
||||||
except json.JSONDecodeError:
|
except (json.JSONDecodeError, ValueError) as e:
|
||||||
continue
|
continue
|
||||||
return jsonify(logs)
|
return jsonify({'logs': logs, 'total': len(logs)})
|
||||||
else:
|
else:
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'error': 'journalctl not available or failed',
|
'error': 'journalctl not available or failed',
|
||||||
'logs': []
|
'logs': [],
|
||||||
|
'total': 0
|
||||||
})
|
})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error getting logs: {e}")
|
print(f"Error getting logs: {e}")
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'error': f'Unable to access system logs: {str(e)}',
|
'error': f'Unable to access system logs: {str(e)}',
|
||||||
'logs': []
|
'logs': [],
|
||||||
|
'total': 0
|
||||||
|
})
|
||||||
|
|
||||||
|
@app.route('/api/logs/download', methods=['GET'])
|
||||||
|
def api_logs_download():
|
||||||
|
"""Download system logs as a text file"""
|
||||||
|
try:
|
||||||
|
log_type = request.args.get('type', 'system') # system, kernel, auth
|
||||||
|
lines = request.args.get('lines', '1000')
|
||||||
|
|
||||||
|
if log_type == 'kernel':
|
||||||
|
cmd = ['journalctl', '-k', '-n', lines, '--no-pager']
|
||||||
|
filename = 'kernel.log'
|
||||||
|
elif log_type == 'auth':
|
||||||
|
cmd = ['journalctl', '-u', 'ssh', '-u', 'sshd', '-n', lines, '--no-pager']
|
||||||
|
filename = 'auth.log'
|
||||||
|
else:
|
||||||
|
cmd = ['journalctl', '-n', lines, '--no-pager']
|
||||||
|
filename = 'system.log'
|
||||||
|
|
||||||
|
result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
|
||||||
|
|
||||||
|
if result.returncode == 0:
|
||||||
|
# Create a temporary file
|
||||||
|
import tempfile
|
||||||
|
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.log') as f:
|
||||||
|
f.write(result.stdout)
|
||||||
|
temp_path = f.name
|
||||||
|
|
||||||
|
return send_file(
|
||||||
|
temp_path,
|
||||||
|
mimetype='text/plain',
|
||||||
|
as_attachment=True,
|
||||||
|
download_name=f'proxmox_{filename}'
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return jsonify({'error': 'Failed to generate log file'}), 500
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error downloading logs: {e}")
|
||||||
|
return jsonify({'error': str(e)}), 500
|
||||||
|
|
||||||
|
@app.route('/api/notifications', methods=['GET'])
|
||||||
|
def api_notifications():
|
||||||
|
"""Get Proxmox notification history"""
|
||||||
|
try:
|
||||||
|
notifications = []
|
||||||
|
|
||||||
|
# 1. Get notifications from journalctl (Proxmox notification service)
|
||||||
|
try:
|
||||||
|
cmd = [
|
||||||
|
'journalctl',
|
||||||
|
'-u', 'pve-ha-lrm',
|
||||||
|
'-u', 'pve-ha-crm',
|
||||||
|
'-u', 'pvedaemon',
|
||||||
|
'-u', 'pveproxy',
|
||||||
|
'-u', 'pvestatd',
|
||||||
|
'--grep', 'notification|email|webhook|alert|notify',
|
||||||
|
'-n', '100',
|
||||||
|
'--output', 'json',
|
||||||
|
'--no-pager'
|
||||||
|
]
|
||||||
|
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
|
||||||
|
|
||||||
|
if result.returncode == 0:
|
||||||
|
for line in result.stdout.strip().split('\n'):
|
||||||
|
if line:
|
||||||
|
try:
|
||||||
|
log_entry = json.loads(line)
|
||||||
|
timestamp_us = int(log_entry.get('__REALTIME_TIMESTAMP', '0'))
|
||||||
|
timestamp = datetime.fromtimestamp(timestamp_us / 1000000).strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
|
message = log_entry.get('MESSAGE', '')
|
||||||
|
|
||||||
|
# Determine notification type from message
|
||||||
|
notif_type = 'info'
|
||||||
|
if 'email' in message.lower():
|
||||||
|
notif_type = 'email'
|
||||||
|
elif 'webhook' in message.lower():
|
||||||
|
notif_type = 'webhook'
|
||||||
|
elif 'alert' in message.lower() or 'warning' in message.lower():
|
||||||
|
notif_type = 'alert'
|
||||||
|
elif 'error' in message.lower() or 'fail' in message.lower():
|
||||||
|
notif_type = 'error'
|
||||||
|
|
||||||
|
notifications.append({
|
||||||
|
'timestamp': timestamp,
|
||||||
|
'type': notif_type,
|
||||||
|
'service': log_entry.get('_SYSTEMD_UNIT', 'proxmox'),
|
||||||
|
'message': message,
|
||||||
|
'source': 'journal'
|
||||||
|
})
|
||||||
|
except (json.JSONDecodeError, ValueError):
|
||||||
|
continue
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error reading notification logs: {e}")
|
||||||
|
|
||||||
|
# 2. Try to read Proxmox notification configuration
|
||||||
|
try:
|
||||||
|
notif_config_path = '/etc/pve/notifications.cfg'
|
||||||
|
if os.path.exists(notif_config_path):
|
||||||
|
with open(notif_config_path, 'r') as f:
|
||||||
|
config_content = f.read()
|
||||||
|
# Parse notification targets (emails, webhooks, etc.)
|
||||||
|
for line in config_content.split('\n'):
|
||||||
|
if line.strip() and not line.startswith('#'):
|
||||||
|
notifications.append({
|
||||||
|
'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
||||||
|
'type': 'config',
|
||||||
|
'service': 'notification-config',
|
||||||
|
'message': f'Notification target configured: {line.strip()}',
|
||||||
|
'source': 'config'
|
||||||
|
})
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error reading notification config: {e}")
|
||||||
|
|
||||||
|
# 3. Get backup notifications from task log
|
||||||
|
try:
|
||||||
|
cmd = ['pvesh', 'get', '/cluster/tasks', '--output-format', 'json']
|
||||||
|
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
|
||||||
|
|
||||||
|
if result.returncode == 0:
|
||||||
|
tasks = json.loads(result.stdout)
|
||||||
|
for task in tasks:
|
||||||
|
if task.get('type') in ['vzdump', 'backup']:
|
||||||
|
status = task.get('status', 'unknown')
|
||||||
|
notif_type = 'success' if status == 'OK' else 'error' if status == 'stopped' else 'info'
|
||||||
|
|
||||||
|
notifications.append({
|
||||||
|
'timestamp': datetime.fromtimestamp(task.get('starttime', 0)).strftime('%Y-%m-%d %H:%M:%S'),
|
||||||
|
'type': notif_type,
|
||||||
|
'service': 'backup',
|
||||||
|
'message': f"Backup task {task.get('upid', 'unknown')}: {status}",
|
||||||
|
'source': 'task-log'
|
||||||
|
})
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error reading task notifications: {e}")
|
||||||
|
|
||||||
|
# Sort by timestamp (newest first)
|
||||||
|
notifications.sort(key=lambda x: x['timestamp'], reverse=True)
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'notifications': notifications[:100], # Limit to 100 most recent
|
||||||
|
'total': len(notifications)
|
||||||
|
})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error getting notifications: {e}")
|
||||||
|
return jsonify({
|
||||||
|
'error': str(e),
|
||||||
|
'notifications': [],
|
||||||
|
'total': 0
|
||||||
})
|
})
|
||||||
|
|
||||||
@app.route('/api/health', methods=['GET'])
|
@app.route('/api/health', methods=['GET'])
|
||||||
@@ -3408,7 +3596,10 @@ def api_info():
|
|||||||
'/api/logs',
|
'/api/logs',
|
||||||
'/api/health',
|
'/api/health',
|
||||||
'/api/hardware',
|
'/api/hardware',
|
||||||
'/api/gpu/<slot>/realtime' # Added endpoint for GPU monitoring
|
'/api/gpu/<slot>/realtime', # Added endpoint for GPU monitoring
|
||||||
|
'/api/backups', # Added backup endpoint
|
||||||
|
'/api/events', # Added events endpoint
|
||||||
|
'/api/notifications' # Added notifications endpoint
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user