// LOGPile Frontend Application
document.addEventListener('DOMContentLoaded', () => {
initSourceType();
initApiSource();
initUpload();
initTabs();
initFilters();
loadParsersInfo();
});
let sourceType = 'archive';
let apiConnectPayload = null;
let collectionJob = null;
let collectionJobPollTimer = null;
let collectionJobLogCounter = 0;
let apiPortTouchedByUser = false;
let isAutoUpdatingApiPort = false;
function initSourceType() {
const sourceButtons = document.querySelectorAll('.source-switch-btn');
sourceButtons.forEach(button => {
button.addEventListener('click', () => {
setSourceType(button.dataset.sourceType);
});
});
setSourceType(sourceType);
}
function setSourceType(nextType) {
sourceType = nextType === 'api' ? 'api' : 'archive';
document.querySelectorAll('.source-switch-btn').forEach(button => {
button.classList.toggle('active', button.dataset.sourceType === sourceType);
});
const archiveContent = document.getElementById('archive-source-content');
const apiSourceContent = document.getElementById('api-source-content');
archiveContent.classList.toggle('hidden', sourceType !== 'archive');
apiSourceContent.classList.toggle('hidden', sourceType !== 'api');
}
function initApiSource() {
const apiForm = document.getElementById('api-connect-form');
if (!apiForm) {
return;
}
const cancelJobButton = document.getElementById('cancel-job-btn');
const fieldNames = ['host', 'port', 'username', 'password'];
apiForm.addEventListener('submit', (event) => {
event.preventDefault();
const { isValid, payload, errors } = validateCollectForm();
renderFormErrors(errors);
if (!isValid) {
renderApiConnectStatus(false, null);
apiConnectPayload = null;
return;
}
apiConnectPayload = payload;
renderApiConnectStatus(true, payload);
startCollectionJob(payload);
});
if (cancelJobButton) {
cancelJobButton.addEventListener('click', () => {
cancelCollectionJob();
});
}
fieldNames.forEach((fieldName) => {
const field = apiForm.elements.namedItem(fieldName);
if (!field) {
return;
}
const eventName = field.tagName.toLowerCase() === 'select' ? 'change' : 'input';
field.addEventListener(eventName, () => {
if (fieldName === 'port') {
handleApiPortInput(field.value);
}
const { errors } = validateCollectForm();
renderFormErrors(errors);
clearApiConnectStatus();
if (collectionJob && isCollectionJobTerminal(collectionJob.status)) {
resetCollectionJobState();
}
});
});
applyRedfishDefaultPort();
renderCollectionJob();
}
function validateCollectForm() {
const host = getApiValue('host');
const portRaw = getApiValue('port');
const username = getApiValue('username');
const password = getApiValue('password');
const errors = {};
if (!host) {
errors.host = 'Укажите host.';
}
const port = Number(portRaw);
const isPortInteger = Number.isInteger(port);
if (!portRaw) {
errors.port = 'Укажите порт.';
} else if (!isPortInteger || port < 1 || port > 65535) {
errors.port = 'Порт должен быть от 1 до 65535.';
}
if (!username) {
errors.username = 'Укажите username.';
}
if (!password) {
errors.password = 'Введите пароль.';
}
if (Object.keys(errors).length > 0) {
return { isValid: false, errors, payload: null };
}
// TODO: UI для выбора протокола вернем, когда откроем IPMI коннектор.
const payload = {
host,
protocol: 'redfish',
port,
username,
auth_type: 'password',
tls_mode: 'insecure',
password
};
return { isValid: true, errors: {}, payload };
}
function renderFormErrors(errors) {
const apiForm = document.getElementById('api-connect-form');
const summary = document.getElementById('api-form-errors');
if (!apiForm || !summary) {
return;
}
const errorFields = ['host', 'port', 'username', 'password'];
errorFields.forEach((fieldName) => {
const errorNode = apiForm.querySelector(`[data-error-for="${fieldName}"]`);
if (!errorNode) {
return;
}
const fieldWrapper = errorNode.closest('.api-form-field');
const message = errors[fieldName] || '';
errorNode.textContent = message;
if (fieldWrapper) {
fieldWrapper.classList.toggle('has-error', Boolean(message));
}
});
const messages = Object.values(errors);
if (messages.length === 0) {
summary.innerHTML = '';
summary.classList.add('hidden');
return;
}
summary.classList.remove('hidden');
summary.innerHTML = `Исправьте ошибки в форме:
${messages.map(msg => `- ${escapeHtml(msg)}
`).join('')}
`;
}
function renderApiConnectStatus(isValid, payload) {
const status = document.getElementById('api-connect-status');
if (!status) {
return;
}
if (!isValid) {
status.textContent = 'Форма не отправлена: есть ошибки.';
status.className = 'api-connect-status error';
return;
}
const payloadPreview = { ...payload };
if (payloadPreview.password) {
payloadPreview.password = '***';
}
if (payloadPreview.token) {
payloadPreview.token = '***';
}
status.textContent = `Payload сформирован: ${JSON.stringify(payloadPreview)}`;
status.className = 'api-connect-status success';
}
function clearApiConnectStatus() {
const status = document.getElementById('api-connect-status');
if (!status) {
return;
}
status.textContent = '';
status.className = 'api-connect-status';
}
function startCollectionJob(payload) {
resetCollectionJobState();
setApiFormBlocked(true);
fetch('/api/collect', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
})
.then(async (response) => {
const body = await response.json().catch(() => ({}));
if (!response.ok) {
throw new Error(body.error || 'Не удалось запустить задачу');
}
collectionJob = {
id: body.job_id,
status: normalizeJobStatus(body.status || 'queued'),
progress: 0,
logs: [],
payload
};
appendJobLog(body.message || 'Задача поставлена в очередь');
renderCollectionJob();
collectionJobPollTimer = window.setInterval(() => {
pollCollectionJobStatus();
}, 1200);
})
.catch((err) => {
setApiFormBlocked(false);
clearApiConnectStatus();
renderApiConnectStatus(false, null);
const status = document.getElementById('api-connect-status');
if (status) {
status.textContent = err.message || 'Ошибка запуска задачи';
status.className = 'api-connect-status error';
}
});
}
function pollCollectionJobStatus() {
if (!collectionJob || isCollectionJobTerminal(collectionJob.status)) {
clearCollectionJobPolling();
return;
}
fetch(`/api/collect/${encodeURIComponent(collectionJob.id)}`)
.then(async (response) => {
const body = await response.json().catch(() => ({}));
if (!response.ok) {
throw new Error(body.error || 'Не удалось получить статус задачи');
}
const prevStatus = collectionJob.status;
collectionJob.status = normalizeJobStatus(body.status || collectionJob.status);
collectionJob.progress = Number.isFinite(body.progress) ? body.progress : collectionJob.progress;
collectionJob.error = body.error || '';
syncServerLogs(body.logs);
renderCollectionJob();
if (isCollectionJobTerminal(collectionJob.status)) {
clearCollectionJobPolling();
if (collectionJob.status === 'success') {
loadDataFromStatus();
} else if (collectionJob.status === 'failed' && collectionJob.error) {
appendJobLog(`Ошибка: ${collectionJob.error}`);
renderCollectionJob();
}
} else if (prevStatus !== collectionJob.status && collectionJob.status === 'running') {
appendJobLog('Сбор выполняется...');
renderCollectionJob();
}
})
.catch((err) => {
appendJobLog(`Ошибка статуса: ${err.message}`);
renderCollectionJob();
clearCollectionJobPolling();
setApiFormBlocked(false);
});
}
function cancelCollectionJob() {
if (!collectionJob || isCollectionJobTerminal(collectionJob.status)) {
return;
}
fetch(`/api/collect/${encodeURIComponent(collectionJob.id)}/cancel`, {
method: 'POST'
})
.then(async (response) => {
const body = await response.json().catch(() => ({}));
if (!response.ok) {
throw new Error(body.error || 'Не удалось отменить задачу');
}
collectionJob.status = normalizeJobStatus(body.status || 'canceled');
collectionJob.progress = Number.isFinite(body.progress) ? body.progress : collectionJob.progress;
syncServerLogs(body.logs);
clearCollectionJobPolling();
renderCollectionJob();
})
.catch((err) => {
appendJobLog(`Ошибка отмены: ${err.message}`);
renderCollectionJob();
});
}
function appendJobLog(message) {
if (!collectionJob) {
return;
}
const time = new Date().toLocaleTimeString('ru-RU', { hour12: false });
collectionJob.logs.push({
id: ++collectionJobLogCounter,
time,
message
});
}
function renderCollectionJob() {
const jobStatusBlock = document.getElementById('api-job-status');
const jobIdValue = document.getElementById('job-id-value');
const statusValue = document.getElementById('job-status-value');
const progressValue = document.getElementById('job-progress-value');
const logsList = document.getElementById('job-logs-list');
const cancelButton = document.getElementById('cancel-job-btn');
if (!jobStatusBlock || !jobIdValue || !statusValue || !progressValue || !logsList || !cancelButton) {
return;
}
if (!collectionJob) {
jobStatusBlock.classList.add('hidden');
setApiFormBlocked(false);
return;
}
jobStatusBlock.classList.remove('hidden');
jobIdValue.textContent = collectionJob.id;
statusValue.textContent = collectionJob.status;
statusValue.className = `job-status-badge status-${collectionJob.status.toLowerCase()}`;
const isTerminal = isCollectionJobTerminal(collectionJob.status);
const terminalMessage = {
success: 'Сбор завершен',
failed: 'Сбор завершился ошибкой',
canceled: 'Сбор отменен'
}[collectionJob.status];
const progressLabel = isTerminal
? terminalMessage
: 'Сбор данных...';
progressValue.textContent = `${collectionJob.progress}% · ${progressLabel}`;
logsList.innerHTML = collectionJob.logs.map((log) => (
`${escapeHtml(log.time)}${escapeHtml(log.message)}`
)).join('');
cancelButton.disabled = isTerminal;
setApiFormBlocked(!isTerminal);
}
function isCollectionJobTerminal(status) {
return ['success', 'failed', 'canceled'].includes(normalizeJobStatus(status));
}
function setApiFormBlocked(shouldBlock) {
const apiForm = document.getElementById('api-connect-form');
if (!apiForm) {
return;
}
apiForm.classList.toggle('is-disabled', shouldBlock);
Array.from(apiForm.elements).forEach((field) => {
field.disabled = shouldBlock;
});
}
function clearCollectionJobPolling() {
if (!collectionJobPollTimer) {
return;
}
window.clearInterval(collectionJobPollTimer);
collectionJobPollTimer = null;
}
function resetCollectionJobState() {
clearCollectionJobPolling();
collectionJob = null;
renderCollectionJob();
}
function syncServerLogs(logs) {
if (!collectionJob || !Array.isArray(logs)) {
return;
}
if (logs.length <= collectionJob.logs.length) {
return;
}
const from = collectionJob.logs.length;
for (let i = from; i < logs.length; i += 1) {
appendJobLog(logs[i]);
}
}
function normalizeJobStatus(status) {
return String(status || '').trim().toLowerCase();
}
async function loadDataFromStatus() {
try {
const response = await fetch('/api/status');
const payload = await response.json();
if (!payload.loaded) {
return;
}
const vendor = payload.vendor || payload.protocol || '';
const filename = payload.filename || (payload.protocol && payload.target_host
? `${payload.protocol}://${payload.target_host}`
: '');
await loadData(vendor, filename);
} catch (err) {
console.error('Failed to load data after collect:', err);
}
}
function applyRedfishDefaultPort() {
const apiForm = document.getElementById('api-connect-form');
if (!apiForm) {
return;
}
const portField = apiForm.elements.namedItem('port');
if (!portField || typeof portField.value !== 'string') {
return;
}
const currentValue = portField.value.trim();
if (apiPortTouchedByUser && currentValue !== '') {
return;
}
isAutoUpdatingApiPort = true;
portField.value = '443';
isAutoUpdatingApiPort = false;
}
function handleApiPortInput(value) {
if (isAutoUpdatingApiPort) {
return;
}
apiPortTouchedByUser = value.trim() !== '';
}
function getApiValue(fieldName) {
const apiForm = document.getElementById('api-connect-form');
if (!apiForm) {
return '';
}
const field = apiForm.elements.namedItem(fieldName);
if (!field || typeof field.value !== 'string') {
return '';
}
return field.value.trim();
}
// Load and display available parsers
async function loadParsersInfo() {
try {
const response = await fetch('/api/parsers');
const data = await response.json();
const container = document.getElementById('parsers-info');
if (data.parsers && data.parsers.length > 0) {
let html = 'Поддерживаемые платформы:
';
data.parsers.forEach(p => {
html += `
${escapeHtml(p.name)}
v${escapeHtml(p.version)}
`;
});
html += '
';
container.innerHTML = html;
}
} catch (err) {
console.error('Failed to load parsers info:', err);
}
}
// Upload handling
function initUpload() {
const dropZone = document.getElementById('drop-zone');
const fileInput = document.getElementById('file-input');
dropZone.addEventListener('dragover', (e) => {
e.preventDefault();
dropZone.classList.add('dragover');
});
dropZone.addEventListener('dragleave', () => {
dropZone.classList.remove('dragover');
});
dropZone.addEventListener('drop', (e) => {
e.preventDefault();
dropZone.classList.remove('dragover');
const files = e.dataTransfer.files;
if (files.length > 0) {
uploadFile(files[0]);
}
});
fileInput.addEventListener('change', () => {
if (fileInput.files.length > 0) {
uploadFile(fileInput.files[0]);
}
});
}
async function uploadFile(file) {
const status = document.getElementById('upload-status');
status.textContent = 'Загрузка и анализ...';
status.className = '';
const formData = new FormData();
formData.append('archive', file);
try {
const response = await fetch('/api/upload', {
method: 'POST',
body: formData
});
const result = await response.json();
if (response.ok) {
status.innerHTML = `${escapeHtml(result.vendor)}
` +
`${result.stats.sensors} сенсоров, ${result.stats.fru} компонентов, ${result.stats.events} событий`;
status.className = 'success';
loadData(result.vendor, result.filename);
} else {
status.textContent = result.error || 'Ошибка загрузки';
status.className = 'error';
}
} catch (err) {
status.textContent = 'Ошибка соединения';
status.className = 'error';
}
}
// Tab navigation
function initTabs() {
const tabs = document.querySelectorAll('.tab');
tabs.forEach(tab => {
tab.addEventListener('click', () => {
tabs.forEach(t => t.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
tab.classList.add('active');
document.getElementById(tab.dataset.tab).classList.add('active');
});
});
}
// Filters
function initFilters() {
document.getElementById('sensor-filter').addEventListener('change', (e) => {
filterSensors(e.target.value);
});
document.getElementById('severity-filter').addEventListener('change', (e) => {
filterEvents(e.target.value);
});
document.getElementById('serial-filter').addEventListener('change', (e) => {
filterSerials(e.target.value);
});
}
let allSensors = [];
let allEvents = [];
let allSerials = [];
let currentVendor = '';
// Load data from API
async function loadData(vendor, filename) {
currentVendor = vendor || '';
document.getElementById('upload-section').classList.add('hidden');
document.getElementById('data-section').classList.remove('hidden');
document.getElementById('clear-btn').classList.remove('hidden');
// Update parser name and filename
const parserName = document.getElementById('parser-name');
const fileNameElem = document.getElementById('file-name');
if (parserName && currentVendor) {
parserName.textContent = currentVendor;
}
if (fileNameElem && filename) {
fileNameElem.textContent = filename;
}
// Update vendor badge if exists (legacy support)
const vendorBadge = document.getElementById('vendor-badge');
if (vendorBadge && currentVendor) {
vendorBadge.textContent = currentVendor;
vendorBadge.classList.remove('hidden');
}
await Promise.all([
loadConfig(),
loadFirmware(),
loadSensors(),
loadSerials(),
loadEvents()
]);
}
async function loadConfig() {
try {
const response = await fetch('/api/config');
const config = await response.json();
renderConfig(config);
} catch (err) {
console.error('Failed to load config:', err);
}
}
function renderConfig(data) {
const container = document.getElementById('config-content');
if (!data || Object.keys(data).length === 0) {
container.innerHTML = 'Нет данных о конфигурации
';
return;
}
const config = data.hardware || data;
const spec = data.specification;
let html = '';
// Server info header
if (config.board) {
html += `
Модель сервера: ${escapeHtml(config.board.product_name || '-')}
Серийный номер: ${escapeHtml(config.board.serial_number || '-')}
`;
}
// Configuration sub-tabs
html += `
`;
// Specification tab
html += '';
if (spec && spec.length > 0) {
html += '
Спецификация сервера
';
spec.forEach(item => {
html += `- ${escapeHtml(item.category)} ${escapeHtml(item.name)} - ${item.quantity} шт.
`;
});
html += '
';
} else {
html += '
Нет данных о спецификации
';
}
html += '
';
// CPU tab
html += '';
if (config.cpus && config.cpus.length > 0) {
const cpuCount = config.cpus.length;
const cpuModel = config.cpus[0].model || '-';
const totalCores = config.cpus.reduce((sum, c) => sum + (c.cores || 0), 0);
const totalThreads = config.cpus.reduce((sum, c) => sum + (c.threads || 0), 0);
html += `
Процессоры
${cpuCount}Процессоров
${totalCores}Ядер
${totalThreads}Потоков
${escapeHtml(cpuModel)}Модель
| Socket | Модель | Ядра | Потоки | Частота | Max Turbo | TDP | L3 Cache | PPIN |
`;
config.cpus.forEach(cpu => {
html += `
| CPU${cpu.socket} |
${escapeHtml(cpu.model)} |
${cpu.cores} |
${cpu.threads} |
${cpu.frequency_mhz} MHz |
${cpu.max_frequency_mhz} MHz |
${cpu.tdp_w}W |
${Math.round(cpu.l3_cache_kb/1024)} MB |
${escapeHtml(cpu.ppin || '-')} |
`;
});
html += '
';
} else {
html += '
Нет данных о процессорах
';
}
html += '
';
// Memory tab
html += '';
if (config.memory && config.memory.length > 0) {
const totalGB = config.memory.reduce((sum, m) => sum + m.size_mb, 0) / 1024;
const presentCount = config.memory.filter(m => m.present !== false).length;
const workingCount = config.memory.filter(m => m.size_mb > 0).length;
html += `
Модули памяти
${totalGB} GBВсего
${presentCount}Установлено
${workingCount}Активно
| Location | Наличие | Размер | Тип | Max частота | Текущая частота | Производитель | Артикул | Статус |
`;
config.memory.forEach(mem => {
const present = mem.present !== false ? '✓' : '-';
const presentClass = mem.present !== false ? 'present-yes' : 'present-no';
const sizeGB = mem.size_mb / 1024;
const statusClass = (mem.status === 'OK' || !mem.status) ? '' : 'status-warning';
const rowClass = sizeGB === 0 ? 'row-warning' : '';
html += `
| ${escapeHtml(mem.location || mem.slot)} |
${present} |
${sizeGB} GB |
${escapeHtml(mem.type || '-')} |
${mem.max_speed_mhz || '-'} MHz |
${mem.current_speed_mhz || mem.speed_mhz || '-'} MHz |
${escapeHtml(mem.manufacturer || '-')} |
${escapeHtml(mem.part_number || '-')} |
${escapeHtml(mem.status || 'OK')} |
`;
});
html += '
';
} else {
html += '
Нет данных о памяти
';
}
html += '
';
// Power tab
html += '';
if (config.power_supplies && config.power_supplies.length > 0) {
const psuTotal = config.power_supplies.length;
const psuPresent = config.power_supplies.filter(p => p.present !== false).length;
const psuOK = config.power_supplies.filter(p => p.status === 'OK').length;
const psuModel = config.power_supplies[0].model || '-';
const psuWattage = config.power_supplies[0].wattage_w || 0;
html += `
Блоки питания
${psuTotal}Всего
${psuPresent}Подключено
${psuOK}Работает
${psuWattage}WМощность
${escapeHtml(psuModel)}Модель
| Слот | Производитель | Модель | Мощность | Вход | Выход | Напряжение | Температура | Статус |
`;
config.power_supplies.forEach(psu => {
const statusClass = psu.status === 'OK' ? '' : 'status-warning';
html += `
| ${escapeHtml(psu.slot)} |
${escapeHtml(psu.vendor || '-')} |
${escapeHtml(psu.model || '-')} |
${psu.wattage_w || '-'}W |
${psu.input_power_w || '-'}W |
${psu.output_power_w || '-'}W |
${psu.input_voltage ? psu.input_voltage.toFixed(0) : '-'}V |
${psu.temperature_c || '-'}°C |
${escapeHtml(psu.status || '-')} |
`;
});
html += '
';
} else {
html += '
Нет данных о блоках питания
';
}
html += '
';
// Storage tab
html += '';
if (config.storage && config.storage.length > 0) {
const storTotal = config.storage.length;
const storHDD = config.storage.filter(s => s.type === 'HDD').length;
const storSSD = config.storage.filter(s => s.type === 'SSD').length;
const storNVMe = config.storage.filter(s => s.type === 'NVMe').length;
const totalTB = (config.storage.reduce((sum, s) => sum + (s.size_gb || 0), 0) / 1000).toFixed(1);
let typesSummary = [];
if (storHDD > 0) typesSummary.push(`${storHDD} HDD`);
if (storSSD > 0) typesSummary.push(`${storSSD} SSD`);
if (storNVMe > 0) typesSummary.push(`${storNVMe} NVMe`);
html += `
Накопители
${storTotal}Всего слотов
${config.storage.filter(s => s.present).length}Установлено
${totalTB > 0 ? totalTB + ' TB' : '-'}Объём
${typesSummary.join(', ') || '-'}По типам
| NO. | Статус | Расположение | Backplane ID | Тип | Модель | Размер | Серийный номер |
`;
config.storage.forEach(s => {
const presentIcon = s.present ? '●' : '○';
const presentText = s.present ? 'Present' : 'Empty';
html += `
| ${escapeHtml(s.slot || '-')} |
${presentIcon} ${presentText} |
${escapeHtml(s.location || '-')} |
${s.backplane_id !== undefined ? s.backplane_id : '-'} |
${escapeHtml(s.type || '-')} |
${escapeHtml(s.model || '-')} |
${s.size_gb > 0 ? s.size_gb + ' GB' : '-'} |
${s.serial_number ? '' + escapeHtml(s.serial_number) + '' : '-'} |
`;
});
html += '
';
} else {
html += '
Нет данных о накопителях
';
}
html += '
';
// GPU tab
html += '';
const gpuRows = (config.gpus && config.gpus.length > 0)
? config.gpus
: (config.pcie_devices || [])
.filter((p) => {
const cls = String(p.device_class || '').toLowerCase();
const mfr = String(p.manufacturer || '').toLowerCase();
return cls.includes('gpu') || cls.includes('display') || cls.includes('3d') || mfr.includes('nvidia') || p.vendor_id === 0x10de;
})
.map((p) => ({
slot: p.slot,
model: p.part_number || p.device_class,
manufacturer: p.manufacturer,
bdf: p.bdf,
serial_number: p.serial_number,
current_link_width: p.link_width,
current_link_speed: p.link_speed,
max_link_width: p.max_link_width,
max_link_speed: p.max_link_speed
}));
if (gpuRows.length > 0) {
const gpuCount = gpuRows.length;
const gpuModel = gpuRows[0].model || '-';
const gpuVendor = gpuRows[0].manufacturer || '-';
html += `
Графические процессоры
${gpuCount}Всего GPU
${escapeHtml(gpuVendor)}Производитель
${escapeHtml(gpuModel)}Модель
| Слот | Модель | Производитель | BDF | PCIe | Серийный номер |
`;
gpuRows.forEach(gpu => {
const pcieLink = formatPCIeLink(
gpu.current_link_width || gpu.link_width,
gpu.current_link_speed || gpu.link_speed,
gpu.max_link_width,
gpu.max_link_speed
);
html += `
| ${escapeHtml(gpu.slot || '-')} |
${escapeHtml(gpu.model || '-')} |
${escapeHtml(gpu.manufacturer || '-')} |
${escapeHtml(gpu.bdf || '-')} |
${pcieLink} |
${escapeHtml(gpu.serial_number || '-')} |
`;
});
html += '
';
} else {
html += '
Нет GPU
';
}
html += '
';
// Network tab
html += '';
const networkRows = (config.network_adapters && config.network_adapters.length > 0)
? config.network_adapters
: (config.pcie_devices || [])
.filter((p) => {
const cls = String(p.device_class || '').toLowerCase();
return cls.includes('network') || cls.includes('ethernet') || cls.includes('gigabit');
})
.map((p) => ({
location: p.slot,
model: p.part_number || p.device_class,
vendor: p.manufacturer,
port_count: 0,
port_type: '',
mac_addresses: p.mac_addresses || [],
status: p.status || ''
}));
if (networkRows.length > 0) {
const nicCount = networkRows.length;
const totalPorts = networkRows.reduce((sum, n) => sum + (n.port_count || 0), 0);
const nicTypes = [...new Set(networkRows.map(n => n.port_type).filter(t => t))];
const nicModels = [...new Set(networkRows.map(n => n.model).filter(m => m))];
html += `
Сетевые адаптеры
${nicCount}Адаптеров
${totalPorts}Портов
${nicTypes.join(', ') || '-'}Тип портов
${escapeHtml(nicModels.join(', ') || '-')}Модели
| Слот | Модель | Производитель | Порты | Тип | MAC адреса | Статус |
`;
networkRows.forEach(nic => {
const macs = nic.mac_addresses ? nic.mac_addresses.join(', ') : '-';
const statusClass = nic.status === 'OK' ? '' : 'status-warning';
html += `
| ${escapeHtml(nic.location || nic.slot || '-')} |
${escapeHtml(nic.model || '-')} |
${escapeHtml(nic.vendor || '-')} |
${nic.port_count || '-'} |
${escapeHtml(nic.port_type || '-')} |
${escapeHtml(macs)} |
${escapeHtml(nic.status || '-')} |
`;
});
html += '
';
} else {
html += '
Нет данных о сетевых адаптерах
';
}
html += '
';
// PCIe Device Inventory tab
html += '';
const hasPCIe = config.pcie_devices && config.pcie_devices.length > 0;
const hasGPUs = config.gpus && config.gpus.length > 0;
if (hasPCIe || hasGPUs) {
html += '
PCIe устройства
| Слот | BDF | Модель | Производитель | Vendor:Device ID | PCIe Link | Серийный номер | Прошивка |
';
const pcieRowKey = (slot, bdf, vendorId, deviceId) => {
const normalizedBDF = (bdf || '').trim().toLowerCase();
if (normalizedBDF) return `bdf:${normalizedBDF}`;
const normalizedSlot = (slot || '').trim().toLowerCase();
if (normalizedSlot) return `slot:${normalizedSlot}`;
return `id:${vendorId || 0}:${deviceId || 0}`;
};
const gpuByKey = new Map();
(config.gpus || []).forEach(gpu => {
gpuByKey.set(pcieRowKey(gpu.slot, gpu.bdf, gpu.vendor_id, gpu.device_id), gpu);
});
(config.pcie_devices || []).forEach(p => {
const key = pcieRowKey(p.slot, p.bdf, p.vendor_id, p.device_id);
const matchedGPU = gpuByKey.get(key);
const pcieLink = formatPCIeLink(
p.link_width,
p.link_speed,
p.max_link_width,
p.max_link_speed
);
const serial = p.serial_number || (matchedGPU ? matchedGPU.serial_number : '');
const firmware = p.firmware || (matchedGPU ? matchedGPU.firmware : '') || findPCIeFirmwareVersion(config.firmware, p);
html += `
| ${escapeHtml(p.slot || '-')} |
${escapeHtml(p.bdf || '-')} |
${escapeHtml(p.part_number || '-')} |
${escapeHtml(p.manufacturer || '-')} |
${p.vendor_id ? p.vendor_id.toString(16) : '-'}:${p.device_id ? p.device_id.toString(16) : '-'} |
${pcieLink} |
${escapeHtml(serial || '-')} |
${escapeHtml(firmware || '-')} |
`;
});
(config.gpus || []).forEach(gpu => {
const pcieLink = formatPCIeLink(
gpu.current_link_width || gpu.link_width,
gpu.current_link_speed || gpu.link_speed,
gpu.max_link_width,
gpu.max_link_speed
);
html += `
| ${escapeHtml(gpu.slot || '-')} |
${escapeHtml(gpu.bdf || '-')} |
${escapeHtml(gpu.model || gpu.part_number || '-')} |
${escapeHtml(gpu.manufacturer || '-')} |
${gpu.vendor_id ? gpu.vendor_id.toString(16) : '-'}:${gpu.device_id ? gpu.device_id.toString(16) : '-'} |
${pcieLink} |
${escapeHtml(gpu.serial_number || '-')} |
${escapeHtml(gpu.firmware || '-')} |
`;
});
html += '
';
} else {
html += '
Нет данных о PCIe устройствах
';
}
html += '
';
container.innerHTML = html;
// Initialize config sub-tabs
initConfigTabs();
}
function initConfigTabs() {
const tabs = document.querySelectorAll('.config-tab');
tabs.forEach(tab => {
tab.addEventListener('click', () => {
tabs.forEach(t => t.classList.remove('active'));
document.querySelectorAll('.config-tab-content').forEach(c => c.classList.remove('active'));
tab.classList.add('active');
document.getElementById('config-' + tab.dataset.configTab).classList.add('active');
});
});
}
async function loadFirmware() {
try {
const response = await fetch('/api/firmware');
const firmware = await response.json();
renderFirmware(firmware);
} catch (err) {
console.error('Failed to load firmware:', err);
}
}
let allFirmware = [];
function renderFirmware(firmware) {
allFirmware = firmware || [];
// Render in Firmware tab
const tbody = document.querySelector('#firmware-table tbody');
tbody.innerHTML = '';
if (!firmware || firmware.length === 0) {
tbody.innerHTML = '| Нет данных о прошивках |
';
} else {
firmware.forEach(fw => {
const row = document.createElement('tr');
row.innerHTML = `
${escapeHtml(fw.component)} |
${escapeHtml(fw.model)} |
${escapeHtml(fw.version)} |
`;
tbody.appendChild(row);
});
}
}
async function loadSensors() {
try {
const response = await fetch('/api/sensors');
allSensors = await response.json();
renderSensors(allSensors);
} catch (err) {
console.error('Failed to load sensors:', err);
}
}
function renderSensors(sensors) {
const container = document.getElementById('sensors-content');
if (!sensors || sensors.length === 0) {
container.innerHTML = 'Нет данных о сенсорах
';
return;
}
// Group by type
const byType = {};
sensors.forEach(s => {
if (!byType[s.type]) byType[s.type] = [];
byType[s.type].push(s);
});
const typeNames = {
temperature: 'Температура',
voltage: 'Напряжение',
power: 'Мощность',
fan_speed: 'Вентиляторы',
fan_status: 'Статус вентиляторов',
psu_status: 'Статус БП',
cpu_status: 'Статус CPU',
storage_status: 'Статус накопителей',
other: 'Прочее'
};
let html = '';
for (const [type, items] of Object.entries(byType)) {
html += `
${typeNames[type] || type}
`;
items.forEach(s => {
let valueStr = '';
let statusClass = s.status === 'ok' ? 'ok' : (s.status === 'ns' ? 'ns' : 'warn');
if (s.value) {
valueStr = `${s.value} ${s.unit}`;
} else if (s.raw_value) {
valueStr = s.raw_value;
} else {
valueStr = s.status;
}
html += `
${escapeHtml(s.name)}
${escapeHtml(valueStr)}
`;
});
html += '
';
}
container.innerHTML = html;
}
function filterSensors(type) {
if (!type) {
renderSensors(allSensors);
return;
}
const filtered = allSensors.filter(s => s.type === type);
renderSensors(filtered);
}
async function loadSerials() {
try {
const response = await fetch('/api/serials');
allSerials = await response.json();
renderSerials(allSerials);
} catch (err) {
console.error('Failed to load serials:', err);
}
}
function renderSerials(serials) {
const tbody = document.querySelector('#serials-table tbody');
tbody.innerHTML = '';
if (!serials || serials.length === 0) {
tbody.innerHTML = '| Нет серийных номеров |
';
return;
}
const categoryNames = {
'Board': 'Мат. плата',
'CPU': 'Процессор',
'Memory': 'Память',
'Storage': 'Накопитель',
'GPU': 'Видеокарта',
'PCIe': 'PCIe',
'Network': 'Сеть',
'PSU': 'БП',
'Firmware': 'Прошивка',
'FRU': 'FRU'
};
serials.forEach(item => {
// Skip items without serial number or with N/A
if (!item.serial_number || item.serial_number === 'N/A') return;
const row = document.createElement('tr');
row.innerHTML = `
${categoryNames[item.category] || item.category} |
${escapeHtml(item.component)} |
${escapeHtml(item.location || '-')} |
${escapeHtml(item.serial_number)} |
${escapeHtml(item.manufacturer || '-')} |
`;
tbody.appendChild(row);
});
}
function filterSerials(category) {
if (!category) {
renderSerials(allSerials);
return;
}
const filtered = allSerials.filter(s => s.category === category);
renderSerials(filtered);
}
async function loadEvents() {
try {
const response = await fetch('/api/events');
allEvents = await response.json();
renderEvents(allEvents);
} catch (err) {
console.error('Failed to load events:', err);
}
}
function renderEvents(events) {
const tbody = document.querySelector('#events-table tbody');
tbody.innerHTML = '';
if (!events || events.length === 0) {
tbody.innerHTML = '| Нет событий |
';
return;
}
events.forEach(event => {
const row = document.createElement('tr');
row.innerHTML = `
${formatDate(event.timestamp)} |
${escapeHtml(event.source)} |
${escapeHtml(event.description)} |
${event.severity} |
`;
tbody.appendChild(row);
});
}
function filterEvents(severity) {
if (!severity) {
renderEvents(allEvents);
return;
}
const filtered = allEvents.filter(e => e.severity === severity);
renderEvents(filtered);
}
// Export functions
function exportData(format) {
window.location.href = `/api/export/${format}`;
}
// Clear data
async function clearData() {
try {
await fetch('/api/clear', { method: 'DELETE' });
document.getElementById('upload-section').classList.remove('hidden');
document.getElementById('data-section').classList.add('hidden');
document.getElementById('clear-btn').classList.add('hidden');
document.getElementById('upload-status').textContent = '';
allSensors = [];
allEvents = [];
allSerials = [];
} catch (err) {
console.error('Failed to clear data:', err);
}
}
// Restart app (reload page)
function restartApp() {
if (confirm('Перезапустить приложение? Все загруженные данные будут потеряны.')) {
fetch('/api/clear', { method: 'DELETE' }).then(() => {
window.location.reload();
});
}
}
// Exit app (shutdown server)
async function exitApp() {
if (confirm('Завершить работу приложения?')) {
try {
await fetch('/api/shutdown', { method: 'POST' });
document.body.innerHTML = 'LOGPile
Приложение завершено. Можете закрыть эту вкладку.
';
} catch (err) {
// Server shutdown, connection will fail
document.body.innerHTML = 'LOGPile
Приложение завершено. Можете закрыть эту вкладку.
';
}
}
}
// Utilities
function formatDate(isoString) {
if (!isoString) return '-';
const date = new Date(isoString);
return date.toLocaleString('ru-RU');
}
function escapeHtml(text) {
if (!text) return '';
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
function findPCIeFirmwareVersion(firmwareEntries, pcieDevice) {
if (!Array.isArray(firmwareEntries) || !pcieDevice) return '';
const slot = (pcieDevice.slot || '').trim().toLowerCase();
const model = (pcieDevice.part_number || '').trim().toLowerCase();
if (!slot && !model) return '';
for (const fw of firmwareEntries) {
const name = (fw.device_name || '').trim().toLowerCase();
const version = (fw.version || '').trim();
if (!name || !version) continue;
if (slot && name.includes(slot)) return version;
if (model && name.includes(model)) return version;
}
return '';
}
function formatPCIeLink(currentWidth, currentSpeed, maxWidth, maxSpeed) {
// Helper to convert speed to generation
function speedToGen(speed) {
if (!speed) return '';
const gtMatch = speed.match(/(\d+\.?\d*)\s*GT/i);
if (gtMatch) {
const gts = parseFloat(gtMatch[1]);
if (gts >= 32) return 'Gen5';
if (gts >= 16) return 'Gen4';
if (gts >= 8) return 'Gen3';
if (gts >= 5) return 'Gen2';
if (gts >= 2.5) return 'Gen1';
}
return '';
}
// Helper to extract GT/s value for comparison
function extractGTs(speed) {
if (!speed) return 0;
const gtMatch = speed.match(/(\d+\.?\d*)\s*GT/i);
return gtMatch ? parseFloat(gtMatch[1]) : 0;
}
// If no data, return dash
if (!currentWidth && !currentSpeed) return '-';
const curGen = speedToGen(currentSpeed);
const maxGen = speedToGen(maxSpeed);
// Check if current is lower than max
const widthDegraded = maxWidth && currentWidth && currentWidth < maxWidth;
const speedDegraded = maxSpeed && currentSpeed && extractGTs(currentSpeed) < extractGTs(maxSpeed);
// Build current link string
const curWidthStr = currentWidth ? `x${currentWidth}` : '';
const curLinkStr = curGen ? `${curWidthStr} ${curGen}` : `${curWidthStr} ${currentSpeed || ''}`;
// Build max link string (if available)
let maxLinkStr = '';
if (maxWidth || maxSpeed) {
const maxWidthStr = maxWidth ? `x${maxWidth}` : '';
maxLinkStr = maxGen ? `${maxWidthStr} ${maxGen}` : `${maxWidthStr} ${maxSpeed || ''}`;
}
// Apply degraded class if needed
const degradedClass = (widthDegraded || speedDegraded) ? ' class="pcie-degraded"' : '';
// Format output: show "current" or "current / max" if max differs
if (maxLinkStr && (widthDegraded || speedDegraded)) {
return `${curLinkStr} / ${maxLinkStr}`;
} else if (maxLinkStr && maxLinkStr !== curLinkStr) {
return `${curLinkStr} / ${maxLinkStr}`;
} else {
return curLinkStr;
}
}