fix: remove HEAD-based site checker that caused false DOWN status

The checkAllSitesAvailability() function did HEAD requests from EasyPanel
to check sites. Many WordPress sites block HEAD or return errors, causing
all sites to show as DOWN while keeping valid response times from the
CWP collector. The CWP collector (collect-sites.sh) is the single source
of truth for site status.

Removed:
- checkSiteAvailability() and checkAllSitesAvailability() from monitoring service
- POST /api/monitor/check-sites endpoint
- api/scripts/check-sites.ts cron script

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-10 17:48:41 +00:00
parent eb4e45186b
commit a19e07d83c
3 changed files with 1 additions and 170 deletions

View File

@@ -9,12 +9,9 @@ interface MonitoringItem {
id: number
name: string
category: string
type: string
status: string
details: any
last_check: string
created_at: string
updated_at: string
}
interface CategorySummary {
@@ -25,105 +22,6 @@ interface CategorySummary {
critical: number
}
/**
* Check if a URL is accessible (HTTP HEAD request)
*/
export async function checkSiteAvailability(url: string, timeout = 10000): Promise<{
available: boolean
statusCode?: number
responseTime?: number
error?: string
}> {
const startTime = Date.now()
const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), timeout)
try {
const response = await fetch(url, {
method: 'HEAD',
signal: controller.signal,
headers: {
'User-Agent': 'Descomplicar-Monitor/1.0'
}
})
clearTimeout(timeoutId)
const responseTime = Date.now() - startTime
return {
available: response.ok || response.status < 500,
statusCode: response.status,
responseTime
}
} catch (error) {
clearTimeout(timeoutId)
return {
available: false,
error: (error as Error).message,
responseTime: Date.now() - startTime
}
}
}
/**
* Check all sites and update their availability status
*/
export async function checkAllSitesAvailability(): Promise<{
checked: number
up: number
down: number
results: any[]
}> {
// Get all sites from monitoring table
const [sites] = await db.query<RowDataPacket[]>(`
SELECT id, name, details FROM tbl_eal_monitoring
WHERE category = 'site'
`)
const results: any[] = []
let up = 0
let down = 0
for (const site of sites) {
const details = typeof site.details === 'string' ? JSON.parse(site.details) : site.details
const siteUrl = details?.site_url || `https://${site.name}`
const check = await checkSiteAvailability(siteUrl)
// Update status if site is down
if (!check.available) {
await db.query(
'UPDATE tbl_eal_monitoring SET status = ?, last_check = NOW() WHERE id = ?',
['down', site.id]
)
down++
} else {
// If was down and now is up, set to 'up' (will be replaced by plugin data later)
const currentStatus = details?.health?.status || 'ok'
if (currentStatus === 'down') {
await db.query(
'UPDATE tbl_eal_monitoring SET status = ?, last_check = NOW() WHERE id = ?',
['up', site.id]
)
}
up++
}
results.push({
name: site.name,
url: siteUrl,
...check
})
}
return {
checked: sites.length,
up,
down,
results
}
}
export async function getMonitoringData() {
// Get all items
const [items] = await db.query<RowDataPacket[]>(`