Compare commits

...

3 Commits

5 changed files with 258 additions and 261 deletions

View File

@ -1,4 +1,5 @@
use std::collections::{BTreeMap}; use serde::{Serialize, Deserialize};
use std::collections::{HashMap, BTreeMap};
use app_env::{appenv::AppEnv, AppStore}; use app_env::{appenv::AppEnv, AppStore};
use app_auth::{AuthStore}; use app_auth::{AuthStore};
use kloud::{defs::KloudStore, datacontext::DataContext}; use kloud::{defs::KloudStore, datacontext::DataContext};
@ -11,6 +12,8 @@ use connectors::defs::{AppDataConn};
use clds::clouds::defs::{ use clds::clouds::defs::{
CloudEnv, CloudEnv,
Cloud, Cloud,
SrvcsHostInfOut,
InfoStatus,
}; };
use kloud::kloud::Kloud; use kloud::kloud::Kloud;
@ -73,4 +76,13 @@ pub async fn load_key() -> String {
} }
key key
} }
pub type MapCheckInfo = BTreeMap<String,Vec<SrvcsHostInfOut>>;
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct KldCheck {
pub name: String,
pub liveness: HashMap<String, MapCheckInfo>,
pub apps: HashMap<String, MapCheckInfo>,
pub infos: Vec<InfoStatus>,
}

View File

