1
0
Fork 0
mirror of https://codeberg.org/icewind/prometheus-mdns-rs.git synced 2026-06-03 18:04:11 +02:00

Accept service name on cmdline

This commit is contained in:
Taras Glek 2022-11-24 11:42:16 +00:00
commit b597ee84e9

View file

@ -9,9 +9,6 @@ use std::net::SocketAddr;
use std::time::Duration; use std::time::Duration;
use std::time::Instant; use std::time::Instant;
/// The hostname of the devices we are searching for.
const SERVICE_NAME: &str = "_prometheus-http._tcp.local";
struct Service { struct Service {
labels: HashMap<String, String>, labels: HashMap<String, String>,
addr: SocketAddr, addr: SocketAddr,
@ -42,7 +39,11 @@ async fn main() -> Result<(), main_error::MainError> {
.nth(1) .nth(1)
.map(|path| AtomicFile::new(path, AllowOverwrite)); .map(|path| AtomicFile::new(path, AllowOverwrite));
let stream = mdns::discover::all(SERVICE_NAME, INTERVAL)?.listen(); let service_name: &str = &env::args()
.nth(2)
.unwrap_or("_prometheus-http._tcp.local".to_string());
let stream = mdns::discover::all(service_name, INTERVAL)?.listen();
pin_mut!(stream); pin_mut!(stream);
let mut services: HashMap<SocketAddr, Service> = HashMap::new(); let mut services: HashMap<SocketAddr, Service> = HashMap::new();