Prechádzať zdrojové kódy

revert(snmp): drop Netgear FastPath memory + vitals visibility (reverts #1538)

Back to CPU/temp-only vitals hidden behind VitalsAvailable=false. The
feature returns restructured once PRs get CI (see the restructuring
issue).
gnacho 1 mesiac pred
rodič
commit
d66d648251

+ 3 - 3
app/src/components/RouterCard.tsx

@@ -96,9 +96,9 @@ export function RouterCard({ router, index = 0, className }: RouterCardProps) {
           {/* #441: sin vitals (switch SNMP/beacon) no se pintan ceros falsos */}
           {router.vitalsAvailable !== false && (
             <>
-              {router.cpu != null && <MiniMetric icon={Cpu} value={`${router.cpu} %`} label="CPU" hot={router.hotMetric === 'cpu'} />}
-              {router.ram != null && <MiniMetric icon={MemoryStick} value={`${router.ram} %`} label="RAM" hot={router.hotMetric === 'ram'} />}
-              {router.temp != null && <MiniMetric icon={Thermometer} value={fmtTemp(router.temp, tempUnit)} label={t('common.temperature')} hot={router.hotMetric === 'temp'} />}
+              <MiniMetric icon={Cpu} value={`${router.cpu} %`} label="CPU" hot={router.hotMetric === 'cpu'} />
+              <MiniMetric icon={MemoryStick} value={`${router.ram} %`} label="RAM" hot={router.hotMetric === 'ram'} />
+              <MiniMetric icon={Thermometer} value={fmtTemp(router.temp, tempUnit)} label={t('common.temperature')} hot={router.hotMetric === 'temp'} />
             </>
           )}
           <MiniMetric icon={Users} value={String(router.clients)} label={t('common.clients')} />

+ 10 - 12
app/src/components/routers/FleetCard.tsx

@@ -276,18 +276,16 @@ export function FleetCard({ router, index = 0, refreshKey = 0 }: FleetCardProps)
             </p>
           ) : (
             <>
-              {router.cpu != null && <MetricRow icon={Cpu} label="CPU" value={`${router.cpu} %`} pct={router.cpu ?? 0} hot={router.hotMetric === 'cpu'} />}
-              {router.ram != null && <MetricRow icon={MemoryStick} label={t('common.memory')} value={`${router.ram} %`} pct={router.ram ?? 0} hot={router.hotMetric === 'ram'} />}
-              {router.temp != null && (
-                <MetricRow
-                  icon={Thermometer}
-                  label={t('common.temperature')}
-                  value={fmtTemp(router.temp, tempUnit)}
-                  pct={Math.min(100, ((router.temp ?? 0) / 90) * 100)}
-                  hot={router.hotMetric === 'temp'}
-                  title={router.hotMetric === 'temp' ? t('routers.tempThreshold', { value: fmtTemp(router.tempThreshold ?? 65, tempUnit) }) : undefined}
-                />
-              )}
+              <MetricRow icon={Cpu} label="CPU" value={`${router.cpu} %`} pct={router.cpu ?? 0} hot={router.hotMetric === 'cpu'} />
+              <MetricRow icon={MemoryStick} label={t('common.memory')} value={`${router.ram} %`} pct={router.ram ?? 0} hot={router.hotMetric === 'ram'} />
+              <MetricRow
+                icon={Thermometer}
+                label={t('common.temperature')}
+                value={fmtTemp(router.temp, tempUnit)}
+                pct={Math.min(100, ((router.temp ?? 0) / 90) * 100)}
+                hot={router.hotMetric === 'temp'}
+                title={router.hotMetric === 'temp' ? t('routers.tempThreshold', { value: fmtTemp(router.tempThreshold ?? 65, tempUnit) }) : undefined}
+              />
             </>
           )}
         </div>

+ 1 - 19
server-go/internal/adapters/live.go

