mirror of
https://codeberg.org/icewind/wifi-prometheus-exporter.git
synced 2026-06-03 16:44:11 +02:00
switch to iw
This commit is contained in:
parent
3ee65f7ca4
commit
8cd4806dc2
4 changed files with 19 additions and 13 deletions
|
|
@ -41,6 +41,7 @@ impl MqttConfig {
|
|||
#[derive(Debug, Deserialize)]
|
||||
pub struct SshConfig {
|
||||
pub address: String,
|
||||
pub user: String,
|
||||
pubkey_file: String,
|
||||
key_file: String,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ pub struct WifiLister {
|
|||
impl WifiLister {
|
||||
pub fn new<A: ToSocketAddrs + Debug>(
|
||||
addr: A,
|
||||
user: &str,
|
||||
key: &str,
|
||||
pubkey: &str,
|
||||
interfaces: &[String],
|
||||
|
|
@ -23,18 +24,14 @@ impl WifiLister {
|
|||
session.set_tcp_stream(tcp);
|
||||
session.handshake().map_err(Error::SshSession)?;
|
||||
session
|
||||
.userauth_pubkey_memory("admin", Some(pubkey), key, None)
|
||||
.userauth_pubkey_memory(user, Some(pubkey), key, None)
|
||||
.map_err(Error::SshAuth)?;
|
||||
|
||||
let command = if interfaces.is_empty() {
|
||||
"wl assoclist".to_string()
|
||||
} else {
|
||||
let commands: Vec<String> = interfaces
|
||||
.iter()
|
||||
.map(|interface| format!("wl -a {} assoclist", interface))
|
||||
.collect();
|
||||
commands.join(" && ")
|
||||
};
|
||||
let commands: Vec<String> = interfaces
|
||||
.iter()
|
||||
.map(|interface| format!("iw dev {} station dump", interface))
|
||||
.collect();
|
||||
let command = commands.join(" && ");
|
||||
|
||||
info!("ssh connected");
|
||||
|
||||
|
|
@ -55,7 +52,9 @@ impl WifiLister {
|
|||
channel.wait_close()?;
|
||||
|
||||
Ok(s.lines()
|
||||
.map(|s| s.trim_start_matches("assoclist ").to_string())
|
||||
.filter(|s| s.starts_with("Station"))
|
||||
.filter_map(|s| s.split(' ').nth(1))
|
||||
.map(String::from)
|
||||
.collect())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ async fn main() -> Result<(), MainError> {
|
|||
};
|
||||
|
||||
if config.exporter.interfaces.is_empty() {
|
||||
info!("Listening on default interface");
|
||||
error!("No interfaces specified");
|
||||
return Ok(());
|
||||
} else {
|
||||
info!(
|
||||
"Listening on interfaces: {}",
|
||||
|
|
@ -54,6 +55,7 @@ async fn main() -> Result<(), MainError> {
|
|||
let connected: Arc<Mutex<DeviceStates>> = Default::default();
|
||||
let wifi_listener = WifiLister::new(
|
||||
&config.ssh.address,
|
||||
&config.ssh.user,
|
||||
&config.ssh.key()?,
|
||||
&config.ssh.pubkey()?,
|
||||
&config.exporter.interfaces,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue