Skip to main content

unifly_api/model/
legacy_resources.rs

1// ── Legacy-only model types ──
2//
3// These types support Legacy API resources that have no Integration API
4// equivalent. Consumed by CLI stats, system, admin, and DPI commands.
5
6use chrono::{DateTime, Utc};
7use serde::{Deserialize, Serialize};
8use std::net::IpAddr;
9
10use super::entity_id::{EntityId, MacAddress};
11
12/// Statistical report (from Legacy API `stat/report/*`).
13#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct StatReport {
15    pub interval: String,
16    pub entries: Vec<StatEntry>,
17}
18
19/// A single stats entry within a report.
20#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct StatEntry {
22    pub timestamp: DateTime<Utc>,
23    pub wan_tx_bytes: Option<u64>,
24    pub wan_rx_bytes: Option<u64>,
25    pub num_sta: Option<u32>,
26    pub lan_num_sta: Option<u32>,
27    pub wlan_num_sta: Option<u32>,
28    pub latency: Option<f64>,
29    /// Catch-all for stat-specific fields.
30    pub extra: serde_json::Value,
31}
32
33/// Controller system info (from `GET /v1/info` or Legacy `/api/s/{site}/stat/sysinfo`).
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct SystemInfo {
36    pub controller_name: Option<String>,
37    pub version: String,
38    pub build: Option<String>,
39    pub hostname: Option<String>,
40    pub ip: Option<IpAddr>,
41    pub uptime_secs: Option<u64>,
42    pub update_available: Option<bool>,
43}
44
45/// Health summary for a subsystem (from Legacy `stat/health`).
46#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct HealthSummary {
48    /// Subsystem: "www", "wlan", "wan", "lan", "vpn"
49    pub subsystem: String,
50    /// Status: "ok", "warn", "error"
51    pub status: String,
52    pub num_adopted: Option<u32>,
53    pub num_sta: Option<u32>,
54    pub tx_bytes_r: Option<u64>,
55    pub rx_bytes_r: Option<u64>,
56    pub latency: Option<f64>,
57    pub wan_ip: Option<String>,
58    pub gateways: Option<Vec<String>>,
59    pub extra: serde_json::Value,
60}
61
62/// Low-level controller system info (from Legacy `stat/sysinfo`).
63#[derive(Debug, Clone, Serialize, Deserialize)]
64pub struct SysInfo {
65    pub timezone: Option<String>,
66    pub autobackup: Option<bool>,
67    pub hostname: Option<String>,
68    pub ip_addrs: Vec<String>,
69    pub live_chat: Option<String>,
70    pub data_retention_days: Option<u32>,
71    pub extra: serde_json::Value,
72}
73
74/// Backup entry (from Legacy `cmd/backup`).
75#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct Backup {
77    pub filename: String,
78    pub size_bytes: u64,
79    pub created_at: Option<DateTime<Utc>>,
80    pub version: Option<String>,
81}
82
83/// Admin user (from Legacy `cmd/sitemgr`).
84#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct Admin {
86    pub id: EntityId,
87    pub name: String,
88    pub email: Option<String>,
89    /// Role: "admin", "readonly", "custom"
90    pub role: String,
91    pub is_super: bool,
92    pub last_login: Option<DateTime<Utc>>,
93}
94
95/// Country entry (from Legacy `stat/ccode`).
96#[derive(Debug, Clone, Serialize, Deserialize)]
97pub struct Country {
98    pub code: String,
99    pub name: String,
100}
101
102/// DPI application entry.
103#[derive(Debug, Clone, Serialize, Deserialize)]
104pub struct DpiApplication {
105    pub id: u32,
106    pub name: String,
107    pub category_id: u32,
108    pub tx_bytes: u64,
109    pub rx_bytes: u64,
110}
111
112/// DPI category entry.
113#[derive(Debug, Clone, Serialize, Deserialize)]
114pub struct DpiCategory {
115    pub id: u32,
116    pub name: String,
117    pub tx_bytes: u64,
118    pub rx_bytes: u64,
119    pub apps: Vec<DpiApplication>,
120}
121
122/// Interval for historical stats queries.
123#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
124pub enum StatsInterval {
125    FiveMinutes,
126    Hourly,
127    Daily,
128}
129
130/// A single site-level stats sample (from `stat/report/hourly.site` or `daily.site`).
131#[derive(Debug, Clone, Serialize, Deserialize)]
132pub struct SiteStatsSample {
133    pub timestamp: DateTime<Utc>,
134    pub wan_tx_bytes: Option<u64>,
135    pub wan_rx_bytes: Option<u64>,
136    pub num_sta: Option<u32>,
137    pub lan_num_sta: Option<u32>,
138    pub wlan_num_sta: Option<u32>,
139    pub latency: Option<f64>,
140}
141
142/// A single device-level stats sample (from `stat/report/hourly.ap` or `hourly.gw`).
143#[derive(Debug, Clone, Serialize, Deserialize)]
144pub struct DeviceStatsSample {
145    pub timestamp: DateTime<Utc>,
146    pub mac: MacAddress,
147    pub tx_bytes: Option<u64>,
148    pub rx_bytes: Option<u64>,
149    pub num_sta: Option<u32>,
150    pub cpu: Option<f64>,
151    pub mem: Option<f64>,
152}