+ api token + ref #43
11
.env.example
11
.env.example
|
|
@ -1,15 +1,18 @@
|
||||||
# Template .env for API grabber
|
# Template .env for API grabber
|
||||||
|
|
||||||
# PostgreSQL connection [DEPRECATED]
|
# PostgreSQL connection [DEPRECATED]
|
||||||
|
# -------------------------------
|
||||||
DB_HOST = "ip.addr.postgresql.server"
|
DB_HOST = "ip.addr.postgresql.server"
|
||||||
DB_USER = "db_user"
|
DB_USER = "db_user"
|
||||||
DB_PASSWORD = "db_user_password"
|
DB_PASSWORD = "db_user_password"
|
||||||
DB_DBNAME = "db_name"1
|
DB_DBNAME = "db_name"1
|
||||||
|
|
||||||
# Prometheus-Exporter info
|
# Prometheus-Exporter info
|
||||||
|
# -------------------------------
|
||||||
EXPORTER_URL = "http(s)://ip.ip.ip.ip:port"
|
EXPORTER_URL = "http(s)://ip.ip.ip.ip:port"
|
||||||
|
|
||||||
# VINTEO Jitter puller (needed to init Jitter native grab)
|
# VINTEO Jitter puller (needed to init Jitter native grab)
|
||||||
|
# -------------------------------
|
||||||
VINTEO_URL_BASE = "http(s)://ip.ip.ip.ip:port"
|
VINTEO_URL_BASE = "http(s)://ip.ip.ip.ip:port"
|
||||||
VINTEO_ENDPOINT_CONFERENCES = "/api/v1/to/something"
|
VINTEO_ENDPOINT_CONFERENCES = "/api/v1/to/something"
|
||||||
VINTEO_ENDPOINT_PARTICIPANTS = "/api/v1/to/something"
|
VINTEO_ENDPOINT_PARTICIPANTS = "/api/v1/to/something"
|
||||||
|
|
@ -20,11 +23,19 @@ VINTEO_API_KEY = "6fe8b0db-62b4-4065-9c1e-441ec4228341.9acec20bd17d7178f332896f8
|
||||||
STATUS_SYSTEM_URL = "http://192.168.2.39:9999/api/input"
|
STATUS_SYSTEM_URL = "http://192.168.2.39:9999/api/input"
|
||||||
|
|
||||||
# eNODE.Monitoring configuration
|
# eNODE.Monitoring configuration
|
||||||
|
# -------------------------------
|
||||||
|
# eNODE.Monitoring server IP
|
||||||
ENODE_MONITORING_IP = "ip.ip.ip.ip"
|
ENODE_MONITORING_IP = "ip.ip.ip.ip"
|
||||||
|
# eNODE.Monitoring credentials
|
||||||
ENODE_MONITORING_LOGIN = "admin_user_enode_monitoring" # admin user is required
|
ENODE_MONITORING_LOGIN = "admin_user_enode_monitoring" # admin user is required
|
||||||
ENODE_MONITORING_PASSWORD = "admin_password_enode_monitoring" # # admin password is required
|
ENODE_MONITORING_PASSWORD = "admin_password_enode_monitoring" # # admin password is required
|
||||||
|
# List of target devices
|
||||||
ENODE_TARGET_DEVICES = "18, 19"
|
ENODE_TARGET_DEVICES = "18, 19"
|
||||||
|
# to work with unlimit API-Token
|
||||||
|
ENODE_API_TOKEN = "sssswwwwaaaaffff"
|
||||||
|
|
||||||
|
# OPTIONAL SETTINGS
|
||||||
|
# -------------------------------
|
||||||
# IM configuration for max level of logging info
|
# IM configuration for max level of logging info
|
||||||
# for example DEBUG, INFO, WARN, ERROR, TRACE
|
# for example DEBUG, INFO, WARN, ERROR, TRACE
|
||||||
IM_LOG_INFO = "INFO"
|
IM_LOG_INFO = "INFO"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{collections::{HashMap, HashSet}, future::Future};
|
use std::collections::{HashMap, HashSet};
|
||||||
use integr_structs::api::v3::{PrometheusMetricsExtended, MetricOutputExtended};
|
use integr_structs::api::v3::{PrometheusMetricsExtended, MetricOutputExtended};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use chrono::Local;
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -183,6 +183,7 @@ pub struct MonitoringImporter {
|
||||||
login : String,
|
login : String,
|
||||||
password : String,
|
password : String,
|
||||||
access_token : String,
|
access_token : String,
|
||||||
|
api_token : String,
|
||||||
ts : String,
|
ts : String,
|
||||||
timeout : usize,
|
timeout : usize,
|
||||||
}
|
}
|
||||||
|
|
@ -205,6 +206,7 @@ impl MonitoringImporter {
|
||||||
login : env::var("ENODE_MONITORING_LOGIN").unwrap_or_else(|_| String::new()),
|
login : env::var("ENODE_MONITORING_LOGIN").unwrap_or_else(|_| String::new()),
|
||||||
password : env::var("ENODE_MONITORING_PASSWORD").unwrap_or_else(|_| String::new()),
|
password : env::var("ENODE_MONITORING_PASSWORD").unwrap_or_else(|_| String::new()),
|
||||||
access_token : String::new(),
|
access_token : String::new(),
|
||||||
|
api_token : env::var("ENODE_API_TOKEN").unwrap_or_else(|_| String::new()),
|
||||||
ts : String::new(),
|
ts : String::new(),
|
||||||
timeout : std::env::var("IM_CONNECTION_TIMEOUT").unwrap_or_else(|_| "10".to_string()).parse().unwrap_or_else(|_| 10)
|
timeout : std::env::var("IM_CONNECTION_TIMEOUT").unwrap_or_else(|_| "10".to_string()).parse().unwrap_or_else(|_| 10)
|
||||||
}
|
}
|
||||||
|
|
@ -213,7 +215,13 @@ impl MonitoringImporter {
|
||||||
/// and can be used to pull and push info to and from CM
|
/// and can be used to pull and push info to and from CM
|
||||||
///
|
///
|
||||||
async fn is_valid(&self) -> bool {
|
async fn is_valid(&self) -> bool {
|
||||||
!self.ip.is_empty() && !self.login.is_empty() && !self.password.is_empty()
|
!self.ip.is_empty() && ((!self.login.is_empty() && !self.password.is_empty() ) || !self.api_token.is_empty())
|
||||||
|
}
|
||||||
|
/// Function that checks is current `MonitoringImporter` valid
|
||||||
|
/// and can be used to pull and push info to and from CM
|
||||||
|
///
|
||||||
|
async fn is_minimal(&self) -> bool {
|
||||||
|
(self.login.is_empty() || self.password.is_empty()) && !self.api_token.is_empty()
|
||||||
}
|
}
|
||||||
/// A setter of `timestamp`
|
/// A setter of `timestamp`
|
||||||
///
|
///
|
||||||
|
|
@ -235,8 +243,15 @@ impl MonitoringImporter {
|
||||||
#[tracing::instrument(name = "cm_fn_session_start", skip_all)]
|
#[tracing::instrument(name = "cm_fn_session_start", skip_all)]
|
||||||
pub async fn start_session(&mut self) -> anyhow::Result<()> {
|
pub async fn start_session(&mut self) -> anyhow::Result<()> {
|
||||||
if !self.is_valid().await {
|
if !self.is_valid().await {
|
||||||
|
if self.is_minimal().await {
|
||||||
|
return Err(Error::msg(format!("Given API-Token is no more actual now ({})", &self.access_token)));
|
||||||
|
}
|
||||||
return Err(Error::msg("Invalid eNODE-Monitoring configuration"));
|
return Err(Error::msg("Invalid eNODE-Monitoring configuration"));
|
||||||
}
|
}
|
||||||
|
if !self.api_token.is_empty() {
|
||||||
|
std::mem::swap(&mut self.access_token, &mut self.api_token);
|
||||||
|
info!("API-Token that was in the ENODE configuration was set as access-token");
|
||||||
|
} else {
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
let url = format!("http://{}/e-data-front/auth/login", self.ip);
|
let url = format!("http://{}/e-data-front/auth/login", self.ip);
|
||||||
let fortoken = ForTokenCredentials::new(&self.login, &self.password);
|
let fortoken = ForTokenCredentials::new(&self.login, &self.password);
|
||||||
|
|
@ -248,10 +263,7 @@ impl MonitoringImporter {
|
||||||
.timeout(tokio::time::Duration::from_secs(self.timeout as u64))
|
.timeout(tokio::time::Duration::from_secs(self.timeout as u64))
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
.json(&fortoken);
|
.json(&fortoken);
|
||||||
// let resp = client.send().await?;
|
|
||||||
if let Ok(resp) = client.send().await {
|
if let Ok(resp) = client.send().await {
|
||||||
// let auth = resp.json::<AuthResponse>().await?;
|
|
||||||
|
|
||||||
match resp.json::<AuthResponse>().await {
|
match resp.json::<AuthResponse>().await {
|
||||||
Ok(auth) => {
|
Ok(auth) => {
|
||||||
self.set_ts(&fortoken.ts).await;
|
self.set_ts(&fortoken.ts).await;
|
||||||
|
|
@ -267,6 +279,7 @@ impl MonitoringImporter {
|
||||||
delay = delay * 2;
|
delay = delay * 2;
|
||||||
}
|
}
|
||||||
info!("Started a new CM session");
|
info!("Started a new CM session");
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue