1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::net::IpAddr;

use super::{deserialize_bool, MikrotikClient};

impl MikrotikClient {
    #[tracing::instrument(level = "debug", err)]
    pub async fn get_dhcp_leases(&self) -> anyhow::Result<Vec<DhcpEntry>> {
        self.get_all("/rest/ip/dhcp-server/lease").await
    }
}

#[derive(serde::Deserialize, Clone, Debug)]
#[serde(rename_all = "kebab-case")]
pub struct DhcpEntry {
    #[serde(flatten)]
    pub active: Option<DhcpEntryActive>,

    #[serde(rename = ".id")]
    pub id: String,
    pub address: IpAddr,
    pub address_lists: String,
    #[serde(deserialize_with = "deserialize_bool")]
    pub blocked: bool, // "false",
    pub client_id: Option<String>, // "1:fc:ec:da:19:a5:a",
    pub comment: Option<String>,   // "Unifi AP",
    pub dhcp_option: String,       // "",
    #[serde(deserialize_with = "deserialize_bool")]
    pub disabled: bool,
    #[serde(deserialize_with = "deserialize_bool")]
    pub dynamic: bool,
    pub last_seen: String,                      // "8w3d23h15m28s",
    pub mac_address: Option<eui48::MacAddress>, // "FC:EC:DA:19:A5:0A",
    pub radius: String,                         // "false",
    pub server: Option<String>,                 // "mainDhcp",
    pub status: String,                         // "waiting",
    pub host_name: Option<String>,
    pub agent_circuit_id: Option<String>, //"sw131.d.hosna.network eth 0/5",
    pub agent_remote_id: Option<String>,  // "sfp-sfpplus4",
}

#[derive(serde::Deserialize, Clone, Debug)]
#[serde(rename_all = "kebab-case")]
pub struct DhcpEntryActive {
    #[serde(rename = "active-address")]
    pub address: IpAddr,
    #[serde(rename = "active-client-id")]
    pub client_id: Option<String>, // "1:42:66:19:96:42:d6",
    #[serde(rename = "active-mac-address")]
    pub mac_address: Option<eui48::MacAddress>, // "42:66:19:96:42:D6",
    #[serde(rename = "active-server")]
    pub active_server: String, // "mainDhcp",
    pub expires_after: String,
}