sleeping devices status #1519

This commit is contained in:
Jokob @NetAlertX
2026-03-02 04:35:07 +00:00
parent deb0d16c3d
commit 8e6efc3008
22 changed files with 211 additions and 55 deletions

View File

@@ -101,6 +101,8 @@ class Device(ObjectType):
devParentRelTypeSource = String(description="Source tracking for devParentRelType (USER, LOCKED, NEWDEV, or plugin prefix)")
devVlanSource = String(description="Source tracking for devVlan")
devFlapping = Int(description="Indicates flapping device (device changing between online/offline states frequently)")
devCanSleep = Int(description="Can this device sleep? (0 or 1). When enabled, offline periods within NTFPRCS_sleep_time are reported as Sleeping instead of Down.")
devIsSleeping = Int(description="Computed: Is device currently in a sleep window? (0 or 1)")
class DeviceResult(ObjectType):
@@ -247,7 +249,7 @@ class Query(ObjectType):
)
is_down = (
device["devPresentLastScan"] == 0 and device["devAlertDown"] and "down" in allowed_statuses
device["devPresentLastScan"] == 0 and device["devAlertDown"] and device.get("devIsSleeping", 0) == 0 and "down" in allowed_statuses
)
is_offline = (
@@ -282,11 +284,17 @@ class Query(ObjectType):
devices_data = [
device for device in devices_data if device["devIsNew"] == 1 and device["devIsArchived"] == 0
]
elif status == "sleeping":
devices_data = [
device
for device in devices_data
if device.get("devIsSleeping", 0) == 1 and device["devIsArchived"] == 0
]
elif status == "down":
devices_data = [
device
for device in devices_data
if device["devPresentLastScan"] == 0 and device["devAlertDown"] and device["devIsArchived"] == 0
if device["devPresentLastScan"] == 0 and device["devAlertDown"] and device.get("devIsSleeping", 0) == 0 and device["devIsArchived"] == 0
]
elif status == "archived":
devices_data = [

View File

@@ -35,7 +35,7 @@ COLUMN_NAME_PATTERN = re.compile(r"^[a-zA-Z0-9_]+$")
ALLOWED_DEVICE_COLUMNS = Literal[
"devName", "devOwner", "devType", "devVendor",
"devGroup", "devLocation", "devComments", "devFavorite",
"devParentMAC"
"devParentMAC", "devCanSleep"
]
ALLOWED_NMAP_MODES = Literal[
@@ -204,9 +204,19 @@ class DeviceInfo(BaseModel):
description="Present in last scan (0 or 1)",
json_schema_extra={"enum": [0, 1]}
)
devStatus: Optional[Literal["online", "offline"]] = Field(
devStatus: Optional[Literal["online", "offline", "sleeping"]] = Field(
None,
description="Online/Offline status"
description="Online/Offline/Sleeping status"
)
devCanSleep: Optional[int] = Field(
0,
description="Can device sleep? (0=No, 1=Yes). When enabled, offline periods within NTFPRCS_sleep_time window are shown as Sleeping.",
json_schema_extra={"enum": [0, 1]}
)
devIsSleeping: Optional[int] = Field(
0,
description="Computed: Is device currently in a sleep window? (0=No, 1=Yes)",
json_schema_extra={"enum": [0, 1]}
)
devMacSource: Optional[str] = Field(None, description="Source of devMac (USER, LOCKED, or plugin prefix)")
devNameSource: Optional[str] = Field(None, description="Source of devName")
@@ -228,14 +238,15 @@ class DeviceSearchResponse(BaseResponse):
class DeviceListRequest(BaseModel):
"""Request for listing devices by status."""
status: Optional[Literal[
"connected", "down", "favorites", "new", "archived", "all", "my",
"connected", "down", "sleeping", "favorites", "new", "archived", "all", "my",
"offline"
]] = Field(
None,
description=(
"Filter devices by status:\n"
"- connected: Active devices present in the last scan\n"
"- down: Devices with active 'Device Down' alert\n"
"- down: Devices with active 'Device Down' alert (excludes sleeping)\n"
"- sleeping: Devices in a sleep window (devCanSleep=1, offline within NTFPRCS_sleep_time)\n"
"- favorites: Devices marked as favorite\n"
"- new: Devices flagged as new\n"
"- archived: Devices moved to archive\n"