refactor(PingServices): update server selection logic to include home routers and improve error handling for ping services
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m39s

This commit is contained in:
2026-02-16 23:47:24 +07:00
parent ee357ed59a
commit c0d35c2e51
2 changed files with 13 additions and 9 deletions
+2 -2
View File
@@ -300,8 +300,8 @@ async function applyMikrotikConfig(req, res) {
async function runPingViaRouter(serverId, gatewayIp, target, count = 5, interfaceName = null) {
const servers = await readServersFromS3();
const server = servers.find((s) => (s.id || s.dns || s.ip) === serverId);
if (!server || server.type !== 'jumphost') {
throw new Error('Jumphost server not found');
if (!server || (server.type !== 'jumphost' && server.type !== 'home')) {
throw new Error('Сервер (jumphost или входной роутер) не найден');
}
const creds = getMikrotikCredentials(server);
if (!creds) {
+11 -7
View File
@@ -367,26 +367,30 @@ async function getPingServices(req, res) {
const { runPingViaRouter } = require('./mikrotikConfigRoutes');
const { readServersFromS3 } = require('./serversRoutes');
const servers = await readServersFromS3();
const jumphosts = servers.filter((s) => s && String(s.type || '').toLowerCase() === 'jumphost');
const serverId = (uiSettings.pingServicesServerId && String(uiSettings.pingServicesServerId).trim()) || (jumphosts[0] && (jumphosts[0].id || jumphosts[0].dns || jumphosts[0].ip));
const routerServers = servers.filter(
(s) => s && (String(s.type || '').toLowerCase() === 'jumphost' || String(s.type || '').toLowerCase() === 'home')
);
const serverId = (uiSettings.pingServicesServerId && String(uiSettings.pingServicesServerId).trim()) || (routerServers[0] && (routerServers[0].id || routerServers[0].dns || routerServers[0].ip));
const gatewayIp = (uiSettings.pingServicesGatewayIp && String(uiSettings.pingServicesGatewayIp).trim()) || null;
let gatewayIpResolved = gatewayIp;
if (!gatewayIpResolved && serverId && jumphosts.length > 0) {
const server = jumphosts.find((s) => (s.id || s.dns || s.ip) === serverId) || jumphosts[0];
if (!gatewayIpResolved && serverId && routerServers.length > 0) {
const server = routerServers.find((s) => (s.id || s.dns || s.ip) === serverId) || routerServers[0];
const gateways = Array.isArray(server.gateways) ? server.gateways : [];
const primary = gateways.find((g) => g && g.primary) || gateways[0];
gatewayIpResolved = primary && (primary.ip || primary.remoteIp) ? (primary.ip || primary.remoteIp) : null;
}
if (!serverId || !gatewayIpResolved) {
if (!serverId) {
console.warn('[ping-services] router mode: no serverId (no jumphost/home in settings or in servers list)');
return res.json(fallbackPayload);
}
const results = await Promise.all(
PING_SERVICES.map(async (svc) => {
try {
const result = await runPingViaRouter(serverId, gatewayIpResolved, svc.host, 3);
const result = await runPingViaRouter(serverId, gatewayIpResolved || null, svc.host, 3);
const ms = typeof result.avgMs === 'number' ? Math.round(result.avgMs) : null;
return { id: svc.id, name: svc.name, host: svc.host, ms };
} catch (_) {
} catch (err) {
console.warn('[ping-services] runPingViaRouter failed for', svc.host, err?.message || err);
return { id: svc.id, name: svc.name, host: svc.host, ms: null };
}
})