/** * Diagnostics Page * Generate and download Unraid diagnostic reports */ import { useState } from 'react'; import { Alert, Button, Card, Container, Divider, Group, List, Loader, Paper, Progress, Stack, Text, ThemeIcon, Title, } from '@mantine/core'; import { notifications } from '@mantine/notifications'; import { IconBug, IconAlertCircle, IconCheck, IconDownload, IconRefresh, IconCpu, IconDatabase, IconServer, IconNetwork, IconBrandDocker, } from '@tabler/icons-react'; import { GetServerSidePropsContext } from 'next'; import { UnraidLayout } from '~/components/Unraid/Layout'; import { getServerAuthSession } from '~/server/auth'; import { getServerSideTranslations } from '~/tools/server/getServerSideTranslations'; import { checkForSessionOrAskForLogin } from '~/tools/server/loginBuilder'; import { api } from '~/utils/api'; interface DiagnosticCheck { name: string; icon: React.ElementType; status: 'pending' | 'running' | 'success' | 'warning' | 'error'; message?: string; } export default function DiagnosticsPage() { const [isGenerating, setIsGenerating] = useState(false); const [progress, setProgress] = useState(0); const [checks, setChecks] = useState([ { name: 'System Information', icon: IconServer, status: 'pending' }, { name: 'CPU & Memory', icon: IconCpu, status: 'pending' }, { name: 'Array Status', icon: IconDatabase, status: 'pending' }, { name: 'Network Configuration', icon: IconNetwork, status: 'pending' }, { name: 'Docker Containers', icon: IconBrandDocker, status: 'pending' }, ]); const { data: info, isLoading, error, } = api.unraid.info.useQuery(); const { data: array, } = api.unraid.array.useQuery(); const { data: docker, } = api.unraid.docker.useQuery(); const runDiagnostics = async () => { setIsGenerating(true); setProgress(0); // Simulate running diagnostics const steps = checks.length; for (let i = 0; i < steps; i++) { setChecks((prev) => prev.map((check, idx) => idx === i ? { ...check, status: 'running' } : check ) ); await new Promise((resolve) => setTimeout(resolve, 500)); // Simulate random results const statuses: Array<'success' | 'warning' | 'error'> = ['success', 'success', 'success', 'warning']; const status = statuses[Math.floor(Math.random() * statuses.length)]; setChecks((prev) => prev.map((check, idx) => idx === i ? { ...check, status, message: status === 'warning' ? 'Minor issues detected' : status === 'error' ? 'Problems found' : 'All checks passed', } : check ) ); setProgress(((i + 1) / steps) * 100); } setIsGenerating(false); notifications.show({ title: 'Diagnostics Complete', message: 'Diagnostic report has been generated', color: 'green', icon: , }); }; const resetDiagnostics = () => { setProgress(0); setChecks((prev) => prev.map((check) => ({ ...check, status: 'pending', message: undefined, })) ); }; const getStatusColor = (status: DiagnosticCheck['status']) => { switch (status) { case 'success': return 'green'; case 'warning': return 'yellow'; case 'error': return 'red'; case 'running': return 'blue'; default: return 'gray'; } }; if (isLoading) { return ( Loading system information... ); } if (error) { return ( } title="Error" color="red"> {error.message} ); } return ( {/* Header */}
Diagnostics System health checks and diagnostic reports
{/* Progress */} {progress > 0 && ( Diagnostic Progress {Math.round(progress)}% )} {/* Diagnostic Checks */} System Checks {checks.map((check, idx) => (
{check.status === 'running' ? ( ) : ( )}
{check.name} {check.message && ( {check.message} )}
{check.status}
{idx < checks.length - 1 && }
))}
{/* System Summary */} System Summary Unraid Version {info?.versions.unraid || 'Unknown'} Linux Kernel {info?.os.kernel || 'Unknown'} Array Status {array?.state || 'Unknown'} Docker Containers {docker?.containers.filter((c) => c.state === 'RUNNING').length || 0} running /{' '} {docker?.containers.length || 0} total CPU {info?.cpu.brand || 'Unknown'} Total RAM {info?.memory?.total ? `${Math.round(info.memory.total / 1024 / 1024 / 1024)} GB` : 'Unknown'} {/* Download Report */} Diagnostic Report Generate a comprehensive diagnostic report for troubleshooting. This includes system logs, configuration files, and hardware information. System configuration and settings Hardware information (CPU, RAM, disks) Network configuration Docker container status Recent system logs Plugin information
); } export const getServerSideProps = async (context: GetServerSidePropsContext) => { const session = await getServerAuthSession(context); const translations = await getServerSideTranslations( ['common'], context.locale, context.req, context.res ); const result = checkForSessionOrAskForLogin( context, session, () => session?.user != undefined ); if (result) { return result; } return { props: { ...translations, }, }; };