feat: ping through agent — send ICMP ping from workstation via agent

Adds a ping tool in the Equipment page workstation card (visible when
agent is online). User enters an IP/hostname, the request goes through
the PMS backend → WebSocket → agent → executes ping -n 4, returns
raw output displayed in a monospace block.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-29 10:08:38 +03:00
parent 7f546d809e
commit 11300bccbf
3 changed files with 74 additions and 0 deletions

View File

@@ -343,6 +343,23 @@ const workstationRoutes: FastifyPluginAsync = async (fastify) => {
},
)
// ── POST /api/hotels/:slug/workstations/:id/ping ────────────────────────────
fastify.post<WsParam & { Body: { host: string } }>(
'/api/hotels/:slug/workstations/:id/ping',
{ onRequest: [fastify.authenticate] },
async (req, reply) => {
const { id } = req.params
const { host } = req.body
if (!host?.trim()) return reply.code(400).send({ error: 'host required' })
try {
const result = await sendCommandAndWait(id, { type: 'ping_host', host: host.trim() }, 20000) as { ok: boolean; output?: string; error?: string }
return result
} catch (err) {
return reply.code(502).send({ ok: false, error: err instanceof Error ? err.message : 'Ошибка' })
}
},
)
// ── POST /api/hotels/:slug/workstations/update-all ──────────────────────────
fastify.post<SlugParam>(
'/api/hotels/:slug/workstations/update-all',