fix: Remaining TypeScript strict mode errors in routes

This commit is contained in:
2026-02-04 23:19:32 +00:00
parent 7be99098f5
commit f4160b60f9
6 changed files with 294 additions and 7 deletions

View File

@@ -0,0 +1,68 @@
/**
* Server Metrics Routes
* @author Descomplicar® | @link descomplicar.pt | @copyright 2026
*/
import { Router, Request, Response } from 'express'
import {
collectAllServerMetrics,
collectSSHMetrics,
syncHetznerToMonitoring
} from '../services/server-metrics.js'
const router = Router()
// POST /api/server-metrics/collect - Collect all server metrics
router.post('/collect', async (_req: Request, res: Response) => {
try {
const result = await collectAllServerMetrics()
res.json({
success: true,
message: 'Métricas recolhidas com sucesso',
...result
})
} catch (error) {
console.error('Error collecting metrics:', error)
res.status(500).json({
success: false,
error: 'Failed to collect metrics'
})
}
})
// POST /api/server-metrics/ssh - Collect SSH metrics only (CWP, EasyPanel)
router.post('/ssh', async (_req: Request, res: Response) => {
try {
const result = await collectSSHMetrics()
res.json({
success: true,
message: `SSH: ${result.success} OK, ${result.failed} failed`,
...result
})
} catch (error) {
console.error('Error collecting SSH metrics:', error)
res.status(500).json({
success: false,
error: 'Failed to collect SSH metrics'
})
}
})
// POST /api/server-metrics/hetzner - Sync Hetzner to monitoring
router.post('/hetzner', async (_req: Request, res: Response) => {
try {
const synced = await syncHetznerToMonitoring()
res.json({
success: true,
message: `${synced} servidores Hetzner sincronizados`,
synced
})
} catch (error) {
console.error('Error syncing Hetzner:', error)
res.status(500).json({
success: false,
error: 'Failed to sync Hetzner metrics'
})
}
})
export default router