migration: structs

pull/6/head
prplV 2025-02-27 12:53:31 +03:00
parent 6228b2393d
commit a758db9bb4
2 changed files with 136 additions and 1 deletions

View File

@ -5,5 +5,6 @@ edition = "2021"
[dependencies] [dependencies]
anyhow = "1.0.95" anyhow = "1.0.95"
chrono = "0.4.40"
serde = { version = "1.0.217", features = ["derive"] } serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.135" serde_json = "1.0.135"

View File

@ -1,9 +1,10 @@
use core::sync;
use std::collections::HashMap; use std::collections::HashMap;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use serde_json::{ to_string_pretty, Value }; use serde_json::{ to_string_pretty, Value };
use anyhow::Result; use anyhow::Result;
use std::sync::Arc; use std::sync::Arc;
use std::fmt::Display;
use chrono::{DateTime, Local};
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
@ -274,3 +275,136 @@ pub mod v3 {
} }
} }
} }
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<String>,
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<String>,
}
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<T> GenericUrl for [T]
where T : Display {
fn display(&self) -> String {
let mut vec: Vec<String> = 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,
}
}
}