From b30e940df7533a790cd5aea8d9810caed96095e7 Mon Sep 17 00:00:00 2001 From: prplV Date: Tue, 18 Feb 2025 16:06:41 +0300 Subject: [PATCH] egn user-agent + refactor --- .env.example | 6 ++---- crates/api-grub/Cargo.toml | 2 ++ crates/api-grub/src/net.rs | 20 ++++++++++++++------ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index 78b0f00..7a5d489 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,4 @@ -CONFIG_SERVER_CREDS = "ws://ip.ip.ip.ip:port" -API_GRUBBER_SOCKET = "api-grubber.sock" -PREPROC_SOCKET = "preproc.sock" +# Template .env for API grabber # PostgreSQL connection [DEPRECATED] DB_HOST = "ip.addr.postgresql.server" @@ -9,4 +7,4 @@ DB_PASSWORD = "db_user_password" DB_DBNAME = "db_name"1 # Prometheus-Exporter info -EXPORTER_URL = "ip.ip.ip.ip:port" \ No newline at end of file +EXPORTER_URL = "http(s)://ip.ip.ip.ip:port" \ No newline at end of file diff --git a/crates/api-grub/Cargo.toml b/crates/api-grub/Cargo.toml index cf61de9..f9d14ee 100644 --- a/crates/api-grub/Cargo.toml +++ b/crates/api-grub/Cargo.toml @@ -16,3 +16,5 @@ reqwest = { version = "0.12.12", features = ["rustls-tls", "json"] } deadpool-postgres = { version = "0.14.1", features = ["serde"] } tokio-postgres = "0.7.12" dotenv = "0.15.0" +md5 = "0.7.0" +rand = "0.9.0" diff --git a/crates/api-grub/src/net.rs b/crates/api-grub/src/net.rs index eb9425a..5434b6c 100644 --- a/crates/api-grub/src/net.rs +++ b/crates/api-grub/src/net.rs @@ -1,18 +1,20 @@ // module to handle unix-socket connection + pulling info from api -use anyhow::{Error, Result}; -use integr_structs::api::{ApiConfigV2, ProcessedEndpoint}; +use anyhow::Result; +// use integr_structs::api::{ApiConfigV2, ProcessedEndpoint}; use log::{error, info}; -use serde_json::Value; +use rand::random; use tokio::sync::mpsc::Receiver; use tokio::time::{sleep, Duration}; -use reqwest::{Client, Method, RequestBuilder}; +use reqwest::{Client, Method}; +use std::hash::{Hash, Hasher}; use std::sync::Arc; use tokio::task::JoinHandle; // use tokio::sync::Mutex; use dotenv::dotenv; use crate::json::JsonParser; -use crate::export::{self, Exporter}; +use crate::export::Exporter; use integr_structs::api::v3::{Config, ConfigEndpoint, Credentials, Metrics, PrometheusMetrics}; +use md5::compute; // type BufferType = Arc>>; @@ -96,8 +98,14 @@ impl<'a> ApiPoll<'a> { // let mut req = Client::new() // // .user_agent("api_grub/integration_module") // .get(&metrics.url); + use std::hash::DefaultHasher; + + let rand = random::(); + let mut hash = DefaultHasher::new(); + rand.hash(&mut hash); + let client = Client::builder() - .user_agent("api_grub/integration_module"); + .user_agent(format!("api-grabber-{}", hash.finish())); let mut req = client.build().unwrap().get(&metrics.url); let login = &creds.endpoint.login;