updated view and database

This commit is contained in:
ske087
2026-06-24 15:21:40 +03:00
parent cb12a8f1cf
commit a48b3afb83
14 changed files with 372 additions and 205 deletions
+27 -1
View File
@@ -4,7 +4,7 @@ Database models for enhanced server monitoring system
from sqlalchemy import Column, Integer, String, DateTime, Text, Boolean, ForeignKey, LargeBinary, Float, Table
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from datetime import datetime
from datetime import datetime, timedelta
import json
import hashlib
from cryptography.fernet import Fernet
@@ -53,6 +53,9 @@ class Device(Base):
info_reviewed_at = Column(DateTime, default=lambda: datetime(1970, 1, 1))
card_presence = Column(String(10), default='enable')
custom_chrome_url = Column(String(500), nullable=True) # per-device production URL override (overrides WMTGlobalConfig.chrome_url)
# Stamped on every WMT client check-in (config pull / update request / timestamp poll).
# Authoritative signal that a device is "WMT enabled" on the unified devices page.
wmt_last_seen = Column(DateTime, nullable=True, index=True)
# Relationships
logs = relationship("LogEntry", back_populates="device")
@@ -67,6 +70,29 @@ class Device(Base):
"""Alias for nume_masa used by WMT module."""
return self.nume_masa
@property
def wmt_enabled(self):
"""True when this device has ever checked in via the WMT client API.
This is the authoritative "WMT enabled" signal for the unified devices
page (replaces the old 'has a MAC address' heuristic).
"""
return self.wmt_last_seen is not None
@property
def is_online(self):
"""Heuristic online state: active status and seen within the last 10 minutes."""
if self.status != 'active' or not self.last_seen:
return False
return (datetime.utcnow() - self.last_seen) <= timedelta(minutes=10)
@property
def minutes_since_last_seen(self):
"""Whole minutes since the device was last seen (None if never seen)."""
if not self.last_seen:
return None
return int((datetime.utcnow() - self.last_seen).total_seconds() // 60)
def __repr__(self):
return f"<Device(hostname='{self.hostname}', ip='{self.device_ip}')>"