misc changes
This commit is contained in:
parent
2dd5020963
commit
400aaf667d
@ -1,15 +1,13 @@
|
|||||||
use crate::zabbix::api::get_zabbix_authtoken;
|
use crate::zabbix::api::get_zabbix_authtoken;
|
||||||
use crate::zabbix::problems::DataMatrix;
|
use crate::zabbix::problems::DataMatrix;
|
||||||
use clap::App;
|
use clap::App;
|
||||||
use nix::sys::inotify::{AddWatchFlags, InitFlags, Inotify, InotifyEvent};
|
use nix::sys::inotify::{AddWatchFlags, InitFlags, Inotify};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Error as JsonError;
|
use serde_json::Error as JsonError;
|
||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::string::String;
|
use std::string::String;
|
||||||
use std::thread::sleep;
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ReloadFrequency {
|
pub enum ReloadFrequency {
|
||||||
@ -121,41 +119,31 @@ impl<'a> Config {
|
|||||||
Ok(cfg) => {
|
Ok(cfg) => {
|
||||||
let tmpcfg = Config::new();
|
let tmpcfg = Config::new();
|
||||||
Config {
|
Config {
|
||||||
<<<<<<< Updated upstream
|
server: cfg["server"]
|
||||||
server: cfg["server"].as_str().unwrap_or(tmpcfg.server.as_str()).to_string(),
|
|
||||||
username: cfg["username"].as_str().unwrap_or(tmpcfg.username.as_str()).to_string(),
|
|
||||||
password: cfg["password"].as_str().unwrap_or(tmpcfg.password.as_str()).to_string(),
|
|
||||||
authtoken: Some(cfg["authtoken"].as_str().unwrap_or(tmpcfg.authtoken.unwrap().as_str()).to_string()),
|
|
||||||
sloweffect: Some(cfg["sloweffect"].as_bool().unwrap_or(tmpcfg.sloweffect.unwrap())),
|
|
||||||
refresh: Some(cfg["refresh"].as_u64().unwrap_or(tmpcfg.refresh.unwrap())),
|
|
||||||
limit: Some(cfg["limit"].as_u64().unwrap_or(tmpcfg.limit.unwrap())),
|
|
||||||
=======
|
|
||||||
server: ncfg["server"]
|
|
||||||
.as_str()
|
.as_str()
|
||||||
.unwrap_or(&tmpcfg.server.clone())
|
.unwrap_or(tmpcfg.server.as_str())
|
||||||
.to_string(),
|
.to_string(),
|
||||||
username: ncfg["username"]
|
username: cfg["username"]
|
||||||
.as_str()
|
.as_str()
|
||||||
.unwrap_or(&tmpcfg.username.clone())
|
.unwrap_or(tmpcfg.username.as_str())
|
||||||
.to_string(),
|
.to_string(),
|
||||||
password: ncfg["password"]
|
password: cfg["password"]
|
||||||
.as_str()
|
.as_str()
|
||||||
.unwrap_or(&tmpcfg.password.clone())
|
.unwrap_or(tmpcfg.password.as_str())
|
||||||
.to_string(),
|
.to_string(),
|
||||||
authtoken: Some(
|
authtoken: Some(
|
||||||
ncfg["authtoken"]
|
cfg["authtoken"]
|
||||||
.as_str()
|
.as_str()
|
||||||
.unwrap_or(self.authtoken.clone().unwrap().as_str())
|
.unwrap_or(tmpcfg.authtoken.unwrap().as_str())
|
||||||
.to_string(),
|
.to_string(),
|
||||||
),
|
),
|
||||||
sloweffect: Some(
|
sloweffect: Some(
|
||||||
ncfg["sloweffect"]
|
cfg["sloweffect"]
|
||||||
.as_bool()
|
.as_bool()
|
||||||
.unwrap_or(tmpcfg.sloweffect.unwrap()),
|
.unwrap_or(tmpcfg.sloweffect.unwrap()),
|
||||||
),
|
),
|
||||||
refresh: Some(ncfg["refresh"].as_u64().unwrap_or(tmpcfg.refresh.unwrap())),
|
refresh: Some(cfg["refresh"].as_u64().unwrap_or(tmpcfg.refresh.unwrap())),
|
||||||
limit: Some(ncfg["limit"].as_u64().unwrap_or(tmpcfg.limit.unwrap())),
|
limit: Some(cfg["limit"].as_u64().unwrap_or(tmpcfg.limit.unwrap())),
|
||||||
>>>>>>> Stashed changes
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -163,14 +151,7 @@ impl<'a> Config {
|
|||||||
Config::new()
|
Config::new()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
<<<<<<< Updated upstream
|
|
||||||
self.save(&configfile);
|
self.save(&configfile);
|
||||||
=======
|
|
||||||
*self = newcfg;
|
|
||||||
if !fileexists || errorreading {
|
|
||||||
self.save(&configfile).await;
|
|
||||||
}
|
|
||||||
>>>>>>> Stashed changes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, configfile: &str) {
|
async fn save(&self, configfile: &str) {
|
||||||
|
@ -51,7 +51,7 @@ async fn _async_check_zabbix_connection(cfg: &Config) -> Result<bool, reqwest::E
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Build the query that fetchs the token
|
/// Build the query that fetchs the token
|
||||||
fn build_query_auth_token(zabbix_username: &String, zabbix_password: &String) -> Value {
|
fn build_query_auth_token(zabbix_username: &String, zabbix_password: &String) -> JsonValue {
|
||||||
let zabbix_api_function = "user.login";
|
let zabbix_api_function = "user.login";
|
||||||
json!({
|
json!({
|
||||||
"jsonrpc": ZABBIX_API_VERSION,
|
"jsonrpc": ZABBIX_API_VERSION,
|
||||||
@ -88,7 +88,7 @@ fn _build_query_problems(zabbix_token: &String, zabbix_limit: i64) -> JsonValue
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Build the query that fetchs triggers
|
/// Build the query that fetchs triggers
|
||||||
fn build_query_triggers(zabbix_token: &String) -> Value {
|
fn build_query_triggers(zabbix_token: &String) -> JsonValue {
|
||||||
let zabbix_api_function = "trigger.get";
|
let zabbix_api_function = "trigger.get";
|
||||||
json!({
|
json!({
|
||||||
"jsonrpc": ZABBIX_API_VERSION,
|
"jsonrpc": ZABBIX_API_VERSION,
|
||||||
|
Loading…
Reference in New Issue
Block a user