From faaf9c9bbae08c0c334584ca0827b6fd5ed484db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Arnauts?= Date: Thu, 27 Oct 2022 13:41:47 +0200 Subject: [PATCH 1/2] Use Domain ID when fetching the device list from netshot --- README.md | 3 ++- src/main.rs | 2 +- src/rest/netbox.rs | 2 +- src/rest/netshot.rs | 6 ++++-- 4 files changed, 8 insertions(+), 5 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..8860d4d 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()); From a028b904a24bf9636ec678645a8068288ffac878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Arnauts?= Date: Thu, 27 Oct 2022 13:51:50 +0200 Subject: [PATCH 2/2] Fix test --- src/rest/netshot.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rest/netshot.rs b/src/rest/netshot.rs index 8860d4d..119d43c 100644 --- a/src/rest/netshot.rs +++ b/src/rest/netshot.rs @@ -293,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);