From 5a1588e2565b1ebf40a5742140ea2ca678259517 Mon Sep 17 00:00:00 2001 From: prplV Date: Wed, 18 Dec 2024 10:32:11 +0300 Subject: [PATCH 01/14] config_path unwrapping mechanism --- noxis-rs/src/options/config.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/noxis-rs/src/options/config.rs b/noxis-rs/src/options/config.rs index f7b5f26..acc8d81 100644 --- a/noxis-rs/src/options/config.rs +++ b/noxis-rs/src/options/config.rs @@ -51,7 +51,10 @@ fn load_processes(json_filename: &str) -> Option { pub async fn get_actual_config(params : Arc) -> Option { // * if no local conf -> loop and +inf getting conf from redis server // * if local conf -> once getting conf from redis server - let config_path = params.config.to_str()?; + let config_path = params.config.to_str().unwrap_or_else(|| { + error!("Invalid character in config file. Config path was set as default"); + "settings.json" + }); info!("Configurating config module with params: no-remote-config={}, no-sub={}, local config path={:?}, remote server={}", params.no_remote_config, params.no_sub, params.config, params.remote_server_url); match load_processes(config_path) { Some(local_conf) => { -- 2.40.1 From 1578216712c7e13a32ea9d5795649c2d9ce42478 Mon Sep 17 00:00:00 2001 From: prplV Date: Wed, 18 Dec 2024 10:55:13 +0300 Subject: [PATCH 02/14] [ISSUE#12 "preload errors without returning !!!!"] preload params validation mech fix --- noxis-rs/src/options/config.rs | 2 +- noxis-rs/src/options/preboot.rs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/noxis-rs/src/options/config.rs b/noxis-rs/src/options/config.rs index acc8d81..92ac033 100644 --- a/noxis-rs/src/options/config.rs +++ b/noxis-rs/src/options/config.rs @@ -52,7 +52,7 @@ pub async fn get_actual_config(params : Arc) -> Option // * if no local conf -> loop and +inf getting conf from redis server // * if local conf -> once getting conf from redis server let config_path = params.config.to_str().unwrap_or_else(|| { - error!("Invalid character in config file. Config path was set as default"); + error!("Invalid character in config file. Config path was set to default"); "settings.json" }); info!("Configurating config module with params: no-remote-config={}, no-sub={}, local config path={:?}, remote server={}", params.no_remote_config, params.no_sub, params.config, params.remote_server_url); diff --git a/noxis-rs/src/options/preboot.rs b/noxis-rs/src/options/preboot.rs index 02e013f..10e030f 100644 --- a/noxis-rs/src/options/preboot.rs +++ b/noxis-rs/src/options/preboot.rs @@ -102,19 +102,26 @@ pub struct PrebootParams { } impl PrebootParams { - pub fn validate(self) -> Result { + pub fn validate(mut self) -> Result { if !self.socket_path.exists() && !self.no_hostagent { - return Err(Error::msg("Socket-file not found or Noxis can't read it. Cannot start")); + eprintln!("Error: Socket-file not found or Noxis can't read it. Socket-file was set to default"); + self.socket_path = PathBuf::from("/var/run/enode/hostagent.sock"); + // return Err(Error::msg("Socket-file not found or Noxis can't read it. Cannot start")); } // existing log dir if !self.log_to.exists() && !self.no_logs { - return Err(Error::msg("Log Directory Not Found or Noxis can't read it. Cannot start")); + eprintln!("Error: LogDir not found or Noxis can't read it. LogDir was set to default"); + self.log_to = PathBuf::from("./"); + // return Err(Error::msg("Log Directory Not Found or Noxis can't read it. Cannot start")); } // existing sock file if !self.config.exists() { - return Err(Error::msg("Local Config Not Found or Noxis can't read it. Cannot start")); + eprintln!("Error: Invalid character in config file. Config path was set to default"); + self.config = PathBuf::from("settings.json"); + // return Err(Error::msg("Local Config Not Found or Noxis can't read it. Cannot start")); } // redis server check + dbg!(&self); Ok(self) } } -- 2.40.1 From 7be46d437309c2e6b925b7499257f384c697f921 Mon Sep 17 00:00:00 2001 From: prplV Date: Wed, 18 Dec 2024 11:02:49 +0300 Subject: [PATCH 03/14] no warn in preboot.rs and config.rs + no dbg --- noxis-rs/src/options/config.rs | 2 +- noxis-rs/src/options/preboot.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/noxis-rs/src/options/config.rs b/noxis-rs/src/options/config.rs index 92ac033..65b4731 100644 --- a/noxis-rs/src/options/config.rs +++ b/noxis-rs/src/options/config.rs @@ -7,7 +7,7 @@ use std::os::unix::process::CommandExt; use std::process::Command; use std::sync::Arc; use std::{env, fs}; -use std::fmt::format; +// use std::fmt::format; use super::preboot::PrebootParams; use tokio::time::{Duration, sleep}; diff --git a/noxis-rs/src/options/preboot.rs b/noxis-rs/src/options/preboot.rs index 10e030f..90c8102 100644 --- a/noxis-rs/src/options/preboot.rs +++ b/noxis-rs/src/options/preboot.rs @@ -1,4 +1,5 @@ // module to handle pre-boot params of the monitor +#[allow(unused_imports)] use anyhow::{Result, Ok, Error}; use clap::Parser; use std::path::PathBuf; @@ -110,7 +111,7 @@ impl PrebootParams { } // existing log dir if !self.log_to.exists() && !self.no_logs { - eprintln!("Error: LogDir not found or Noxis can't read it. LogDir was set to default"); + eprintln!("Error: Log-Dir not found or Noxis can't read it. LogDir was set to default"); self.log_to = PathBuf::from("./"); // return Err(Error::msg("Log Directory Not Found or Noxis can't read it. Cannot start")); } @@ -121,7 +122,6 @@ impl PrebootParams { // return Err(Error::msg("Local Config Not Found or Noxis can't read it. Cannot start")); } // redis server check - dbg!(&self); Ok(self) } } @@ -134,7 +134,7 @@ mod preboot_unitests{ #[test] fn parsing_zero_args() { - assert!(PrebootParams::try_parse_from(vec!["runner-rs"]).is_ok()) + assert!(PrebootParams::try_parse_from(vec!["runner-rs"]).is_ok()) } #[test] fn parsing_hagent_valid_args() { -- 2.40.1 From 97bc91ffcdcbb6d5322d43fb4cdea41ad950bc98 Mon Sep 17 00:00:00 2001 From: prplV Date: Mon, 23 Dec 2024 09:44:53 +0300 Subject: [PATCH 04/14] added cli_pipeline doc-comms --- noxis-rs/src/options/cli_pipeline.rs | 40 +++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/noxis-rs/src/options/cli_pipeline.rs b/noxis-rs/src/options/cli_pipeline.rs index b189a36..1b73624 100644 --- a/noxis-rs/src/options/cli_pipeline.rs +++ b/noxis-rs/src/options/cli_pipeline.rs @@ -6,7 +6,19 @@ use std::{borrow::BorrowMut, net::{IpAddr, Ipv4Addr}}; // use std::io::BufReader; use tokio::io::{BufReader, AsyncWriteExt, AsyncBufReadExt}; - +/// # Fn `init_cli_pipeline` +/// ## for catching all input requests from CLI +/// +/// *input* : - +/// +/// *output* : `anyhow::Result<()>` to wrap errors +/// +/// *initiator* : fn `main` +/// +/// *managing* : `TcpListener` object to handle requests +/// +/// *depends on* : - +/// pub async fn init_cli_pipeline() -> DynResult<()> { return match init_listener().await { Some(list) => { @@ -27,6 +39,19 @@ pub async fn init_cli_pipeline() -> DynResult<()> { } } +/// # Fn `init_listener` +/// ## for creating TCP-listener for communicating with CLI +/// +/// *input* : - +/// +/// *output* : `Some` if port 7753 was opened | None if not +/// +/// *initiator* : fn `init_cli_pipeline` +/// +/// *managing* : `TcpListener` object to handle requests +/// +/// *depends on* : `tokio::net::TcpListener` +/// async fn init_listener() -> Option { return match TcpListener::bind("127.0.0.1:7753").await { Ok(listener) => { @@ -40,6 +65,19 @@ async fn init_listener() -> Option { } } +/// # Fn `process_connection` +/// ## for processing input CLI requests +/// +/// *input* : mut stream: `TcpStream` +/// +/// *output* : - +/// +/// *initiator* : fn `init_cli_pipeline` +/// +/// *managing* : mutable object of `TcpStream` +/// +/// *depends on* : `tokio::net::TcpStream` +/// async fn process_connection(mut stream: TcpStream) { // loop{ // stream. -- 2.40.1 From 939bdc6676f0ac8196699d3ba4ed93fe8176bac0 Mon Sep 17 00:00:00 2001 From: prplV Date: Mon, 23 Dec 2024 14:07:22 +0300 Subject: [PATCH 05/14] added preboot doc-comms --- noxis-rs/src/options/preboot.rs | 81 +++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/noxis-rs/src/options/preboot.rs b/noxis-rs/src/options/preboot.rs index 90c8102..47f2d79 100644 --- a/noxis-rs/src/options/preboot.rs +++ b/noxis-rs/src/options/preboot.rs @@ -4,6 +4,18 @@ use anyhow::{Result, Ok, Error}; use clap::Parser; use std::path::PathBuf; +/// # Enum `MetricsPrebootParams` +/// ## for setting up metrics mode as preboot param from command prompt +/// +/// examples: +/// ``` +/// noxis-rs ... --metrics full +/// noxis-rs ... --metrics system +/// noxis-rs ... --metrics processes +/// noxis-rs ... --metrics net +/// noxis-rs ... --metrics none +/// ``` +/// #[derive(clap::ValueEnum, Debug, Clone)] pub enum MetricsPrebootParams { Full, @@ -13,6 +25,8 @@ pub enum MetricsPrebootParams { None, } +/// # `std::fmt::Display` implementation for `MetricsPrebootParams` +/// ## to enable parsing object to String impl std::fmt::Display for MetricsPrebootParams { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self { @@ -25,6 +39,71 @@ impl std::fmt::Display for MetricsPrebootParams { } } +/// # struct `PrebootParams` +/// ## to parse and set up all modes as preboot params from command prompt +/// +/// ### args : +/// +/// `--no-hagent` - to disable hagent work module and set up work mode as autonomous +/// ### usage : +/// ``` +/// noxis-rs ... --no-hagent ... +/// ``` +/// +/// +/// `--no-logs` - to disable logging at all +/// ### usage : +/// ``` +/// noxis-rs ... --no-logs ... +/// ``` +/// +/// `--refresh-logs` - to truncate logs directory +/// ### usage : +/// ``` +/// noxis-rs ... --refresh-logs ... +/// ``` +/// +/// `--no-remote-config` - to disable work with Redis as config producer +/// ### usage : +/// ``` +/// noxis-rs ... --no-remote-config ... +/// ``` +/// +/// `--no-sub` - to disable Redis subscribtion mechanism +/// ### usage : +/// ``` +/// noxis-rs ... --no-sub ... +/// ``` +/// +/// `--socket-path` - to set Unix Domain Socket file's directory +/// ### usage : +/// ``` +/// noxis-rs ... --no-sub ... +/// ``` +/// +/// `--log-to` - to set directory for logs +/// ### usage : +/// ``` +/// noxis-rs ... --log-to /dir/to/logs/ ... +/// ``` +/// +/// `--remote-server-url` - to set Redis Server +/// ### usage : +/// ``` +/// noxis-rs ... --remote-server-url 192.168.28.12 ... +/// ``` +/// +/// `--config` - to set Noxis' config full path +/// ### usage : +/// ``` +/// noxis-rs ... --config /etc/enode/settings.json ... +/// ``` +/// +/// `--metrics` - to set metrics mode +/// ### usage : +/// ``` +/// noxis-rs ... --metrics full ... +/// ``` #[derive(Debug, Parser)] pub struct PrebootParams { // actions @@ -102,6 +181,8 @@ pub struct PrebootParams { pub metrics: MetricsPrebootParams, } +/// # implementation for `MetricsPrebootParams` +/// ## to enable validation mechanism impl PrebootParams { pub fn validate(mut self) -> Result { if !self.socket_path.exists() && !self.no_hostagent { -- 2.40.1 From c03981186aaeb4bd6eea2689011f14aba697efd1 Mon Sep 17 00:00:00 2001 From: prplV Date: Mon, 23 Dec 2024 14:34:47 +0300 Subject: [PATCH 06/14] preboot doc-comms fix --- noxis-rs/src/options/preboot.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/noxis-rs/src/options/preboot.rs b/noxis-rs/src/options/preboot.rs index 47f2d79..58ab6a3 100644 --- a/noxis-rs/src/options/preboot.rs +++ b/noxis-rs/src/options/preboot.rs @@ -46,62 +46,62 @@ impl std::fmt::Display for MetricsPrebootParams { /// /// `--no-hagent` - to disable hagent work module and set up work mode as autonomous /// ### usage : -/// ``` +/// ``` bash /// noxis-rs ... --no-hagent ... /// ``` /// /// /// `--no-logs` - to disable logging at all /// ### usage : -/// ``` +/// ``` bash /// noxis-rs ... --no-logs ... /// ``` /// /// `--refresh-logs` - to truncate logs directory /// ### usage : -/// ``` +/// ``` bash /// noxis-rs ... --refresh-logs ... /// ``` /// /// `--no-remote-config` - to disable work with Redis as config producer /// ### usage : -/// ``` +/// ``` bash /// noxis-rs ... --no-remote-config ... /// ``` /// /// `--no-sub` - to disable Redis subscribtion mechanism /// ### usage : -/// ``` +/// ``` bash /// noxis-rs ... --no-sub ... /// ``` /// /// `--socket-path` - to set Unix Domain Socket file's directory /// ### usage : -/// ``` +/// ``` bash /// noxis-rs ... --no-sub ... /// ``` /// /// `--log-to` - to set directory for logs /// ### usage : -/// ``` +/// ``` bash /// noxis-rs ... --log-to /dir/to/logs/ ... /// ``` /// /// `--remote-server-url` - to set Redis Server /// ### usage : -/// ``` +/// ``` bash /// noxis-rs ... --remote-server-url 192.168.28.12 ... /// ``` /// /// `--config` - to set Noxis' config full path /// ### usage : -/// ``` +/// ``` bash /// noxis-rs ... --config /etc/enode/settings.json ... /// ``` /// /// `--metrics` - to set metrics mode /// ### usage : -/// ``` +/// ``` bash /// noxis-rs ... --metrics full ... /// ``` #[derive(Debug, Parser)] -- 2.40.1 From 426e2878669ebd281e1b07d37f667e7bf683f30b Mon Sep 17 00:00:00 2001 From: prplV Date: Mon, 23 Dec 2024 15:02:51 +0300 Subject: [PATCH 07/14] fix#2 --- noxis-rs/src/options/preboot.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxis-rs/src/options/preboot.rs b/noxis-rs/src/options/preboot.rs index 58ab6a3..6a02ee3 100644 --- a/noxis-rs/src/options/preboot.rs +++ b/noxis-rs/src/options/preboot.rs @@ -78,7 +78,7 @@ impl std::fmt::Display for MetricsPrebootParams { /// `--socket-path` - to set Unix Domain Socket file's directory /// ### usage : /// ``` bash -/// noxis-rs ... --no-sub ... +/// noxis-rs ... --socket-path /var/run/enode/hostagent.sock ... /// ``` /// /// `--log-to` - to set directory for logs -- 2.40.1 From ce067efffd8cd7ac1386c51389b9e4f1611309c1 Mon Sep 17 00:00:00 2001 From: prplV Date: Mon, 23 Dec 2024 17:35:23 +0300 Subject: [PATCH 08/14] ISSUE#16 --- noxis-rs/src/utils.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/noxis-rs/src/utils.rs b/noxis-rs/src/utils.rs index 86e63f5..9ead34d 100644 --- a/noxis-rs/src/utils.rs +++ b/noxis-rs/src/utils.rs @@ -156,7 +156,7 @@ async fn process_protocol_symbol(proc: Arc, val: u8) -> Result< // }, // 101 - Impermissible trigger values in JSON 101 => { - error!("Impermissible trigger values in JSON in {}'s block. Killing thread...", proc.name); + error!("Impermissible trigger values in JSON in {}'s block. Killing thread...", &proc.name); if is_active(&proc.name).await { terminate_process(&proc.name).await; } @@ -164,9 +164,10 @@ async fn process_protocol_symbol(proc: Arc, val: u8) -> Result< }, // // 121 - Cannot create valid watcher for file dependency + // todo : think about valid situation 121 => { - error!("Cannot create valid watcher for {}'s file dependency. Terminating thread...", proc.name); - let _ = terminate_process("runner-rs").await; + error!("Cannot create valid watcher for file dependency. Terminating {} process...", &proc.name); + let _ = terminate_process(&proc.name).await; return Err(CustomError::Fatal) }, // 111 - global thread termination with killing current child in a face -- 2.40.1 From 8b123cd59319cf9ba77109ed7f9cfa2d870a7c5e Mon Sep 17 00:00:00 2001 From: prplV Date: Fri, 27 Dec 2024 13:47:54 +0300 Subject: [PATCH 09/14] import refactor --- noxis-rs/src/options/cli_pipeline.rs | 7 ++----- noxis-rs/src/options/config.rs | 2 +- noxis-rs/src/options/signals.rs | 2 +- noxis-rs/src/utils/files.rs | 2 +- noxis-rs/src/utils/metrics.rs | 2 +- noxis-rs/src/utils/services.rs | 2 +- 6 files changed, 7 insertions(+), 10 deletions(-) diff --git a/noxis-rs/src/options/cli_pipeline.rs b/noxis-rs/src/options/cli_pipeline.rs index 1b73624..3b9897c 100644 --- a/noxis-rs/src/options/cli_pipeline.rs +++ b/noxis-rs/src/options/cli_pipeline.rs @@ -20,7 +20,7 @@ use tokio::io::{BufReader, AsyncWriteExt, AsyncBufReadExt}; /// *depends on* : - /// pub async fn init_cli_pipeline() -> DynResult<()> { - return match init_listener().await { + match init_listener().await { Some(list) => { loop { if let Ok((socket, addr)) = list.accept().await { @@ -53,7 +53,7 @@ pub async fn init_cli_pipeline() -> DynResult<()> { /// *depends on* : `tokio::net::TcpListener` /// async fn init_listener() -> Option { - return match TcpListener::bind("127.0.0.1:7753").await { + match TcpListener::bind("127.0.0.1:7753").await { Ok(listener) => { info!("Runner is listening localhost:7753"); Some(listener) @@ -79,9 +79,6 @@ async fn init_listener() -> Option { /// *depends on* : `tokio::net::TcpStream` /// async fn process_connection(mut stream: TcpStream) { - // loop{ - // stream. - // } let buf_reader = BufReader::new(stream.borrow_mut()); let mut rqst = buf_reader.lines(); diff --git a/noxis-rs/src/options/config.rs b/noxis-rs/src/options/config.rs index 65b4731..5ebe5bb 100644 --- a/noxis-rs/src/options/config.rs +++ b/noxis-rs/src/options/config.rs @@ -1,4 +1,4 @@ -use crate::options::structs::*; +use super::structs::*; use log::{error, info, warn}; use redis::{Client, Connection}; use std::fs::OpenOptions; diff --git a/noxis-rs/src/options/signals.rs b/noxis-rs/src/options/signals.rs index c107c74..7604bde 100644 --- a/noxis-rs/src/options/signals.rs +++ b/noxis-rs/src/options/signals.rs @@ -1,4 +1,4 @@ -use crate::options::structs::CustomError; +use super::structs::CustomError; use std::sync::Arc; use tokio::io; use tokio::sync::mpsc; diff --git a/noxis-rs/src/utils/files.rs b/noxis-rs/src/utils/files.rs index 28346c2..639ced2 100644 --- a/noxis-rs/src/utils/files.rs +++ b/noxis-rs/src/utils/files.rs @@ -1,5 +1,5 @@ use crate::options::structs::{CustomError, Files}; -use crate::utils::prcs::{is_active, is_frozen}; +use super::prcs::{is_active, is_frozen}; use inotify::{EventMask, Inotify, WatchMask}; use std::borrow::BorrowMut; use std::path::Path; diff --git a/noxis-rs/src/utils/metrics.rs b/noxis-rs/src/utils/metrics.rs index 0648a3e..756e44b 100644 --- a/noxis-rs/src/utils/metrics.rs +++ b/noxis-rs/src/utils/metrics.rs @@ -7,7 +7,7 @@ use crate::options::structs::TrackingProcess; use sysinfo::{Process, System}; use tokio::join; use crate::options::structs::{ProcessMetrics, ContainerMetrics}; -use crate::utils::get_container_id; +use super::get_container_id; // use pcap::{Device, Capture, Active}; // use std::net::Ipv4Addr; // use anyhow::{Result, Ok}; diff --git a/noxis-rs/src/utils/services.rs b/noxis-rs/src/utils/services.rs index d89ee6b..fb51f7d 100644 --- a/noxis-rs/src/utils/services.rs +++ b/noxis-rs/src/utils/services.rs @@ -1,5 +1,5 @@ use crate::options::structs::{CustomError, Services}; -use crate::utils::prcs::{is_active, is_frozen}; +use super::prcs::{is_active, is_frozen}; use log::{error, warn}; use std::net::{TcpStream, ToSocketAddrs}; use std::sync::Arc; -- 2.40.1 From 014e8dd56d5fde99de3ad211c4f3b1cc5cf5057e Mon Sep 17 00:00:00 2001 From: prplV Date: Thu, 9 Jan 2025 15:10:34 +0300 Subject: [PATCH 10/14] noxis cli protocol now developed --- noxis-cli/src/cli.rs | 16 ++++++++-------- noxis-cli/src/main.rs | 2 -- noxis-cli/src/net.rs | 5 ++++- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/noxis-cli/src/cli.rs b/noxis-cli/src/cli.rs index 677e721..6c07db6 100644 --- a/noxis-cli/src/cli.rs +++ b/noxis-cli/src/cli.rs @@ -1,6 +1,6 @@ use clap::{Parser, Subcommand}; -#[derive(Debug, Parser)] +#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)] pub struct Cli { #[command( subcommand, @@ -9,7 +9,7 @@ pub struct Cli { command : Commands, } -#[derive(Debug, Subcommand)] +#[derive(Debug, Subcommand, serde::Serialize, serde::Deserialize)] pub enum Commands { #[command( about = "To get info about current Noxis status", @@ -43,7 +43,7 @@ pub enum Commands { Config(ConfigCommand), } -#[derive(Debug, Parser)] +#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)] pub struct StartAction { #[arg( long="with-flags", @@ -53,13 +53,13 @@ pub struct StartAction { flags : Vec, } -#[derive(Debug, Parser)] +#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)] pub struct ConfigCommand { #[command(subcommand)] action : ConfigAction, } -#[derive(Debug, Subcommand)] +#[derive(Debug, Subcommand, serde::Serialize, serde::Deserialize)] pub enum ConfigAction { #[command( about = "To change current Noxis configuration", @@ -75,7 +75,7 @@ pub enum ConfigAction { Reset, } -#[derive(Debug, Parser)] +#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)] pub struct LocalConfig { // flag #[arg( @@ -91,7 +91,7 @@ pub struct LocalConfig { config : String, } -#[derive(Debug, Parser)] +#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)] pub struct ProcessCommand { #[arg( help = "name of needed process", @@ -104,7 +104,7 @@ pub struct ProcessCommand { action : ProcessAction, } -#[derive(Debug, Subcommand)] +#[derive(Debug, Subcommand, serde::Serialize, serde::Deserialize)] enum ProcessAction { #[command( about = "To get info about current process status", diff --git a/noxis-cli/src/main.rs b/noxis-cli/src/main.rs index 718ec2f..0b9e00f 100644 --- a/noxis-cli/src/main.rs +++ b/noxis-cli/src/main.rs @@ -9,8 +9,6 @@ use anyhow::Result; #[tokio::main] async fn main() -> Result<()>{ let cli = Cli::parse(); - dbg!(&cli); - // println!("{:?}", cli); try_send(create_tcp_stream().await, cli).await?; Ok(()) } diff --git a/noxis-cli/src/net.rs b/noxis-cli/src/net.rs index 1c2e470..2e8c43a 100644 --- a/noxis-cli/src/net.rs +++ b/noxis-cli/src/net.rs @@ -11,14 +11,17 @@ pub async fn create_tcp_stream() -> Result { } pub async fn try_send(stream: Result, params: Cli) -> Result<()> { + use serde_json::to_string; let mut stream = stream?; loop { if stream.writable().await.is_err() { sleep(Duration::from_millis(100)).await; continue; } - let msg = format!("{:?}", params); + // let msg: Cli = from_str(&format!("{:?}", params))?; + let msg= to_string(¶ms)?; // let msg = r"HTTP/1.1 POST\r\nContent-Length: 14\r\nContent-Type: text/plain\r\n\r\nHello, World!@"; + stream.write_all(msg.as_bytes()).await?; // ... break; -- 2.40.1 From 4d2fe5768029fde06099744e406c211fdd4b2ab4 Mon Sep 17 00:00:00 2001 From: prplV Date: Thu, 9 Jan 2025 16:36:33 +0300 Subject: [PATCH 11/14] cli and daemon "PING-PONG" communication --- noxis-rs/Cargo.toml | 1 + noxis-rs/src/options/cli_pipeline.rs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/noxis-rs/Cargo.toml b/noxis-rs/Cargo.toml index cf86d18..62c917f 100644 --- a/noxis-rs/Cargo.toml +++ b/noxis-rs/Cargo.toml @@ -16,3 +16,4 @@ serde = { version = "1.0.203", features = ["derive"] } serde_json = "1.0.118" sysinfo = "0.32.0" tokio = { version = "1.38.0", features = ["full", "time"] } +noxis-cli = { path = "../noxis-cli" } diff --git a/noxis-rs/src/options/cli_pipeline.rs b/noxis-rs/src/options/cli_pipeline.rs index 3b9897c..ad6a670 100644 --- a/noxis-rs/src/options/cli_pipeline.rs +++ b/noxis-rs/src/options/cli_pipeline.rs @@ -5,6 +5,8 @@ use tokio::time::{sleep, Duration}; use std::{borrow::BorrowMut, net::{IpAddr, Ipv4Addr}}; // use std::io::BufReader; use tokio::io::{BufReader, AsyncWriteExt, AsyncBufReadExt}; +use noxis_cli::Cli; +use serde_json::from_str; /// # Fn `init_cli_pipeline` /// ## for catching all input requests from CLI @@ -85,7 +87,16 @@ async fn process_connection(mut stream: TcpStream) { while let Ok(Some(line)) = rqst.next_line().await { if line.is_empty() { - break; + break + } + match from_str::(&line) { + Ok(req) => { + // TODO: func wrapper + dbg!(req); + }, + Err(_) => { + break + }, } println!("{}", line); } -- 2.40.1 From 3d12137052e28dc41d4d06e9f84c5dc5c27a55db Mon Sep 17 00:00:00 2001 From: prplV Date: Mon, 13 Jan 2025 12:52:36 +0300 Subject: [PATCH 12/14] useless log deleted --- noxis-rs/src/options/config.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/noxis-rs/src/options/config.rs b/noxis-rs/src/options/config.rs index 5ebe5bb..0bc5ecc 100644 --- a/noxis-rs/src/options/config.rs +++ b/noxis-rs/src/options/config.rs @@ -201,7 +201,6 @@ fn once_get_remote_configuration(serv_info: &str) -> Option { } }, Err(_) => { - warn!("Cannot get config from Redis Server. Empty channel"); None }, } -- 2.40.1 From 7e0d22d4e0a64f71955c6e7fd9ca6c29e48f29f0 Mon Sep 17 00:00:00 2001 From: prplV Date: Mon, 13 Jan 2025 13:18:20 +0300 Subject: [PATCH 13/14] fixed issue#18 --- noxis-rs/src/options/preboot.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/noxis-rs/src/options/preboot.rs b/noxis-rs/src/options/preboot.rs index 6a02ee3..8130e96 100644 --- a/noxis-rs/src/options/preboot.rs +++ b/noxis-rs/src/options/preboot.rs @@ -4,6 +4,8 @@ use anyhow::{Result, Ok, Error}; use clap::Parser; use std::path::PathBuf; +const SOCKET_PATH: &str = "/var/run/enode/hostagent.sock"; + /// # Enum `MetricsPrebootParams` /// ## for setting up metrics mode as preboot param from command prompt /// @@ -186,8 +188,18 @@ pub struct PrebootParams { impl PrebootParams { pub fn validate(mut self) -> Result { if !self.socket_path.exists() && !self.no_hostagent { - eprintln!("Error: Socket-file not found or Noxis can't read it. Socket-file was set to default"); - self.socket_path = PathBuf::from("/var/run/enode/hostagent.sock"); + if self.socket_path.to_string_lossy() == SOCKET_PATH { + self.no_hostagent = true; + eprintln!("Warning: Socket-file wasn't found. Working without hostagent module..."); + } else { + eprintln!("Warning: Socket-file wasn't found or Noxis can't read it. Socket-file was set to default"); + if !PathBuf::from(SOCKET_PATH).exists() { + self.no_hostagent = true; + eprintln!("Warning: Socket-file wasn't found. Working without hostagent module..."); + } else { + self.socket_path = PathBuf::from(SOCKET_PATH); + } + } // return Err(Error::msg("Socket-file not found or Noxis can't read it. Cannot start")); } // existing log dir -- 2.40.1 From 204d2848715d2cee436cef1b19cdb2d2a96fac66 Mon Sep 17 00:00:00 2001 From: prplV Date: Mon, 13 Jan 2025 13:19:34 +0300 Subject: [PATCH 14/14] deleted useless Dockerfile --- noxis-rs/Dockerfile | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 noxis-rs/Dockerfile diff --git a/noxis-rs/Dockerfile b/noxis-rs/Dockerfile deleted file mode 100644 index 5882e02..0000000 --- a/noxis-rs/Dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -FROM ubuntu - -RUN mkdir -p /usr/src/kii/ - -WORKDIR /usr/src/kii/ - -RUN mkdir monitor/ -RUN mkdir -p services/temp-process/ -RUN touch services/temp-process/dep.txt -RUN touch services/temp-process/run.sh -RUN echo "./services/temp-process/temp-process &>/dev/null" >> services/temp-process/run.sh - -COPY target/x86_64-unknown-linux-gnu/release/runner-rs monitor/ -COPY settings.json . -COPY temp-process services/temp-process/ - -RUN chmod +x services/temp-process/temp-process -RUN chmod +x services/temp-process/run.sh -RUN chmod +x monitor/runner-rs - -# some troubles with execution this row-cmd -# ?: cannot get while initializing container -RUN export ENODE_CID=$(cat /proc/self/mountinfo | grep "/docker/containers/" | head -1 | awk -F '/' "{print \$6}") - -ENTRYPOINT [ "/usr/src/kii/monitor/runner-rs" ] -- 2.40.1