diff --git a/Cargo.lock b/Cargo.lock index 12e35b6..c25ddba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -104,12 +104,10 @@ dependencies = [ "atty", "bitflags", "indexmap", - "lazy_static", "os_str_bytes", "strsim", "termcolor", "textwrap", - "yaml-rust", ] [[package]] @@ -443,12 +441,6 @@ version = "0.2.103" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" -[[package]] -name = "linked-hash-map" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" - [[package]] name = "log" version = "0.4.14" @@ -1132,15 +1124,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "yaml-rust" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" -dependencies = [ - "linked-hash-map", -] - [[package]] name = "zabbixlaunch" version = "1.0.0" diff --git a/Cargo.toml b/Cargo.toml index 5976363..6fc2bdb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://git.paulbsd.com/paulbsd/zabbixlaunch" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = { version = "3", features = ["cargo", "yaml"] } +clap = "3" embedded-graphics = { version = "0.7", optional = true } launchy = { git = "https://github.com/kangalioo/launchy", branch = "master" } reqwest = { version = "0.11", default-features = false, features = ["blocking", "json", "rustls-tls"] } @@ -19,3 +19,5 @@ nix = "0.23" [profile.release] debug = 0 +lto = true +codegen-units = 1 diff --git a/src/config/mod.rs b/src/config/mod.rs index 6233f27..69fe709 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -66,8 +66,9 @@ impl Context { .short('c') .long("config") .value_name("FILE") - .help("Sets a custom config file") - .takes_value(true), + .default_value("/etc/zabbixlaunch/config.json") + .takes_value(true) + .help("Sets a custom config file"), ) .arg( Arg::new("mode") @@ -75,8 +76,9 @@ impl Context { .long("mode") .value_name("mode") .default_value("draw") - .help("Sets a when running") - .takes_value(true), + .possible_values(&["draw", "test", "input", "effect"]) + .takes_value(true) + .help("Sets a when running"), ) .arg( Arg::new("debug") @@ -138,7 +140,7 @@ impl<'a> Config { pub fn load(&'a mut self, configfile: &str) { let fileopen: Result; let filemeta = std::fs::metadata(configfile); - let mut errorreading = false; + let mut error_reading = false; let fileexists = match filemeta { Ok(_) => true, Err(_) => false, @@ -158,7 +160,7 @@ impl<'a> Config { let mut contents = String::new(); file.read_to_string(&mut contents).unwrap(); let parse: Result = serde_json::from_str(contents.as_str()); - let newcfg = match parse { + let ncfg = match parse { Ok(ncfg) => { let tmpcfg = Config::new(); Config { @@ -190,13 +192,13 @@ impl<'a> Config { } } Err(err) => { - errorreading = true; + error_reading = true; println!("error occured: '{}'", err); Config::new() } }; - *self = newcfg; - if !fileexists || errorreading { + *self = ncfg; + if !fileexists || error_reading { self.save(&configfile); } } diff --git a/src/zabbix/api.rs b/src/zabbix/api.rs index ea70c48..e0c5845 100644 --- a/src/zabbix/api.rs +++ b/src/zabbix/api.rs @@ -1,8 +1,8 @@ -use std::time::Duration; -use std::thread::sleep; use crate::config::Config; use serde_json::json; use serde_json::Value as JsonValue; +//use std::thread::sleep; +//use std::time::Duration; pub const ZABBIX_API_VERSION: &'static str = "2.0"; pub const ZABBIX_API_ID: i32 = 1; @@ -36,15 +36,13 @@ pub fn get_zabbix_problems(cfg: &Config) -> Result { match resp { Ok(v) => v.json(), - Err(e) => { - Err(e) - } + Err(e) => Err(e), } } /// Check if Zabbix is operational /// Undefinitely check that Zabbix works -fn check_zabbix_connection(cfg: &Config) -> bool { +/*fn check_zabbix_connection(cfg: &Config) -> bool { let mut res: bool = false; let delay = 5; let timeout = 10; @@ -60,7 +58,7 @@ fn check_zabbix_connection(cfg: &Config) -> bool { sleep(Duration::from_secs(delay)); } res -} +}*/ /// Build the query that fetchs the token fn build_query_auth_token(zabbix_username: &String, zabbix_password: &String) -> JsonValue { @@ -77,7 +75,7 @@ fn build_query_auth_token(zabbix_username: &String, zabbix_password: &String) -> } /// Build the query that fetchs problems -fn build_query_problems(zabbix_token: &String, zabbix_limit: i64) -> JsonValue { +/*fn build_query_problems(zabbix_token: &String, zabbix_limit: i64) -> JsonValue { let zabbix_api_function = "problem.get"; json!({ "jsonrpc": ZABBIX_API_VERSION, @@ -97,7 +95,7 @@ fn build_query_problems(zabbix_token: &String, zabbix_limit: i64) -> JsonValue { "auth": zabbix_token, "id": ZABBIX_API_ID }) -} +}*/ /// Build the query that fetchs triggers fn build_query_triggers(zabbix_token: &String) -> JsonValue { diff --git a/src/zabbix/problems.rs b/src/zabbix/problems.rs index 3ae11d5..dd1acde 100644 --- a/src/zabbix/problems.rs +++ b/src/zabbix/problems.rs @@ -1,14 +1,14 @@ use serde_json::Value; use std::fmt::{Display, Formatter, Result}; -#[derive(Debug, Clone)] +/*#[derive(Debug, Clone)] pub enum ZabbixStatus { Disaster = 5, High = 4, Average = 3, Warning = 2, Info = 1, -} +}*/ #[derive(Debug, Clone)] pub struct DataMatrix {