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