@ -15,12 +15,13 @@ use kloud::{
}; };
use clds::clouds::defs::{Cloud}; use clds::clouds::defs::{Cloud};
use crate::defs::{DataDBs}; // ,CollsData}; use crate::defs::{DataDBs}; // ,CollsData};
use clds::clouds::on_clouds::{on_cloud_req,on_cloud_name_req_info,get_cloud_check,get_apps_check}; use clds::clouds::on_req::{on_cloud_req,on_cloud_name_req_info,get_cache_data};
pub async fn cloud_req(reqname: &str,cloud: &Cloud,reqenv: &ReqEnv,opts: &KloudQueryConfigFilters) -> String { pub async fn cloud_req(reqname: &str,cloud: &Cloud,reqenv: &ReqEnv,opts: &KloudQueryConfigFilters) -> String {
let mut result: String; let mut result: String;
let mut liveness_result = String::from(""); let mut liveness_result = String::from("\"\"");
let mut apps_result = String::from(""); let mut apps_result = String::from("\"\"");
let mut status_result = String::from("\"\"");
if opts.grp.is_empty() { if opts.grp.is_empty() {
result = on_cloud_req(&reqname,&cloud,&reqenv,&opts.tsksrvcs,&opts.srvrs,&opts.cld).await; result = on_cloud_req(&reqname,&cloud,&reqenv,&opts.tsksrvcs,&opts.srvrs,&opts.cld).await;
} else { } else {
@ -30,15 +31,23 @@ pub async fn cloud_req(reqname: &str,cloud: &Cloud,reqenv: &ReqEnv,opts: &KloudQ
} else { } else {
source = format!("{}/{}/{}",&opts.cld,&opts.grp,&opts.name); source = format!("{}/{}/{}",&opts.cld,&opts.grp,&opts.name);
} }
result = on_cloud_name_req_info(&reqname,&cloud,&reqenv,&opts.tsksrvcs,&opts.srvrs,&source).await; let info = on_cloud_name_req_info(&reqname,&cloud,&reqenv,&opts.tsksrvcs,&opts.srvrs,"",&source).await;
result = serde_json::to_string(&info).unwrap_or_else(|e|{
println!("Error serde info {} {}: ",&reqname,e);
String::from("")
});
} }
// cloud_result = get_cloud_cache_req(&reqenv,&cloud, reqname: &str, reqname_job: &str).await
if opts.tsksrvcs.contains("liveness") { if opts.tsksrvcs.contains("liveness") {
liveness_result = get_cloud_check(&reqenv).await; liveness_result = get_cache_data("liveness",&reqenv).await;
} }
if opts.tsksrvcs.contains("apps") { if opts.tsksrvcs.contains("apps") {
apps_result = get_apps_check(&reqenv).await; apps_result = get_cache_data("apps",&reqenv).await;
} }
result = format!("{}:{}{}:{}{}:{}{}",r#"{"req""#,&result,r#","apps""#,&apps_result,r#","liveness""#,&liveness_result,r#"}"#); if opts.tsksrvcs.contains("status") {
status_result = get_cache_data("status",&reqenv).await;
}
result = format!("{}:{}{}:{}{}:{}{}:{}{}",r#"{"clouds""#,&result,r#","apps""#,&apps_result,r#","status""#,&status_result,r#","liveness""#,&liveness_result,r#"}"#);
result.to_owned() result.to_owned()
} }
pub async fn config ( pub async fn config (

View File

@ -35,7 +35,32 @@ use kloud::{
}; };
use crate::defs::{DataDBs}; // ,CollsData}; use crate::defs::{DataDBs}; // ,CollsData};
use app_auth::{User};
pub async fn get_defs_from_req(reqenv: &ReqEnv, prfx: String, user: &User) -> String {
let prfx_path: String;
if prfx.is_empty() {
prfx_path = String::from("ui");
} else {
prfx_path = prfx;
}
let mut path: String;
if user.user_id.is_empty() {
path = format!("{}/profiles/{}/{}/defs.yaml",reqenv.websrvr().resources_path,&prfx_path,"default");
} else {
path = format!("{}/profiles/{}/defs.yaml",reqenv.websrvr().resources_path,&prfx_path);
}
if ! std::path::Path::new(&path).exists() {
path = format!("{}/profiles/{}/defs.yaml",reqenv.websrvr().resources_path,&prfx_path);
}
let content = Profile::load_fs_content(path.into());
// let lang = opts.lang.unwrap_or_else(|| String::from("es"));
// let section = opts.section.unwrap_or_else(|| String::from(""));
// let lang_items = LangItems::new("langs/ta",&lang,"yaml");
// let result = lang_items.get_items_str(&section);
let res = Profile::to_yaml(content); // String::from("");
serde_json::to_string(&res).unwrap_or_else(|_| String::from(""))
}
// warp::generic::Either<(std::string::String,), (std::string::String,)> // warp::generic::Either<(std::string::String,), (std::string::String,)>
pub async fn langs( pub async fn langs(
opts: KloudQueryLangFilters, opts: KloudQueryLangFilters,
@ -105,7 +130,7 @@ pub async fn defs(
let reqenv = ReqEnv::new(db.app, db.auth, header, method, "/defs", "defs", &prfx); let reqenv = ReqEnv::new(db.app, db.auth, header, method, "/defs", "defs", &prfx);
// let allow_origin = reqenv.websrvr().allow_origin; // let allow_origin = reqenv.websrvr().allow_origin;
match reqenv.user_authentication().await { match reqenv.user_authentication().await {
Ok(auth) => { Ok(_auth) => {
// dbg!("auth: {}",&auth); // dbg!("auth: {}",&auth);
// println!("User: {} | {}",&user.user_id,&user.token); // println!("User: {} | {}",&user.user_id,&user.token);
// if let Some(lang) = reqtasks.params().get("lang") { // if let Some(lang) = reqtasks.params().get("lang") {
@ -115,18 +140,7 @@ pub async fn defs(
// } // }
// log::debug!("LANG: {} - {}",language, lang); // log::debug!("LANG: {} - {}",language, lang);
// dbg!("LANG: {} - {}",language, lang); // dbg!("LANG: {} - {}",language, lang);
let result = get_defs_from_req(&reqenv, prfx.to_owned(), &reqenv.get_user().await).await;
let mut path = format!("{}/profiles/{}/{}/defs.yaml",reqenv.websrvr().resources_path,&prfx,&auth.user_id);
if ! std::path::Path::new(&path).exists() {
path = format!("{}/profiles/{}/defs.yaml",reqenv.websrvr().resources_path,&prfx);
}
let content = Profile::load_fs_content(path.into());
// let lang = opts.lang.unwrap_or_else(|| String::from("es"));
// let section = opts.section.unwrap_or_else(|| String::from(""));
// let lang_items = LangItems::new("langs/ta",&lang,"yaml");
// let result = lang_items.get_items_str(&section);
let res = Profile::to_yaml(content); // String::from("");
let result = serde_json::to_string(&res).unwrap_or_else(|_| String::from(""));
Ok(warp::http::Response::builder() Ok(warp::http::Response::builder()
.body(result.to_string()) .body(result.to_string())
.into_response()) .into_response())

View File

@ -13,110 +13,164 @@ use app_auth::{UserCtx};
// KloudQueryConfigFilters, // KloudQueryConfigFilters,
// }, // },
// }; // };
use clds::defs::{KloudCheckHome}; use clds::defs::{KloudCheckHome,CloudCheckItem};
use clds::clouds::defs::{Cloud,SrvcsHostInfo,App,AppsrvcInfo,TskSrvc,TsksrvcInfo}; use clds::status::{get_statusinfo_fileslist,load_statusinfo};
use crate::defs::{DataDBs}; // ,CollsData}; use clds::clouds::defs::{Cloud,SrvcsHostInfOut,AppOut,AppsrvcInfo,AppsrvcInfOut, TskSrvcOut, TsksrvcInfo, TsksrvcInfOut,InfoStatus};
use clds::clouds::on_clouds::{get_cloud_check,get_apps_check}; use clds::clouds::on_req::{get_cache_data};
// use app_env::appenv::{Rol,Policy};
pub async fn get_tsks_apps_check(reqenv: &ReqEnv, cld_indx: usize, _auth: UserCtx, role: &str) -> String { use crate::defs::{KldCheck, MapCheckInfo, DataDBs}; // ,CollsData};
let result_apps = get_apps_check(&reqenv).await; use crate::handlers::h_defs::{get_defs_from_req};
// println!("Result apps: {}",&result_apps);
let res_apps: Vec<KloudCheckHome> = serde_json::from_str(&result_apps).unwrap_or_else(|e| { pub fn tsks_info_on_role(role: String, tsksrvcs: Vec<TsksrvcInfo>) -> Vec<TsksrvcInfOut> {
println!("Error serde apps json: {}",e); tsksrvcs.into_iter().map(|tsk| {
let srvc = match role.as_str() {
"admin" =>
TskSrvcOut {
name: tsk.srvc.name.to_owned(),
path: tsk.srvc.path.to_owned(),
req: tsk.srvc.req.to_owned(),
target: tsk.srvc.target.to_owned(),
liveness: tsk.srvc.liveness.to_owned(),
critical: tsk.srvc.critical.to_owned(),
},
_ =>
TskSrvcOut {
name: tsk.srvc.name.to_owned(),
path: String::from(""),
req: String::from(""),
target: tsk.srvc.target.to_owned(),
liveness: String::from(""),
critical: tsk.srvc.critical.to_owned(),
},
};
TsksrvcInfOut {
name: tsk.name.to_owned(),
info: tsk.info.to_owned(),
srvc
}
}).collect()
}
pub fn app_info_on_role(role: String, appsrvcs: Vec<AppsrvcInfo>) -> Vec<AppsrvcInfOut> {
appsrvcs.into_iter().map(|app| {
let srvc = match role.as_str() {
"admin" =>
AppOut {
name: app.srvc.name.to_owned(),
path: app.srvc.path.to_owned(),
req: app.srvc.req.to_owned(),
target: app.srvc.target.to_owned(),
liveness: app.srvc.liveness.to_owned(),
critical: app.srvc.critical.to_owned(),
},
_ =>
AppOut {
name: app.srvc.name.to_owned(),
path: String::from(""),
req: String::from(""),
target: app.srvc.target.to_owned(),
liveness: String::from(""),
critical: app.srvc.critical.to_owned(),
},
};
AppsrvcInfOut {
name: app.name.to_owned(),
info: app.info.to_owned(),
srvc
}
}).collect()
}
pub fn collect_clouds_check_items(role: &str, items: &Vec<CloudCheckItem> ) -> BTreeMap<String,Vec<SrvcsHostInfOut>> {
let mut m_items = BTreeMap::new();
items.iter().for_each(|itm| {
let liveness: Vec<SrvcsHostInfOut>;
liveness = itm.liveness.to_owned().into_iter().map(|it| {
SrvcsHostInfOut {
hostname: format!("{}",&it.hostname),
tsksrvcs: tsks_info_on_role(role.to_owned(), it.tsksrvcs),
appsrvcs: app_info_on_role(role.to_owned(), it.appsrvcs),
}
}).collect();
m_items.insert(format!("{}",&itm.name),liveness);
});
m_items
}
pub async fn get_info_status(reqenv: &ReqEnv,kld: &KloudCheckHome) -> Vec<InfoStatus> {
let kld_statusinfo_files: Vec<String> = get_statusinfo_fileslist(&reqenv.config().state_path,&kld.name).await.unwrap_or_else(|e|{
println!("Error on infos {}: {}",&kld.name,e);
Vec::new()
});
load_statusinfo(&format!("{}/{}",&reqenv.config().state_path,&kld.name), kld_statusinfo_files).await
}
pub async fn get_tsks_apps_check(reqenv: &ReqEnv,_auth: UserCtx, role: &str, prfx: String) -> String {
let result_data: String;
let res_liveness: Vec<KloudCheckHome>;
let result_status = get_cache_data("status",&reqenv).await;
if result_status.is_empty() {
let result_liveness = get_cache_data("liveness",&reqenv).await;
result_data = get_cache_data("apps",&reqenv).await;
res_liveness = serde_json::from_str(&result_liveness).unwrap_or_else(|e| {
println!("Error serde liveness json: {}",e);
Vec::new()
});
} else {
result_data = result_status;
res_liveness = Vec::new();
}
let res_data: Vec<KloudCheckHome> = serde_json::from_str(&result_data).unwrap_or_else(|e| {
println!("Error serde status json: {}",e);
Vec::new() Vec::new()
}); });
// let mut list_groups = String::from("");
let mut grp_apps_hash: HashMap<String, BTreeMap<String,Vec<SrvcsHostInfo>>> = HashMap::new(); let mut kld_check: Vec<KldCheck> = Vec::new();
if let Some(kld) = res_apps.get(cld_indx) { for kld in res_data {
for grp in &kld.groups { // let mut list_groups = String::from("");
let mut grp_check_hash: HashMap<String, MapCheckInfo> = HashMap::new();
kld.groups.iter().for_each(|grp| {
// if !list_groups.is_empty() { // if !list_groups.is_empty() {
// list_groups.push(','); // list_groups.push(',');
// } // }
// list_groups.push_str(&grp.name); // list_groups.push_str(&grp.name);
let mut m_items = BTreeMap::new(); grp_check_hash.insert(format!("{}",grp.name),collect_clouds_check_items(&role,&grp.items));
for itm in &grp.items { });
let liveness: Vec<SrvcsHostInfo>;
if role.is_empty() { kld_check.push(KldCheck {
liveness = itm.liveness.to_owned().into_iter().map(|it| { name: kld.name.to_owned(),
SrvcsHostInfo { liveness: HashMap::new(),
hostname: format!("{}",&it.hostname), apps: grp_check_hash,
tsksrvcs: it.tsksrvcs.to_owned(), infos: get_info_status(reqenv, &kld).await,
appsrvcs: it.appsrvcs.into_iter().map(|ap| { });
AppsrvcInfo { };
name: ap.name.to_owned(), for kld in res_liveness {
info: ap.info.to_owned(), let mut grp_check_hash: HashMap<String, MapCheckInfo> = HashMap::new();
srvc: App { kld.groups.iter().for_each(|grp| {
name: ap.srvc.name.to_owned(), grp_check_hash.insert(format!("{}",grp.name),collect_clouds_check_items(&role,&grp.items));
path: String::from(""), });
req: String::from(""), // dbg!(&kld_statusinfo_files);
target: ap.srvc.target.to_owned(), if kld_check.len() == 0 {
liveness: String::from(""), kld_check.push(KldCheck {
critical: ap.srvc.critical.to_owned(), name: kld.name.to_owned(),
} apps: HashMap::new(),
} liveness: grp_check_hash,
}).collect() infos: get_info_status(reqenv, &kld).await,
} });
}).collect(); } else {
} else { let mut kldix = 0;
liveness = itm.liveness.to_owned(); kld_check.iter().enumerate().for_each(|(idx,k)| {
if k.name == kld.name {
kldix = idx;
} }
m_items.insert(format!("{}",&itm.name),liveness); });
} kld_check[kldix].liveness = grp_check_hash.to_owned();
grp_apps_hash.insert(format!("{}",grp.name),m_items);
} }
} };
let result_cloud = get_cloud_check(&reqenv).await; let check_json=serde_json::to_string(&kld_check).unwrap_or_else(|e|{
// println!("Result cloud: {}",&result_cloud);
let res_cloud: Vec<KloudCheckHome> = serde_json::from_str(&result_cloud).unwrap_or_else(|e| {
println!("Error serde apps json: {}",e);
Vec::new()
});
let mut grp_cloud_hash: HashMap<String, BTreeMap<String,Vec<SrvcsHostInfo>>> = HashMap::new();
if let Some(kld) = res_cloud.get(cld_indx) {
for grp in &kld.groups {
let mut m_items = BTreeMap::new();
for itm in &grp.items {
let liveness: Vec<SrvcsHostInfo>;
if role.is_empty() {
liveness = itm.liveness.to_owned().into_iter().map(|it| {
SrvcsHostInfo {
hostname: format!("{}",&it.hostname),
appsrvcs: it.appsrvcs.to_owned(),
tsksrvcs: it.tsksrvcs.into_iter().map(|tsk| {
TsksrvcInfo {
name: tsk.name.to_owned(),
info: tsk.info.to_owned(),
srvc: TskSrvc {
name: tsk.srvc.name.to_owned(),
path: String::from(""),
req: String::from(""),
target: tsk.srvc.target.to_owned(),
liveness: String::from(""),
critical: tsk.srvc.critical.to_owned(),
}
}
}).collect()
}
}).collect();
} else {
liveness = itm.liveness.to_owned();
}
m_items.insert(format!("{}",&itm.name),liveness.to_owned());
}
grp_cloud_hash.insert(format!("{}",grp.name),m_items);
}
}
// ctx.insert("groups_cloud".to_string(),&grp_cloud_hash);
let res_apps_json=serde_json::to_string(&grp_apps_hash).unwrap_or_else(|e|{
println!("Error serde from value: {}",e); println!("Error serde from value: {}",e);
String::from("") String::from("")
}); });
let res_cloud_json=serde_json::to_string(&grp_cloud_hash).unwrap_or_else(|e|{ let defs_json = get_defs_from_req(&reqenv, prfx.to_owned(), &reqenv.get_user().await).await;
println!("Error serde from value: {}",e); format!("{}:{}{}:{}{}",r#"{"check""#,&check_json,r#","defs""#,&defs_json,r#"}"#).to_owned()
String::from("") // serde_json::to_string(self).unwrap_or_else(|_| String::from("")).replace("\n","")
});
let result = format!("{}:{}{}:{}{}",r#"{"group_apps""#,&res_apps_json,r#","group_cloud""#,&res_cloud_json,r#"}"#);
result.to_owned()
} }
pub async fn home( pub async fn home(
header: HeaderMap<HeaderValue>, header: HeaderMap<HeaderValue>,
@ -145,7 +199,7 @@ pub async fn home(
// dbg!("LANG: {} - {}",language, lang); // dbg!("LANG: {} - {}",language, lang);
let role = reqenv.req.user_role().await; let role = reqenv.req.user_role().await;
// reqenv.is_admin() // reqenv.is_admin()
let result = get_tsks_apps_check(&reqenv,1,auth,&role).await; let result = get_tsks_apps_check(&reqenv,auth,&role,prfx.to_owned()).await;
// let mut path = format!("{}/profiles/{}/{}/defs.yaml",reqenv.websrvr().resources_path,&prfx,&auth.user_id); // let mut path = format!("{}/profiles/{}/{}/defs.yaml",reqenv.websrvr().resources_path,&prfx,&auth.user_id);
// if ! std::path::Path::new(&path).exists() { // if ! std::path::Path::new(&path).exists() {
// path = format!("{}/profiles/{}/defs.yaml",reqenv.websrvr().resources_path,&prfx); // path = format!("{}/profiles/{}/defs.yaml",reqenv.websrvr().resources_path,&prfx);
@ -164,32 +218,14 @@ pub async fn home(
Ok(warp::http::Response::builder() Ok(warp::http::Response::builder()
.body(result.to_string()) .body(result.to_string())
.into_response()) .into_response())
/*
Ok(warp::reply::with_header(
warp::http::Response::new(result),
"Access-Control-Allow-Origin",
&allow_origin))
*/
// warp::reply::json(&res),
// Ok(warp::reply::with_header(
// warp::http::Response::new(result),
// "Access-Control-Allow-Origin",
// &allow_origin))
// Ok(warp::reply::json(&result))
}, },
Err(_e) => { Err(_e) => {
// let result = format!("Error: no credentials found"); // let result = format!("Error: no credentials found");
// println!("{}",e); // println!("{}",e);
let result = get_tsks_apps_check(&reqenv,1,UserCtx::default(),"").await; let result = get_tsks_apps_check(&reqenv,UserCtx::default(),"",prfx.to_owned()).await;
Ok(warp::http::Response::builder() Ok(warp::http::Response::builder()
.body(result.to_string()) .body(result.to_string())
.into_response()) .into_response())
/*
Ok(warp::reply::with_header(
warp::http::Response::new(result),
"Access-Control-Allow-Origin",
&allow_origin))
*/
} }
} }
} }

View File

@ -24,7 +24,13 @@ use crate::defs::{DataDBs,CollsData,load_cloud_env};
use clds::clouds::defs::{ use clds::clouds::defs::{
Cloud, Cloud,
}; };
use clds::clouds::on_clouds::{env_cloud,make_cloud_cache,run_clouds_check,run_apps_check}; use clds::clouds::utils::{
env_cloud,
};
use clds::clouds::on_req::{
run_cache_data,
make_cloud_cache,
};
use reqenv::ReqEnv; use reqenv::ReqEnv;
// static WEBSERVER: AtomicUsize = AtomicUsize::new(0); // static WEBSERVER: AtomicUsize = AtomicUsize::new(0);
@ -222,95 +228,49 @@ async fn set_reqenv(app_env: &AppEnv,verbose: isize) -> ReqEnv {
"/config", "config", "kloud" "/config", "config", "kloud"
) )
} }
pub async fn run_cache_clouds() -> Result<()> { pub async fn run_on_clouds(target_task: &str) -> Result<()> {
let (arg_cfg_path,arg_env_path) = get_args(); let (arg_cfg_path,arg_env_path) = get_args();
let now = chrono::Utc::now().timestamp(); let now = chrono::Utc::now().timestamp();
let verbose = envmnt::get_isize("DEBUG", 0); let verbose = envmnt::get_isize("DEBUG", 0);
if verbose > 0 { if verbose > 0 {
println!("Cache service on Clouds: run {} __________ {} {} ",&now,&arg_cfg_path,&arg_env_path); println!("{} service on Clouds: run {} __________ {} {} ",&target_task,&now,&arg_cfg_path,&arg_env_path);
} }
let (cloud, app_env) = match get_app_env(arg_cfg_path,verbose).await { let (cloud, app_env) = match get_app_env(arg_cfg_path,verbose).await {
Ok((c,e)) => (c,e), Ok((c,e)) => (c,e),
Err(e) => { Err(e) => {
println!("Cache service on Clouds: done {} __________ ",&now); println!("{} service on Clouds: errors {} __________ ",&target_task,&now);
return Err(e); return Err(e);
}, },
}; };
let reqenv = set_reqenv(&app_env,verbose).await; let reqenv = set_reqenv(&app_env,verbose).await;
let res = make_cloud_cache(&reqenv,&cloud).await; let res = match target_task {
if verbose > 0 { "monitor" => {
println!("Cache service on Clouds: done {} __________ ",&now); let monitor_rules = MonitorRules::load(
} &app_env.config.monitor_rules_path,
res &app_env.config.monitor_rules_file,
} &app_env.config.monitor_rules_format
pub async fn run_check_clouds() -> Result<()> { );
let (arg_cfg_path,arg_env_path) = get_args(); if monitor_rules.rules.len() == 0 {
let now = chrono::Utc::now().timestamp(); eprintln!("No monitor rules found");
let verbose = envmnt::get_isize("DEBUG", 0); return Ok(());
if verbose > 0 { }
println!("Check Cloud services: run {} __________ {} {} ",&now,&arg_cfg_path,&arg_env_path); monitor_rules.run(cloud,app_env).await
} },
let (cloud, app_env) = match get_app_env(arg_cfg_path,verbose).await { "apps" =>
Ok((c,e)) => (c,e), run_cache_data(&target_task,&reqenv,&cloud,&target_task,"*").await,
Err(e) => { "liveness" =>
println!("Check Cloud services: done {} __________ ",&now); run_cache_data(&target_task,&reqenv,&cloud,"monitor,liveness","*").await,
return Err(e); "status" =>
}, run_cache_data(&target_task,&reqenv,&cloud,"monitor,status","*").await,
"cache" =>
make_cloud_cache(&reqenv,&cloud).await,
_ => {
eprintln!("Error scheduling task {}",&target_task);
Ok(())
}
}; };
let reqenv = set_reqenv(&app_env,verbose).await;
let res = run_clouds_check(&reqenv,&cloud).await;
if verbose > 0 { if verbose > 0 {
println!("Check Cloud services: done {} __________ ",&now); println!("{} service on Clouds: done {} __________ ",&target_task,&now);
}
res
}
pub async fn run_check_apps() -> Result<()> {
let (arg_cfg_path,arg_env_path) = get_args();
let now = chrono::Utc::now().timestamp();
let verbose = envmnt::get_isize("DEBUG", 0);
if verbose > 0 {
println!("Check Apps services: run {} __________ {} {} ",&now,&arg_cfg_path,&arg_env_path);
}
let (cloud, app_env) = match get_app_env(arg_cfg_path,verbose).await {
Ok((c,e)) => (c,e),
Err(e) => {
println!("Check Apps services: done {} __________ ",&now);
return Err(e);
},
};
let reqenv = set_reqenv(&app_env,verbose).await;
let res = run_apps_check(&reqenv,&cloud).await;
if verbose > 0 {
println!("Check Apps services: done {} __________ ",&now);
}
res
}
pub async fn run_clouds_monitor() -> Result<()> {
let (arg_cfg_path,arg_env_path) = get_args();
let now = chrono::Utc::now().timestamp();
let verbose = envmnt::get_isize("DEBUG", 0);
if verbose > 0 {
println!("Monitor Cloud: run {} __________ {} {} ",&now,arg_cfg_path,&arg_env_path);
}
let (cloud, app_env) = match get_app_env(arg_cfg_path,verbose).await {
Ok((c,e)) => (c,e),
Err(e) => {
println!("Monitor Cloud done {} __________ ",&now);
return Err(e);
},
};
let monitor_rules = MonitorRules::load(
&app_env.config.monitor_rules_path,
&app_env.config.monitor_rules_file,
&app_env.config.monitor_rules_format
);
if monitor_rules.rules.len() == 0 {
eprintln!("No monitor rules found");
return Ok(());
}
let res = monitor_rules.run(cloud,app_env).await;
if verbose > 0 {
println!("Monitor Cloud done {} __________ ",&now);
} }
res res
} }
@ -352,25 +312,18 @@ pub async fn main() -> BxDynResult<()> { //std::io::Result<()> {
} }
let config = Config::new(config_content,debug); let config = Config::new(config_content,debug);
let app_data_conn = AppDataConn::new("Zterton".to_string(),config.datastores_settings.to_owned(),"").await; let app_data_conn = AppDataConn::new("Zterton".to_string(),config.datastores_settings.to_owned(),"").await;
if !app_data_conn.check_connections(config.datastores_settings.to_owned()).await { if config.datastores_settings.len() > 0 {
println!("Error checking app data store connections"); if !app_data_conn.check_connections(config.datastores_settings.to_owned()).await {
} println!("Error checking app data store connections");
}
}
if config.run_schedtasks { if config.run_schedtasks {
for it in &config.schedtasks { config.schedtasks.clone().iter().for_each(|it| {
if ! it.on_start { if it.on_start {
continue; let name:&'static str = Box::leak(format!("{}",&it.name).into_boxed_str());
tokio::spawn(async move {run_on_clouds(name).await});
} }
match it.name.as_str() { });
"monitor" => tokio::spawn(async {run_clouds_monitor().await}),
"check" => tokio::spawn(async {run_check_clouds().await}),
"cache" => tokio::spawn(async {run_cache_clouds().await}),
"apps" => tokio::spawn(async {run_check_apps().await}),
_ => {
eprintln!("Error task {} not defined",&it.name);
continue;
},
};
}
} }
if config.run_websrvrs { if config.run_websrvrs {
for (pos,it) in config.websrvrs.iter().enumerate() { for (pos,it) in config.websrvrs.iter().enumerate() {
@ -382,45 +335,18 @@ pub async fn main() -> BxDynResult<()> { //std::io::Result<()> {
} }
} }
if config.run_schedtasks { if config.run_schedtasks {
for it in config.schedtasks { for it in config.schedtasks.clone() {
if it.schedule.is_empty() { if it.schedule.is_empty() {
eprintln!("Task {} no schedule defined",&it.name); eprintln!("Task {} no schedule defined",&it.name);
continue; continue;
} }
let res = match it.name.as_str() { let res = sched.add(Job::new(&it.schedule.to_owned(), move |uuid, _l| {
"monitor" => if debug > 0 {
sched.add(Job::new(&it.schedule.to_owned(), move |uuid, _l| { println!("Schedule {} {}: {}",&it.name,&it.schedule,uuid);
if debug > 0 { }
println!("Schedule {} {}: {}",&it.name,&it.schedule,uuid); let name:&'static str = Box::leak(format!("{}",&it.name).into_boxed_str());
} tokio::spawn(async move {run_on_clouds(name).await});
tokio::spawn(async {run_clouds_monitor().await}); })?);
})?),
"check" =>
sched.add(Job::new(&it.schedule.to_owned(), move |uuid, _l| {
if debug > 0 {
println!("Schedule {} {}: {}",&it.name,&it.schedule,uuid);
}
tokio::spawn(async {run_check_clouds().await});
})?),
"apps" =>
sched.add(Job::new(&it.schedule.to_owned(), move |uuid, _l| {
if debug > 0 {
println!("Schedule {} {}: {}",&it.name,&it.schedule,uuid);
}
tokio::spawn(async {run_check_apps().await});
})?),
"cache" =>
sched.add(Job::new(&it.schedule.to_owned(), move |uuid, _l| {
if debug > 0 {
println!("Schedule {} {}: {}",&it.name,&it.schedule,uuid);
}
tokio::spawn(async {run_cache_clouds().await});
})?),
_ => {
eprintln!("Error task {} not defined",&it.name);
continue;
},
};
match res { match res {
Ok(_) => { continue; }, Ok(_) => { continue; },
Err(e) => { Err(e) => {