commit
1f4281e877
|
|
@ -0,0 +1,40 @@
|
||||||
|
name: Rust riscv64 build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master , rc ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ master , rc ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: sudo apt-get update && sudo apt-get install -y libssl-dev pkg-config build-essential gcc-riscv64-unknown-elf gcc-riscv64-linux-gnu binutils-riscv64-linux-gnu
|
||||||
|
|
||||||
|
- name: Set up Rust
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
|
||||||
|
- name: Cache dependencies
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cargo/registry
|
||||||
|
~/.cargo/git
|
||||||
|
target
|
||||||
|
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-cargo-
|
||||||
|
|
||||||
|
- name: Set up riscv64gc toolchain
|
||||||
|
run: rustup target add riscv64gc-unknown-linux-gnu
|
||||||
|
|
||||||
|
- name: Build x86_64-unknown-linux-gnu
|
||||||
|
run: cargo riscv64 --verbose
|
||||||
|
|
@ -2,9 +2,9 @@ name: Rust test
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [ master , rc ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master ]
|
branches: [ master , rc ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
name: Rust x86_64 build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master , rc ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ master , rc ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: sudo apt-get update && sudo apt-get install -y libssl-dev pkg-config build-essential
|
||||||
|
|
||||||
|
- name: Set up Rust
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
|
||||||
|
- name: Cache dependencies
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cargo/registry
|
||||||
|
~/.cargo/git
|
||||||
|
target
|
||||||
|
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-cargo-
|
||||||
|
|
||||||
|
- name: Build x86_64-unknown-linux-gnu
|
||||||
|
run: cargo x86_64 --verbose
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/target
|
/target
|
||||||
.idea
|
.idea
|
||||||
/.env
|
.env
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
hagent_test.sock
|
hagent_test.sock
|
||||||
release
|
release
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
# ACTIONS (trigger on exist)
|
||||||
|
NOXIS_NO_HAGENT = "true"
|
||||||
|
# NOXIS_NO_LOGS = "true"
|
||||||
|
NOXIS_REFRESH_LOGS = "true"
|
||||||
|
NOXIS_NO_SUB = "true"
|
||||||
|
|
||||||
|
# VALUES
|
||||||
|
NOXIS_HAGENT_SOCKET_PATH = "/var/run/example/hostagent.sock"
|
||||||
|
NOXIS_LOG_TO = "/var/log/noxis/noxis.log"
|
||||||
|
NOXIS_REMOTE_SERVER_URL = "ip.ip.ip.ip:port"
|
||||||
|
NOXIS_CONFIG_PATH = "./settings.json"
|
||||||
|
NOXIS_METRICS_MODE = "full"
|
||||||
|
|
@ -20,3 +20,4 @@ noxis-cli = { path = "../noxis-cli" }
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
futures = "0.3.31"
|
futures = "0.3.31"
|
||||||
async-trait = "0.1.88"
|
async-trait = "0.1.88"
|
||||||
|
crossbeam = { version = "0.8.4", features = ["crossbeam-channel"] }
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
{
|
{
|
||||||
"dateOfCreation": "1721381809112",
|
"dateOfCreation": "1721381809112",
|
||||||
"configServer": "192.168.2.37",
|
|
||||||
"processes": [
|
"processes": [
|
||||||
{
|
{
|
||||||
"name": "temp-process",
|
"name": "temp-process",
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,7 @@ use utils::v2::init_monitoring;
|
||||||
|
|
||||||
#[tokio::main(flavor = "multi_thread", worker_threads = 4)]
|
#[tokio::main(flavor = "multi_thread", worker_threads = 4)]
|
||||||
async fn main() -> anyhow::Result<()>{
|
async fn main() -> anyhow::Result<()>{
|
||||||
let preboot = Arc::new(PrebootParams::parse().validate()?);
|
let preboot = Arc::new(PrebootParams::validate());
|
||||||
|
|
||||||
let _ = setup_logger();
|
let _ = setup_logger();
|
||||||
|
|
||||||
info!("Noxis is configurating...");
|
info!("Noxis is configurating...");
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ pub mod v2 {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match get_redis_connection(&local_config.config_server).await {
|
match get_redis_connection(¶ms.remote_server_url).await {
|
||||||
Some(mut conn) => {
|
Some(mut conn) => {
|
||||||
let mut pub_sub = conn.as_pubsub();
|
let mut pub_sub = conn.as_pubsub();
|
||||||
let channel_name = get_container_id().unwrap_or(String::from("default"));
|
let channel_name = get_container_id().unwrap_or(String::from("default"));
|
||||||
|
|
@ -879,13 +879,11 @@ mod config_unittests {
|
||||||
// old one (kinda local)
|
// old one (kinda local)
|
||||||
let a = Processes {
|
let a = Processes {
|
||||||
date_of_creation: String::from("1"),
|
date_of_creation: String::from("1"),
|
||||||
config_server: String::new(),
|
|
||||||
processes: vec![],
|
processes: vec![],
|
||||||
};
|
};
|
||||||
// new one (kinda remote)
|
// new one (kinda remote)
|
||||||
let b = Processes {
|
let b = Processes {
|
||||||
date_of_creation: String::from("2"),
|
date_of_creation: String::from("2"),
|
||||||
config_server: String::new(),
|
|
||||||
processes: vec![],
|
processes: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -900,7 +898,6 @@ mod config_unittests {
|
||||||
fn save_config() {
|
fn save_config() {
|
||||||
let a = Processes {
|
let a = Processes {
|
||||||
date_of_creation: String::from("1"),
|
date_of_creation: String::from("1"),
|
||||||
config_server: String::new(),
|
|
||||||
processes: vec![],
|
processes: vec![],
|
||||||
};
|
};
|
||||||
assert!(save_new_config(&a, "tests/examples/save-conf.json").is_ok());
|
assert!(save_new_config(&a, "tests/examples/save-conf.json").is_ok());
|
||||||
|
|
@ -910,7 +907,6 @@ mod config_unittests {
|
||||||
fn save_to_zero_file() {
|
fn save_to_zero_file() {
|
||||||
let a = Processes {
|
let a = Processes {
|
||||||
date_of_creation: String::from("1"),
|
date_of_creation: String::from("1"),
|
||||||
config_server: String::new(),
|
|
||||||
processes: vec![],
|
processes: vec![],
|
||||||
};
|
};
|
||||||
assert!(save_new_config(&a, "tests/examples/none.json").is_ok());
|
assert!(save_new_config(&a, "tests/examples/none.json").is_ok());
|
||||||
|
|
|
||||||
|
|
@ -1,93 +1,12 @@
|
||||||
// module to handle pre-boot params of the monitor
|
//!
|
||||||
|
//! Module to handle `pre-boot params` of the monitor (calling also as `settings`)
|
||||||
|
//!
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use anyhow::{Result, Ok, Error};
|
use anyhow::{Result, Error};
|
||||||
use clap::Parser;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::env::var;
|
use std::env::var;
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
|
|
||||||
const SOCKET_PATH: &str = "/var/run/enode/hostagent.sock";
|
|
||||||
|
|
||||||
///
|
|
||||||
enum EnvVars {
|
|
||||||
NoxisNoHagent,
|
|
||||||
NoxisNoLogs,
|
|
||||||
NoxisRefreshLogs,
|
|
||||||
// NoxisNoRemoteConfig,
|
|
||||||
NoxisNoConfigSub,
|
|
||||||
NoxisSocketPath,
|
|
||||||
NoxisLogTo,
|
|
||||||
NoxisRemoteServerUrl,
|
|
||||||
NoxisConfig,
|
|
||||||
NoxisMetrics,
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
impl std::fmt::Display for EnvVars {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
||||||
match self {
|
|
||||||
EnvVars::NoxisNoHagent => write!(f, "NOXIS_NO_HAGENT"),
|
|
||||||
EnvVars::NoxisNoLogs => write!(f, "NOXIS_NO_LOGS"),
|
|
||||||
EnvVars::NoxisRefreshLogs => write!(f, "NOXIS_REFRESH_LOGS"),
|
|
||||||
// EnvVars::NoxisNoRemoteConfig => write!(f, "NOXIS_NO_REMOTE_CONFIG"),
|
|
||||||
EnvVars::NoxisNoConfigSub => write!(f, "NOXIS_NO_CONFIG_SUB"),
|
|
||||||
EnvVars::NoxisSocketPath => write!(f, "NOXIS_SOCKET_PATH"),
|
|
||||||
EnvVars::NoxisLogTo => write!(f, "NOXIS_LOG_TO"),
|
|
||||||
EnvVars::NoxisRemoteServerUrl => write!(f, "NOXIS_REMOTE_SERVER_URL"),
|
|
||||||
EnvVars::NoxisConfig => write!(f, "NOXIS_CONFIG"),
|
|
||||||
EnvVars::NoxisMetrics => write!(f, "NOXIS_METRICS"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
impl<'a> EnvVars {
|
|
||||||
// Default trait func is not satisfying this issue
|
|
||||||
fn default(self) -> &'a str {
|
|
||||||
match self {
|
|
||||||
EnvVars::NoxisNoHagent => "false",
|
|
||||||
EnvVars::NoxisNoLogs => "false",
|
|
||||||
EnvVars::NoxisRefreshLogs => "false",
|
|
||||||
// EnvVars::NoxisNoRemoteConfig => "false",
|
|
||||||
EnvVars::NoxisNoConfigSub => "false",
|
|
||||||
EnvVars::NoxisSocketPath => "/var/run/enode/hostagent.sock",
|
|
||||||
EnvVars::NoxisLogTo => "./",
|
|
||||||
EnvVars::NoxisRemoteServerUrl => "localhost",
|
|
||||||
EnvVars::NoxisConfig => "./settings.json",
|
|
||||||
EnvVars::NoxisMetrics => "full",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn process_env_var(self, preboot_value: &str) {
|
|
||||||
// let default = self.default();
|
|
||||||
match var(self.to_string()) {
|
|
||||||
std::result::Result::Ok(val) => {
|
|
||||||
if val != preboot_value {
|
|
||||||
std::env::set_var(self.to_string(), self.default());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(_) => {
|
|
||||||
std::env::set_var(self.to_string(), preboot_value);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn setup(preboot: &PrebootParams) {
|
|
||||||
// setup default if not exists
|
|
||||||
// check values and save preboot states in env vars if not equal
|
|
||||||
|
|
||||||
Self::NoxisNoHagent.process_env_var(&preboot.no_hostagent.to_string());
|
|
||||||
Self::NoxisNoLogs.process_env_var(&preboot.no_logs.to_string());
|
|
||||||
Self::NoxisRefreshLogs.process_env_var(&preboot.refresh_logs.to_string());
|
|
||||||
// Self::NoxisNoRemoteConfig.process_env_var(&preboot.no_remote_config.to_string());
|
|
||||||
Self::NoxisNoConfigSub.process_env_var(&preboot.no_sub.to_string());
|
|
||||||
Self::NoxisSocketPath.process_env_var(preboot.socket_path.to_str().unwrap());
|
|
||||||
Self::NoxisLogTo.process_env_var(preboot.log_to.to_str().unwrap());
|
|
||||||
Self::NoxisRemoteServerUrl.process_env_var(&preboot.remote_server_url);
|
|
||||||
Self::NoxisConfig.process_env_var(preboot.config.to_str().unwrap());
|
|
||||||
Self::NoxisMetrics.process_env_var(&preboot.metrics.to_string());
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// # Enum `MetricsPrebootParams`
|
/// # Enum `MetricsPrebootParams`
|
||||||
/// ## for setting up metrics mode as preboot param from command prompt
|
/// ## for setting up metrics mode as preboot param from command prompt
|
||||||
///
|
///
|
||||||
|
|
@ -109,6 +28,19 @@ pub enum MetricsPrebootParams {
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl MetricsPrebootParams {
|
||||||
|
fn from_env(var: &str) -> Self {
|
||||||
|
match var.trim().to_lowercase().as_str() {
|
||||||
|
"full" => Self::Full,
|
||||||
|
"system" => Self::System,
|
||||||
|
"processes" => Self::Processes,
|
||||||
|
"net" => Self::Net,
|
||||||
|
"none" => Self::None,
|
||||||
|
_ => Self::Full,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// # `std::fmt::Display` implementation for `MetricsPrebootParams`
|
/// # `std::fmt::Display` implementation for `MetricsPrebootParams`
|
||||||
/// ## to enable parsing object to String
|
/// ## to enable parsing object to String
|
||||||
impl std::fmt::Display for MetricsPrebootParams {
|
impl std::fmt::Display for MetricsPrebootParams {
|
||||||
|
|
@ -123,257 +55,276 @@ impl std::fmt::Display for MetricsPrebootParams {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # struct `PrebootParams`
|
/// struct to handle Noxis settings (that were set as `.env` or global env vars)
|
||||||
/// ## to parse and set up all modes as preboot params from command prompt
|
|
||||||
///
|
///
|
||||||
/// ### args :
|
/// to parse and set up all modes as preboot params from `.env` or using `export $VAR $VAL` command
|
||||||
///
|
///
|
||||||
/// `--no-hagent` - to disable hagent work module and set up work mode as autonomous
|
/// # Settings :
|
||||||
/// ### usage :
|
///
|
||||||
|
/// All settings are divided by `actions` and `values`.
|
||||||
|
/// 1. `Actions` - true or false on var exist check
|
||||||
|
/// > `Actions` is not about values, it can handle any data
|
||||||
|
///
|
||||||
|
/// 2. `Values` - classic string-driven environment variables
|
||||||
|
///
|
||||||
|
/// # `Actions` vars
|
||||||
|
///
|
||||||
|
/// 1. `NOXIS_NO_HAGENT` - to disable hagent work module and set up work mode as autonomous
|
||||||
|
///
|
||||||
|
/// **usage** :
|
||||||
|
/// ``` toml
|
||||||
|
/// ...
|
||||||
|
/// NOXIS_NO_HAGENT = "random-text"
|
||||||
|
/// ...
|
||||||
|
/// ```
|
||||||
|
/// or
|
||||||
/// ``` bash
|
/// ``` bash
|
||||||
/// noxis-rs ... --no-hagent ...
|
/// export NOXIS_NO_HAGENT "random-text"
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// `--no-logs` - to disable logging at all
|
/// 2. `NOXIS_NO_LOGS` - to disable logging at all
|
||||||
/// ### usage :
|
/// **usage** :
|
||||||
|
/// ``` toml
|
||||||
|
/// ...
|
||||||
|
/// NOXIS_NO_LOGS = "random-text"
|
||||||
|
/// ...
|
||||||
|
/// ```
|
||||||
|
/// or
|
||||||
/// ``` bash
|
/// ``` bash
|
||||||
/// noxis-rs ... --no-logs ...
|
/// export NOXIS_NO_LOGS "random-text"
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// `--refresh-logs` - to truncate logs directory
|
/// 3. `NOXIS_REFRESH_LOGS` - to truncate logs directory
|
||||||
|
///
|
||||||
/// ### usage :
|
/// ### usage :
|
||||||
|
/// ``` toml
|
||||||
|
/// ...
|
||||||
|
/// NOXIS_REFRESH_LOGS = "random-text"
|
||||||
|
/// ...
|
||||||
|
/// ```
|
||||||
|
/// or
|
||||||
/// ``` bash
|
/// ``` bash
|
||||||
/// noxis-rs ... --refresh-logs ...
|
/// export NOXIS_REFRESH_LOGS "random-text"
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// `--no-sub` - to disable Redis subscribtion mechanism
|
/// 4. `NOXIS_NO_SUB` - to disable Redis subscribtion mechanism
|
||||||
|
///
|
||||||
/// ### usage :
|
/// ### usage :
|
||||||
|
/// ``` toml
|
||||||
|
/// NOXIS_NO_SUB = "random-text"
|
||||||
|
/// ```
|
||||||
|
/// or
|
||||||
/// ``` bash
|
/// ``` bash
|
||||||
/// noxis-rs ... --no-sub ...
|
/// export NOXIS_NO_SUB "random-text"
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// `--socket-path` - to set Unix Domain Socket file's directory
|
/// # `Values` vars
|
||||||
|
///
|
||||||
|
/// 1. `NOXIS_HAGENT_SOCKET_PATH` - to set Unix Domain Socket file's directory
|
||||||
|
///
|
||||||
/// ### usage :
|
/// ### usage :
|
||||||
|
/// ``` toml
|
||||||
|
/// NOXIS_HAGENT_SOCKET_PATH = "/var/run/example/hostagent.sock"
|
||||||
|
/// ```
|
||||||
|
/// or
|
||||||
/// ``` bash
|
/// ``` bash
|
||||||
/// noxis-rs ... --socket-path /var/run/enode/hostagent.sock ...
|
/// export NOXIS_HAGENT_SOCKET_PATH "/var/run/example/hostagent.sock"
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// `--log-to` - to set directory for logs
|
/// 2 `NOXIS_LOG_TO` - to set directory for logs
|
||||||
|
///
|
||||||
/// ### usage :
|
/// ### usage :
|
||||||
|
/// ``` toml
|
||||||
|
/// NOXIS_LOG_TO = "/var/log/noxis/noxis.log"
|
||||||
|
/// ```
|
||||||
|
/// or
|
||||||
/// ``` bash
|
/// ``` bash
|
||||||
/// noxis-rs ... --log-to /dir/to/logs/ ...
|
/// export NOXIS_LOG_TO "/var/log/noxis/noxis.log"
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// `--remote-server-url` - to set Redis Server
|
/// 3. `NOXIS_REMOTE_SERVER_URL` - to set Redis Server
|
||||||
|
///
|
||||||
/// ### usage :
|
/// ### usage :
|
||||||
|
/// ``` toml
|
||||||
|
/// NOXIS_REMOTE_SERVER_URL = "ip.ip.ip.ip:port"
|
||||||
|
/// ```
|
||||||
|
/// or
|
||||||
/// ``` bash
|
/// ``` bash
|
||||||
/// noxis-rs ... --remote-server-url 192.168.28.12 ...
|
/// export NOXIS_REMOTE_SERVER_URL "ip.ip.ip.ip:port"
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// `--config` - to set Noxis' config full path
|
/// 4. `NOXIS_CONFIG_PATH` - to set Noxis' config full path
|
||||||
|
///
|
||||||
/// ### usage :
|
/// ### usage :
|
||||||
|
/// ``` toml
|
||||||
|
/// NOXIS_CONFIG_PATH = "./settings.json"
|
||||||
|
/// ```
|
||||||
|
/// or
|
||||||
/// ``` bash
|
/// ``` bash
|
||||||
/// noxis-rs ... --config /etc/enode/settings.json ...
|
/// export NOXIS_CONFIG_PATH "./settings.json"
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// `--metrics` - to set metrics mode
|
/// 5. `NOXIS_METRICS_MODE` - to set metrics mode
|
||||||
|
///
|
||||||
/// ### usage :
|
/// ### usage :
|
||||||
/// ``` bash
|
/// ``` toml
|
||||||
/// noxis-rs ... --metrics full ...
|
/// NOXIS_METRICS_MODE = "full"
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Parser)]
|
/// or
|
||||||
|
/// ``` bash
|
||||||
|
/// export NOXIS_METRICS_MODE "full"
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct PrebootParams {
|
pub struct PrebootParams {
|
||||||
// actions
|
|
||||||
#[arg(
|
|
||||||
long = "no-hagent",
|
|
||||||
action,
|
|
||||||
conflicts_with="socket_path",
|
|
||||||
help="To disable work with host-agent"
|
|
||||||
)]
|
|
||||||
pub no_hostagent : bool,
|
pub no_hostagent : bool,
|
||||||
#[arg(
|
|
||||||
long = "no-logs",
|
|
||||||
action,
|
|
||||||
conflicts_with="log_to",
|
|
||||||
help="To disable logs"
|
|
||||||
)]
|
|
||||||
pub no_logs: bool,
|
pub no_logs: bool,
|
||||||
#[arg(
|
|
||||||
long = "refresh-logs",
|
|
||||||
action,
|
|
||||||
conflicts_with="no_logs",
|
|
||||||
help="To clear logs directory"
|
|
||||||
)]
|
|
||||||
pub refresh_logs : bool,
|
pub refresh_logs : bool,
|
||||||
// #[arg(
|
|
||||||
// long = "no-remote-config",
|
|
||||||
// action,
|
|
||||||
// help="To disable work with remote config server",
|
|
||||||
// conflicts_with="no_sub")]
|
|
||||||
// pub no_remote_config : bool,
|
|
||||||
#[arg(
|
|
||||||
long = "no-sub",
|
|
||||||
action,
|
|
||||||
help="To disable Redis subscription mechanism",
|
|
||||||
)]
|
|
||||||
// conflicts_with="no_remote_config"
|
|
||||||
pub no_sub : bool,
|
pub no_sub : bool,
|
||||||
|
|
||||||
// params (socket_path, log_to, remote_server_url, config)
|
|
||||||
#[arg(
|
|
||||||
long = "socket-path",
|
|
||||||
default_value="/var/run/enode/hostagent.sock",
|
|
||||||
conflicts_with="no_hostagent",
|
|
||||||
help="To set .sock file's path used in communication with host-agent"
|
|
||||||
)]
|
|
||||||
pub socket_path : PathBuf,
|
pub socket_path : PathBuf,
|
||||||
#[arg(
|
|
||||||
long = "log-to",
|
|
||||||
default_value="./",
|
|
||||||
conflicts_with="no_logs",
|
|
||||||
help="To set a path to logs directory"
|
|
||||||
)]
|
|
||||||
pub log_to : PathBuf,
|
pub log_to : PathBuf,
|
||||||
#[arg(
|
|
||||||
long = "remote-server-url",
|
|
||||||
default_value="localhost",
|
|
||||||
conflicts_with="no_sub",
|
|
||||||
help = "To set url of remote config server using in remote config pulling mechanism"
|
|
||||||
)]
|
|
||||||
pub remote_server_url : String,
|
pub remote_server_url : String,
|
||||||
#[arg(
|
|
||||||
long = "config",
|
|
||||||
short,
|
|
||||||
default_value="settings.json",
|
|
||||||
help="To set local config file path"
|
|
||||||
)]
|
|
||||||
pub config : PathBuf,
|
pub config : PathBuf,
|
||||||
|
|
||||||
// value enum params (metrics)
|
|
||||||
#[arg(
|
|
||||||
long = "metrics",
|
|
||||||
short,
|
|
||||||
default_value_t=MetricsPrebootParams::Full,
|
|
||||||
help="To set metrics grubbing mode"
|
|
||||||
)]
|
|
||||||
pub metrics: MetricsPrebootParams,
|
pub metrics: MetricsPrebootParams,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # implementation for `MetricsPrebootParams`
|
/// # implementation for `MetricsPrebootParams`
|
||||||
/// ## to enable validation mechanism
|
/// ## to enable validation mechanism
|
||||||
impl PrebootParams {
|
impl PrebootParams {
|
||||||
pub fn validate(mut self) -> Result<Self> {
|
pub fn validate() -> Self {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
if !self.socket_path.exists() && !self.no_hostagent {
|
Self {
|
||||||
if self.socket_path.to_string_lossy() == SOCKET_PATH {
|
// bool
|
||||||
self.no_hostagent = true;
|
no_hostagent : {
|
||||||
eprintln!("Warning: Socket-file wasn't found. Working without hostagent module...");
|
match var("NOXIS_NO_HAGENT") {
|
||||||
} else {
|
Ok(_) => true,
|
||||||
eprintln!("Warning: Socket-file wasn't found or Noxis can't read it. Socket-file was set to default");
|
Err(_) => false,
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
no_logs : {
|
||||||
|
match var("NOXIS_NO_LOGS") {
|
||||||
|
Ok(_) => true,
|
||||||
|
Err(_) => false,
|
||||||
}
|
}
|
||||||
// return Err(Error::msg("Socket-file not found or Noxis can't read it. Cannot start"));
|
},
|
||||||
|
refresh_logs : {
|
||||||
|
match var("NOXIS_REFRESH_LOGS") {
|
||||||
|
Ok(_) => true,
|
||||||
|
Err(_) => false,
|
||||||
}
|
}
|
||||||
// existing log dir
|
},
|
||||||
if !self.log_to.exists() && !self.no_logs {
|
no_sub : {
|
||||||
eprintln!("Error: Log-Dir not found or Noxis can't read it. LogDir was set to default");
|
match var("NOXIS_NO_SUB") {
|
||||||
self.refresh_logs = false;
|
Ok(_) => true,
|
||||||
self.log_to = PathBuf::from("./");
|
Err(_) => false,
|
||||||
// return Err(Error::msg("Log Directory Not Found or Noxis can't read it. Cannot start"));
|
|
||||||
}
|
}
|
||||||
// existing sock file
|
},
|
||||||
if !self.config.exists() {
|
// vals
|
||||||
eprintln!("Error: Invalid character in config file. Config path was set to default");
|
socket_path : {
|
||||||
// TODO : ??? wtf is going with 2 paths
|
match var("NOXIS_HAGENT_SOCKET_PATH") {
|
||||||
let config = PathBuf::from("/etc/enode/noxis/settings.json");
|
Ok(val) => PathBuf::from(val),
|
||||||
if !config.exists() && self.no_sub {
|
Err(_) => PathBuf::from("/var/run/enode/hostagent.sock"),
|
||||||
return Err(Error::msg("Noxis cannot run without config. Create local config or enable pubsub mechanism"));
|
|
||||||
}
|
}
|
||||||
self.config = PathBuf::from("settings.json");
|
},
|
||||||
// return Err(Error::msg("Local Config Not Found or Noxis can't read it. Cannot start"));
|
log_to : {
|
||||||
|
match var("NOXIS_LOG_TO") {
|
||||||
|
Ok(val) => PathBuf::from(val),
|
||||||
|
Err(_) => PathBuf::from("./"),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
remote_server_url : {
|
||||||
|
match var("NOXIS_REMOTE_SERVER_URL") {
|
||||||
|
Ok(val) => val,
|
||||||
|
Err(_) => String::from("localhost"),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
config : {
|
||||||
|
match var("NOXIS_CONFIG_PATH") {
|
||||||
|
Ok(val) => PathBuf::from(val),
|
||||||
|
Err(_) => PathBuf::from("./settings.json"),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
metrics : {
|
||||||
|
match var("NOXIS_METRICS_MODE") {
|
||||||
|
Ok(val) => MetricsPrebootParams::from_env(&val),
|
||||||
|
Err(_) => MetricsPrebootParams::Full,
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
// redis server check
|
|
||||||
EnvVars::setup(&self);
|
|
||||||
Ok(self)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// unit tests of preboot params parsing mech
|
// unit tests of preboot params parsing mech
|
||||||
#[cfg(test)]
|
// #[cfg(test)]
|
||||||
mod preboot_unitests{
|
// mod preboot_unitests{
|
||||||
use super::*;
|
// use super::*;
|
||||||
|
|
||||||
#[test]
|
// #[test]
|
||||||
fn parsing_zero_args() {
|
// 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]
|
// #[test]
|
||||||
fn parsing_hagent_valid_args() {
|
// fn parsing_hagent_valid_args() {
|
||||||
assert!(PrebootParams::try_parse_from(vec![
|
// assert!(PrebootParams::try_parse_from(vec![
|
||||||
"runner-rs",
|
// "runner-rs",
|
||||||
"--socket-path", "/path/to/socket"
|
// "--socket-path", "/path/to/socket"
|
||||||
]).is_ok())
|
// ]).is_ok())
|
||||||
}
|
// }
|
||||||
#[test]
|
// #[test]
|
||||||
fn parsing_hagent_invalid_args() {
|
// fn parsing_hagent_invalid_args() {
|
||||||
assert!(PrebootParams::try_parse_from(vec![
|
// assert!(PrebootParams::try_parse_from(vec![
|
||||||
"runner-rs",
|
// "runner-rs",
|
||||||
"--socket-path", "/path/to/socket",
|
// "--socket-path", "/path/to/socket",
|
||||||
"--no-hagent"
|
// "--no-hagent"
|
||||||
]).is_err())
|
// ]).is_err())
|
||||||
}
|
// }
|
||||||
#[test]
|
// #[test]
|
||||||
fn parsing_log_valid_args() {
|
// fn parsing_log_valid_args() {
|
||||||
assert!(PrebootParams::try_parse_from(vec![
|
// assert!(PrebootParams::try_parse_from(vec![
|
||||||
"runner-rs",
|
// "runner-rs",
|
||||||
"--log-to", "/path/to/log/dir"
|
// "--log-to", "/path/to/log/dir"
|
||||||
]).is_ok())
|
// ]).is_ok())
|
||||||
}
|
// }
|
||||||
#[test]
|
// #[test]
|
||||||
fn parsing_log_invalid_args() {
|
// fn parsing_log_invalid_args() {
|
||||||
assert!(PrebootParams::try_parse_from(vec![
|
// assert!(PrebootParams::try_parse_from(vec![
|
||||||
"runner-rs",
|
// "runner-rs",
|
||||||
"--log-to /path/to/log/dir",
|
// "--log-to /path/to/log/dir",
|
||||||
"--no-logs"
|
// "--no-logs"
|
||||||
]).is_err())
|
// ]).is_err())
|
||||||
}
|
// }
|
||||||
#[test]
|
// #[test]
|
||||||
fn parsing_config_valid_args() {
|
// fn parsing_config_valid_args() {
|
||||||
assert!(PrebootParams::try_parse_from(vec![
|
// assert!(PrebootParams::try_parse_from(vec![
|
||||||
"runner-rs",
|
// "runner-rs",
|
||||||
"--no-sub",
|
// "--no-sub",
|
||||||
"--remote-server-url", "redis://127.0.0.1"
|
// "--remote-server-url", "redis://127.0.0.1"
|
||||||
]).is_err())
|
// ]).is_err())
|
||||||
}
|
// }
|
||||||
// #[test]
|
// // #[test]
|
||||||
// fn parsing_config_invalid_args_noremote_nosub() {
|
// // fn parsing_config_invalid_args_noremote_nosub() {
|
||||||
// assert!(PrebootParams::try_parse_from(vec![
|
// // assert!(PrebootParams::try_parse_from(vec![
|
||||||
// "runner-rs",
|
// // "runner-rs",
|
||||||
// "--no-remote-config", "--no-sub"
|
// // "--no-remote-config", "--no-sub"
|
||||||
// ]).is_err())
|
// // ]).is_err())
|
||||||
// }
|
// // }
|
||||||
#[test]
|
// #[test]
|
||||||
fn parsing_config_invalid_args_noremote_remoteurl() {
|
// fn parsing_config_invalid_args_noremote_remoteurl() {
|
||||||
assert!(PrebootParams::try_parse_from(vec![
|
// assert!(PrebootParams::try_parse_from(vec![
|
||||||
"runner-rs",
|
// "runner-rs",
|
||||||
"--no-sub",
|
// "--no-sub",
|
||||||
"--remote-server-url", "redis://127.0.0.1"
|
// "--remote-server-url", "redis://127.0.0.1"
|
||||||
]).is_err())
|
// ]).is_err())
|
||||||
}
|
// }
|
||||||
#[test]
|
// #[test]
|
||||||
fn parsing_metrics_args_using_value_enum() {
|
// fn parsing_metrics_args_using_value_enum() {
|
||||||
assert!(PrebootParams::try_parse_from(vec!["runner-rs", "--metrics", "full"]).is_ok());
|
// assert!(PrebootParams::try_parse_from(vec!["runner-rs", "--metrics", "full"]).is_ok());
|
||||||
assert!(PrebootParams::try_parse_from(vec!["runner-rs", "--metrics", "system"]).is_ok());
|
// assert!(PrebootParams::try_parse_from(vec!["runner-rs", "--metrics", "system"]).is_ok());
|
||||||
assert!(PrebootParams::try_parse_from(vec!["runner-rs", "--metrics", "processes"]).is_ok());
|
// assert!(PrebootParams::try_parse_from(vec!["runner-rs", "--metrics", "processes"]).is_ok());
|
||||||
assert!(PrebootParams::try_parse_from(vec!["runner-rs", "--metrics", "net"]).is_ok());
|
// assert!(PrebootParams::try_parse_from(vec!["runner-rs", "--metrics", "net"]).is_ok());
|
||||||
assert!(PrebootParams::try_parse_from(vec!["runner-rs", "--metrics", "none"]).is_ok());
|
// assert!(PrebootParams::try_parse_from(vec!["runner-rs", "--metrics", "none"]).is_ok());
|
||||||
assert!(PrebootParams::try_parse_from(vec!["runner-rs", "--metrics", "unusual_value"]).is_err());
|
// assert!(PrebootParams::try_parse_from(vec!["runner-rs", "--metrics", "unusual_value"]).is_err());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
@ -141,8 +141,6 @@ pub struct Processes {
|
||||||
// runner_id: usize,
|
// runner_id: usize,
|
||||||
#[serde(rename = "dateOfCreation")]
|
#[serde(rename = "dateOfCreation")]
|
||||||
pub date_of_creation: String,
|
pub date_of_creation: String,
|
||||||
#[serde(rename = "configServer")]
|
|
||||||
pub config_server: String,
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub processes: Vec<TrackingProcess>,
|
pub processes: Vec<TrackingProcess>,
|
||||||
}
|
}
|
||||||
|
|
@ -151,7 +149,6 @@ impl Default for Processes {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
date_of_creation : String::new(),
|
date_of_creation : String::new(),
|
||||||
config_server : String::from("default"),
|
|
||||||
processes : Vec::new(),
|
processes : Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue