From a6fb23197f23d5e6af3d924e3d694e182a256131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Arnauts?= Date: Wed, 9 Nov 2022 18:15:23 +0100 Subject: [PATCH] Use Domain ID when fetching the device list from netshot (#10) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michaƫl Arnauts --- README.md | 3 ++- src/main.rs | 2 +- src/rest/netbox.rs | 2 +- src/rest/netshot.rs | 8 +++++--- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 29ab16a..07fbb09 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,8 @@ OPTIONS: The Netshot token [env: NETSHOT_TOKEN] --netshot-url - The Netshot API URL [env: NETSHOT_URL=]``` + The Netshot API URL [env: NETSHOT_URL=] +``` The query-string format need to be like this (url query string without the `?`): diff --git a/src/main.rs b/src/main.rs index e61e2c5..8655e12 100644 --- a/src/main.rs +++ b/src/main.rs @@ -119,7 +119,7 @@ fn main() -> Result<(), Error> { netshot_client.ping()?; log::info!("Getting devices list from Netshot"); - let netshot_devices = netshot_client.get_devices()?; + let netshot_devices = netshot_client.get_devices(opt.netshot_domain_id)?; let netshot_disabled_devices: Vec<&netshot::Device> = netshot_devices .iter() diff --git a/src/rest/netbox.rs b/src/rest/netbox.rs index 3bac355..64cc7a7 100644 --- a/src/rest/netbox.rs +++ b/src/rest/netbox.rs @@ -35,7 +35,7 @@ pub struct Device { pub primary_ip4: Option, } -/// Represent the API response from /api/devim/devices call +/// Represent the API response from /api/dcim/devices call #[derive(Debug, Serialize, Deserialize)] pub struct NetboxDCIMDeviceList { count: u32, diff --git a/src/rest/netshot.rs b/src/rest/netshot.rs index d2130f5..119d43c 100644 --- a/src/rest/netshot.rs +++ b/src/rest/netshot.rs @@ -121,8 +121,10 @@ impl NetshotClient { } /// Get devices registered in Netshot - pub fn get_devices(&self) -> Result, Error> { - let url = format!("{}{}", self.url, PATH_DEVICES); + pub fn get_devices(&self, + domain_id: u32, + ) -> Result, Error> { + let url = format!("{}{}?group={}", self.url, PATH_DEVICES, domain_id); let devices: Vec = self.client.get(url).send()?.json()?; log::debug!("Got {} devices from Netshot", devices.len()); @@ -291,7 +293,7 @@ mod tests { .create(); let client = NetshotClient::new(url.clone(), String::new(), None, None, None).unwrap(); - let devices = client.get_devices().unwrap(); + let devices = client.get_devices(1).unwrap(); assert_eq!(devices.len(), 1);