Scan System

Connectivity scan ka step-by-step technical flow

Scan Trigger Karne Ke Tarike

1. Manual

Dashboard > Routers > Connectivity > Run Connectivity Scan button

2. Scheduler

Dashboard > Routers > Scheduler — automatic intervals set karo (e.g., har 5 minute)

3. Worker Jobs

Backend worker automatically scheduled scans run karta hai background mein

Scan Execution Flow

diagram
SCAN START
    |
    ▼
[1] Select Routers
    ├── All active? (onlyActive = true)
    └── Specific router? (routerId filter)

    |
    ▼
[2] For Each Router:
    |
    ├── [2a] Bridge Status Check
    │   ├── ONLINE? → Continue
    │   └── OFFLINE? → Mark UNREACHABLE, skip
    |
    ├── [2b] Fetch Active Sessions
    │   Bridge Agent → Router API (/ppp/active/getall)
    │   Returns: [{username, address, uptime}]
    |
    ├── [2c] Compare with DB Subscribers
    │   MATCH? → ONLINE
    │   NO MATCH? → miss_count + 1
    |
    └── [2d] Evaluate Miss Count
        miss_count < threshold(2) → wait
        miss_count >= threshold  → OFFLINE_ROUTER

    |
    ▼
[3] Generate Events
    ├── New OFFLINE → event: offline_detected
    └── Was OFFLINE, now ONLINE → event: recovered_online

    |
    ▼
[4] Queue WhatsApp Notifications
    ├── Template find karo
    ├── Cooldown check (4 hours)
    ├── Variables replace karo
    └── Queue to dispatch worker

    |
    ▼
[5] Update Database + WebSocket emit

    |
    ▼
SCAN COMPLETE → Summary return

Router Unreachable Guard

Agar ek scan mein bahut sare users "offline" dikhein (50%+), toh shayad router ki problem ho — users actually offline nahi. Guard is se bachata hai:

logic
IF offline_count / total_tracked > 0.50 (50%)
THEN:
  Mark router as ROUTER_UNREACHABLE
  No individual offline_detected events
  No WhatsApp notifications
  Wait for next scan

Queue Mode vs Direct Mode

ModeDescriptionBest For
Queued (recommended)Scan background worker queue mein jaata haiProduction use
DirectScan immediately is request mein run hota haiTesting/debug

Scan Summary — Kaise Samjhein?

BadgeMatlab
Scan HealthyHealthy0 offline, 0 failed, routers processed
Scan UpdateUpdateKuch offline ya issues hain
offlineRows=5Currently offline subscribers count
eventRows=8Events generated
dispatchRows=3Notifications queued
restartGraceRouters=1Routers in restart grace period