From a758db9bb4560b642c48bd889d10f95efcb9903f Mon Sep 17 00:00:00 2001 From: prplV Date: Thu, 27 Feb 2025 12:53:31 +0300 Subject: [PATCH] migration: structs --- crates/integr-structs/Cargo.toml | 1 + crates/integr-structs/src/api.rs | 136 ++++++++++++++++++++++++++++++- 2 files changed, 136 insertions(+), 1 deletion(-) diff --git a/crates/integr-structs/Cargo.toml b/crates/integr-structs/Cargo.toml index 9183deb..d510ba7 100644 --- a/crates/integr-structs/Cargo.toml +++ b/crates/integr-structs/Cargo.toml @@ -5,5 +5,6 @@ edition = "2021" [dependencies] anyhow = "1.0.95" +chrono = "0.4.40" serde = { version = "1.0.217", features = ["derive"] } serde_json = "1.0.135" diff --git a/crates/integr-structs/src/api.rs b/crates/integr-structs/src/api.rs index 4a824f0..a943b6e 100644 --- a/crates/integr-structs/src/api.rs +++ b/crates/integr-structs/src/api.rs @@ -1,9 +1,10 @@ -use core::sync; use std::collections::HashMap; use serde::{Serialize, Deserialize}; use serde_json::{ to_string_pretty, Value }; use anyhow::Result; use std::sync::Arc; +use std::fmt::Display; +use chrono::{DateTime, Local}; #[derive(Serialize, Deserialize, Debug)] @@ -273,4 +274,137 @@ pub mod v3 { str_metrics.len() } } +} + + +pub mod enode_monitoring { + use super::*; + + #[derive(Debug, Serialize)] + pub struct ForTokenCredentials { + login : String, + password : String, + pub ts : String, + } + + impl ForTokenCredentials { + pub fn new(login: &str, pass: &str) -> Self { + Self { + login : login.to_owned(), + password : pass.to_owned(), + ts : format!("{}", DateTime::timestamp(&Local::now())), + } + } + } + + pub mod cmdb { + use super::*; + + #[derive(Debug, Serialize)] + pub struct Query { + id : Vec, + data : Data, + #[serde(rename = "postQuery")] + post_query : String, + #[serde(rename = "enableActions")] + enable_actions : bool, + ts : usize + } + impl Default for Query { + fn default() -> Self { + Self { + id : vec!["/measures/device$18".to_owned()], + data : Data::default(), + post_query : "links".to_owned(), + enable_actions : false, + ts : 1740060679399 + } + } + } + #[derive(Debug, Serialize)] + struct Data { + links : Links, + fields : Vec, + } + impl Default for Data { + fn default() -> Self { + Self { + links : Links::default(), + fields : vec![ "$id".to_owned(), "id".to_owned(), "cls".to_owned(), "name".to_owned()] + } + } + } + #[derive(Debug, Serialize)] + struct Links { + flatten : bool, + filter : Filter, + } + impl Default for Links { + fn default() -> Self { + Self { + flatten : true, + filter : Filter::default() + } + } + } + #[derive(Debug, Serialize)] + struct Filter { + cls : String, + } + impl Default for Filter { + fn default() -> Self { + Self { + cls : "measure".to_owned() + } + } + } + } + + // "{\"access_token\":\"5BNQsmiGFQRNA651HeQxZekYgYUAWZ4e\",\"role\":\"administrator\",\"startRT\":\"2025-02-25T09:03:27.581Z\",\"login\":\"admin\",\"push_active\":null,\"$id\":\"systemuser$1\"}", + #[derive(Debug, Deserialize)] + pub struct AuthResponse { + pub access_token : String, + // role : String, + // startRT : String, + // login : String, + // push_active : Value, + // #[serde(rename = "$id")] + // id : String, + } + + pub trait GenericUrl { + fn display(&self) -> String; + } + + impl GenericUrl for [T] + where T : Display { + fn display(&self) -> String { + let mut vec: Vec = Vec::new(); + vec.push("%5B".to_owned()); + self.iter() + .enumerate() + .for_each(|(id, val)| { + if id > 0 { + vec.push(",".to_owned()); + } + vec.push(format!("%22{}%22", val)); + }); + vec.push("%5D".to_owned()); + vec.concat() + } + } + + pub fn get_chunk_size(total_measures: usize) -> usize { + match total_measures { + 0..=144 => total_measures, + 145..=288 => total_measures / 4, + 289..=432 => total_measures / 5, + 433..=576 => total_measures / 6, + 577..=720 => total_measures / 7, + 721..=864 => total_measures / 8, + 865..=1008 => total_measures / 9, + _ => total_measures / 10, + } + } + } \ No newline at end of file