修复语法错误

This commit is contained in:
CN-JS-HuiBai
2026-04-10 22:25:04 +08:00
parent cb27d1a249
commit 2cd6c6ef27

View File

@@ -611,32 +611,34 @@ async function getServerDetails(baseUrl, instance, job, settings = {}) {
// 2. Fallback to Prometheus Targets API
if (!foundIp) {
const targets = await getTargets(baseUrl);
const matchedTarget = targets.find(t => t.labels && t.labels.instance === node && t.labels.job === job);
if (matchedTarget) {
try {
const targets = await getTargets(baseUrl);
const matchedTarget = targets.find(t => t.labels && t.labels.instance === node && t.labels.job === job);
if (matchedTarget) {
const scrapeUrl = matchedTarget.scrapeUrl || '';
try {
const urlObj = new URL(scrapeUrl);
const host = urlObj.hostname;
if (host.includes(':')) {
results.ipv6 = [host];
results.ipv4 = [];
} else {
results.ipv4 = [host];
results.ipv6 = [];
}
const urlObj = new URL(scrapeUrl);
const host = urlObj.hostname;
if (host.includes(':')) {
results.ipv6 = [host];
results.ipv4 = [];
} else {
results.ipv4 = [host];
results.ipv6 = [];
}
foundIp = true;
} catch (e) {
results.ipv4 = [];
results.ipv6 = [];
// Simple fallback if URL parsing fails
const host = scrapeUrl.split('//').pop().split('/')[0].split(':')[0];
if (host) {
results.ipv4 = [host];
results.ipv6 = [];
foundIp = true;
}
}
} else {
results.ipv4 = [];
results.ipv6 = [];
}
} else {
results.ipv4 = [];
results.ipv6 = [];
} catch (e) {
console.error(`[Prometheus] Error fetching target info for ${node}:`, e.message);
}
}
@@ -646,8 +648,8 @@ async function getServerDetails(baseUrl, instance, job, settings = {}) {
}
} catch (err) {
console.error(`[Prometheus] Critical error resolving IPs for ${node}:`, err.message);
results.ipv4 = [];
results.ipv6 = [];
results.ipv4 = results.ipv4 || [];
results.ipv6 = results.ipv6 || [];
}
// Group partitions