@@ -105,11 +105,7 @@ type routerPolled struct {
 	// hasCpu: mismo contrato que hasTemp para la CPU de los switches SNMP
 	// (tabla de procesos Netgear FastPath): sin bandera, el null de #441
 	// pisaría la lectura real.
-	hasCpu bool
-	// hasRam: same contract for the RAM derived from the Netgear FastPath
-	// MemFree/MemAvailable scalars. Without the flag the #441 nulling would
-	// erase a real reading; the OpenWrt agent path sets RAM without needing it.
-	hasRam   bool
+	hasCpu   bool
 	sysDescr string
 	// sysName (#1256): hostname que el usuario define en el equipo; para
 	// SNMP alimenta el Name visible de la unidad en flota.
@@ -1567,20 +1563,6 @@ func (l *Live) buildRouter(p *routerPolled, history []histPoint) Router {
 		if p.hasCpu {
 			r.CPU = iptr(p.cpu)
 		}
-		// Netgear FastPath memory: restore the RAM percentage derived from the
-		// MemFree/MemAvailable scalars, same revival channel as hasCpu/hasTemp.
-		if p.hasRam {
-			r.RAM = iptr(p.ram)
-		}
-		// #1528 revived CPU/temp (and now RAM) but left VitalsAvailable=false,
-		// the beacon/external marker the frontend uses to HIDE the whole vitals
-		// row — so the readings were present in the payload yet never shown in
-		// the overview card, fleet list or detail. If the SNMP poll supplied any
-		// real vital this source CAN report vitals: flip the flag so the row
-		// renders (the frontend skips any individual field that is still nil).
-		if r.CPU != nil || r.RAM != nil || r.Temp != nil {
-			r.VitalsAvailable = bptr(true)
-		}
 	}
 	r.SnmpEnabled = p.cfg.SnmpEnabled
 	if p.selfExpose {

+ 1 - 4
server-go/internal/adapters/snmp_live.go

@@ -54,7 +54,7 @@ func (l *Live) pollRouterSNMP(cfg RouterConfig) (*routerPolled, error) {
 	// Netgear FastPath (XS708T, GS728TXP/S3300…): CPU por proceso y sensores
 	// de temperatura en su MIB privada (4526.11). Best-effort igual que el
 	// MikroTik: sin esos árboles, ok=false y los vitales siguen a null.
-	ngCpu, hasNgCpu, ngTemp, hasNgTemp, ngRam, hasNgRam := npsnmp.PollNetgearVitals(session)
+	ngCpu, hasNgCpu, ngTemp, hasNgTemp := npsnmp.PollNetgearVitals(session)
 	// #1036: MAC propia del switch (dot1dBaseBridgeAddress). Sin ella el
 	// equipo no tenía MAC en flota ni casaba por MAC en topología. Cache:
 	// si el OID no contesta en este poll se conserva la última conocida.
@@ -216,9 +216,6 @@ func (l *Live) pollRouterSNMP(cfg RouterConfig) (*routerPolled, error) {
 	if hasNgCpu {
 		p.cpu, p.hasCpu = ngCpu, true
 	}
-	if hasNgRam {
-		p.ram, p.hasRam = ngRam, true
-	}
 	l.mu.Lock()
 	l.snmpLastPoll[cfg.ID] = now
 	l.mu.Unlock()

+ 8 - 77
server-go/internal/snmp/netgearVitals.go

@@ -10,12 +10,9 @@
 //   - boxServicesTempSensorTemperature
 //     1.3.6.1.4.1.4526.11.43.1.8.1.5.<idx>: Integer32 en °C por sensor; con
 //     varios sensores se reporta el máximo (el punto caliente).
-//   - agentSwitchCpuProcessMemFree / MemAvailable (KBytes scalars):
-//     1.3.6.1.4.1.4526.11.1.1.4.1.0 and …4.2.0. There is no "MemTotal" scalar,
-//     but MemAvailable is the device's usable total pool (≈ physical RAM minus
-//     kernel reservations: 233 MB on a 256 MB GS728TXP, 486 MB on a 512 MB
-//     XS708T), so usage is derived as used% = (MemAvailable − MemFree) /
-//     MemAvailable.
+//
+// No hay escalar de memoria TOTAL en la MIB (solo MemFree/MemAvailable), así
+// que el RAM queda a null antes que inventar un porcentaje.
 package snmp
 
 import (
@@ -26,14 +23,10 @@ import (
 )
 
 const (
-	// OidNetgearCpuUtil: per-process utilization column (5/60/300s string).
+	// OidNetgearCpuUtil: columna de utilización por proceso (string 5/60/300s).
 	OidNetgearCpuUtil = ".1.3.6.1.4.1.4526.11.1.1.4.8.1.3"
-	// OidNetgearTempSensor: per-sensor temperature column (°C).
+	// OidNetgearTempSensor: columna de temperatura por sensor (°C).
 	OidNetgearTempSensor = ".1.3.6.1.4.1.4526.11.43.1.8.1.5"
-	// OidNetgearMemFree / OidNetgearMemAvailable: KBytes scalars. MemAvailable
-	// is the usable total pool, MemFree the currently-free part (see header).
-	OidNetgearMemFree      = ".1.3.6.1.4.1.4526.11.1.1.4.1.0"
-	OidNetgearMemAvailable = ".1.3.6.1.4.1.4526.11.1.1.4.2.0"
 )
 
 // cpuUtilRe casa la primera ventana ("5 Sec (  0.19%)") del string por
@@ -81,54 +74,12 @@ func ParseNetgearTemps(vals []int) (temp int, ok bool) {
 	return max, ok
 }
 
-// ParseNetgearRam derives the used-memory percentage from the two KBytes
-// scalars: MemAvailable is the usable total pool and MemFree the currently
-// free part, so used% = (available - free) / available. Guards against a
-// missing/zero total and free>available (transient between the two gets).
-func ParseNetgearRam(freeKB, availKB int) (used int, ok bool) {
-	if availKB <= 0 || freeKB < 0 {
-		return 0, false
-	}
-	usedF := float64(availKB-freeKB) / float64(availKB) * 100.0
-	if usedF < 0 {
-		usedF = 0
-	}
-	used = int(usedF + 0.5)
-	if used > 100 {
-		used = 100
-	}
-	return used, true
-}
-
-// netgearKbFromPDU reads an integer KBytes value from a numeric PDU. Unlike
-// mikrotikTempFromPDU it applies no temperature range cap (memory values are
-// large); NoSuchObject/NoSuchInstance or a non-numeric type → ok=false.
-func netgearKbFromPDU(v g.SnmpPDU) (int, bool) {
-	if v.Type == g.NoSuchObject || v.Type == g.NoSuchInstance {
-		return 0, false
-	}
-	switch v.Type {
-	case g.Gauge32, g.Integer, g.Counter32, g.Counter64:
-	default:
-		return 0, false
-	}
-	bi := g.ToBigInt(v.Value)
-	if bi == nil || !bi.IsInt64() {
-		return 0, false
-	}
-	n := bi.Int64()
-	if n < 0 {
-		return 0, false
-	}
-	return int(n), true
-}
-
 // PollNetgearVitals lee CPU y temperatura del agente FastPath. Un switch sin
 // estos árboles (otra familia) devuelve ok=false en ambos y el caller
 // conserva sus vitales a null, como hoy.
-func PollNetgearVitals(s *g.GoSNMP) (cpu int, okCpu bool, temp int, okTemp bool, ram int, okRam bool) {
+func PollNetgearVitals(s *g.GoSNMP) (cpu int, okCpu bool, temp int, okTemp bool) {
 	if s == nil {
-		return 0, false, 0, false, 0, false
+		return 0, false, 0, false
 	}
 	if pdus, err := walkSafe(s, OidNetgearCpuUtil); err == nil {
 		vals := make([]string, 0, len(pdus))
@@ -149,25 +100,5 @@ func PollNetgearVitals(s *g.GoSNMP) (cpu int, okCpu bool, temp int, okTemp bool,
 		}
 		temp, okTemp = ParseNetgearTemps(vals)
 	}
-	// Memory: two KBytes scalars in one GET. Missing/free>available → ok=false
-	// and the caller leaves RAM null (the #441 SNMP nulled-vitals contract).
-	if res, err := s.Get([]string{OidNetgearMemFree, OidNetgearMemAvailable}); err == nil {
-		free, avail, haveFree, haveAvail := 0, 0, false, false
-		for _, p := range res.Variables {
-			switch p.Name {
-			case OidNetgearMemFree:
-				if v, ok := netgearKbFromPDU(p); ok {
-					free, haveFree = v, true
-				}
-			case OidNetgearMemAvailable:
-				if v, ok := netgearKbFromPDU(p); ok {
-					avail, haveAvail = v, true
-				}
-			}
-		}
-		if haveFree && haveAvail {
-			ram, okRam = ParseNetgearRam(free, avail)
-		}
-	}
-	return cpu, okCpu, temp, okTemp, ram, okRam
+	return cpu, okCpu, temp, okTemp
 }

+ 0 - 30
server-go/internal/snmp/netgearVitals_test.go

@@ -45,33 +45,3 @@ func TestParseNetgearTemps(t *testing.T) {
 		t.Fatal("sin sensores ok debe ser false")
 	}
 }
-
-func TestParseNetgearRam(t *testing.T) {
-	// GS728TXP live reading: ~233 MB pool, ~50 MB free → ~79% used.
-	if used, ok := ParseNetgearRam(50968, 238968); !ok || used != 79 {
-		t.Fatalf("GS728TXP used = %d/%v, want 79", used, ok)
-	}
-	// XS708T live reading: ~486 MB pool, ~325 MB free → ~33% used.
-	if used, ok := ParseNetgearRam(332580, 497656); !ok || used != 33 {
-		t.Fatalf("XS708T used = %d/%v, want 33", used, ok)
-	}
-	// All free → 0% used.
-	if used, ok := ParseNetgearRam(238968, 238968); !ok || used != 0 {
-		t.Fatalf("all-free used = %d/%v, want 0", used, ok)
-	}
-	// Fully used (free 0) → 100%.
-	if used, ok := ParseNetgearRam(0, 238968); !ok || used != 100 {
-		t.Fatalf("fully-used used = %d/%v, want 100", used, ok)
-	}
-	// free > available (transient between the two gets) clamps to 0.
-	if used, ok := ParseNetgearRam(300000, 238968); !ok || used != 0 {
-		t.Fatalf("free>avail used = %d/%v, want 0", used, ok)
-	}
-	// Guards: no total, or negative free → not ok (RAM stays null).
-	if _, ok := ParseNetgearRam(10, 0); ok {
-		t.Fatal("avail<=0 must be not-ok")
-	}
-	if _, ok := ParseNetgearRam(-1, 238968); ok {
-		t.Fatal("free<0 must be not-ok")
-	}
-}