chore: add monitor cloud task
This commit is contained in:
		
							parent
							
								
									af99fca9b8
								
							
						
					
					
						commit
						e1c49d3b8a
					
				@ -12,7 +12,7 @@ This was created to play and sync different roles:
 | 
				
			|||||||
- Handle pre-configured routes for requests (GET/POST)
 | 
					- Handle pre-configured routes for requests (GET/POST)
 | 
				
			||||||
- Use SSL for HTTPS webservers
 | 
					- Use SSL for HTTPS webservers
 | 
				
			||||||
- Serve web client frontend applications and provide them sign-on mechanism
 | 
					- Serve web client frontend applications and provide them sign-on mechanism
 | 
				
			||||||
- Run a websever with templates [Tera](https://tera.netlify.app) multi-language and style customized
 | 
					- Run a websever with templates ([Tera](https://tera.netlify.app)), multi-language and style customized
 | 
				
			||||||
- Run as a File server from a preconfigured directory
 | 
					- Run as a File server from a preconfigured directory
 | 
				
			||||||
- Implement authenticated files upload (backend & frontend via templates)
 | 
					- Implement authenticated files upload (backend & frontend via templates)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										57
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										57
									
								
								src/main.rs
									
									
									
									
									
								
							@ -6,6 +6,11 @@ use app_env::{
 | 
				
			|||||||
  appdata::AppData,
 | 
					  appdata::AppData,
 | 
				
			||||||
  config::{Config,WebServer}
 | 
					  config::{Config,WebServer}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					use clds::clouds::{
 | 
				
			||||||
 | 
						monitor_rules::{MonitorRules},
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					use clds::monitor::run_monitor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use app_auth::AuthStore;
 | 
					use app_auth::AuthStore;
 | 
				
			||||||
use reject_filters::{handle_rejection};
 | 
					use reject_filters::{handle_rejection};
 | 
				
			||||||
// use zterton::models::{Terton};
 | 
					// use zterton::models::{Terton};
 | 
				
			||||||
@ -290,6 +295,34 @@ pub async fn run_check_clouds() {
 | 
				
			|||||||
	let _ = run_clouds_check(&reqenv,&cloud).await;
 | 
						let _ = run_clouds_check(&reqenv,&cloud).await;
 | 
				
			||||||
  println!("Check Cloud service: done {} __________ ",chrono::Utc::now().timestamp());
 | 
					  println!("Check Cloud service: done {} __________ ",chrono::Utc::now().timestamp());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					pub async fn run_clouds_monitor() {
 | 
				
			||||||
 | 
						let args: Vec<String> = std::env::args().collect();
 | 
				
			||||||
 | 
						let mut arg_cfg_path = String::from("");
 | 
				
			||||||
 | 
						let mut arg_env_path = String::from("");
 | 
				
			||||||
 | 
						args.iter().enumerate().for_each(|(idx,arg)| {
 | 
				
			||||||
 | 
							if arg == "-c" { 
 | 
				
			||||||
 | 
								arg_cfg_path=args[idx+1].to_owned();
 | 
				
			||||||
 | 
							} else if arg == "-e" { 
 | 
				
			||||||
 | 
								arg_env_path=args[idx+1].to_owned();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  println!("Monitor Cloud: run {} __________ {} / {} ",chrono::Utc::now().timestamp(),&arg_cfg_path,&arg_env_path);
 | 
				
			||||||
 | 
						let mut cloud = Cloud::default();
 | 
				
			||||||
 | 
						load_cloud_env(&mut cloud).await;	
 | 
				
			||||||
 | 
						let mut app_env = AppEnv::default();
 | 
				
			||||||
 | 
						let config_content = Config::load_file_content("quiet",&arg_cfg_path);
 | 
				
			||||||
 | 
					  if ! config_content.contains("run_mode") {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						app_env.config = Config::new(config_content,"quiet");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let monitor_rules = MonitorRules::load(&app_env.config.monitor_rules_path,&app_env.config.monitor_rules_file,&app_env.config.monitor_rules_format);
 | 
				
			||||||
 | 
						// monitor_rules.rules[0].context = RuleContext::Service(String::from("kubernetes")); 
 | 
				
			||||||
 | 
						if monitor_rules.rules.len() > 0 {
 | 
				
			||||||
 | 
						  let _ = run_monitor(monitor_rules,cloud,app_env).await;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					  println!("Monitor Cloud: done {} __________ ",chrono::Utc::now().timestamp());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
// for standalone server & async use 
 | 
					// for standalone server & async use 
 | 
				
			||||||
// #[tokio::main] 
 | 
					// #[tokio::main] 
 | 
				
			||||||
// pub async fn main() -> Result<()> {
 | 
					// pub async fn main() -> Result<()> {
 | 
				
			||||||
@ -324,8 +357,10 @@ pub fn main() -> Result<()> {
 | 
				
			|||||||
	pretty_env_logger::init();
 | 
						pretty_env_logger::init();
 | 
				
			||||||
//	assert!(output.is_ok());
 | 
					//	assert!(output.is_ok());
 | 
				
			||||||
	let loop_duration: u64;
 | 
						let loop_duration: u64;
 | 
				
			||||||
 | 
						let run_websrvrs: bool;
 | 
				
			||||||
	let run_cache: bool;
 | 
						let run_cache: bool;
 | 
				
			||||||
	let run_check: bool;
 | 
						let run_check: bool;
 | 
				
			||||||
 | 
						let run_monitor: bool;
 | 
				
			||||||
	let websrvrs: Vec<WebServer>;
 | 
						let websrvrs: Vec<WebServer>;
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		let config_content = Config::load_file_content("quiet", &arg_cfg_path);
 | 
							let config_content = Config::load_file_content("quiet", &arg_cfg_path);
 | 
				
			||||||
@ -333,8 +368,10 @@ pub fn main() -> Result<()> {
 | 
				
			|||||||
			let config = Config::new(config_content,"quiet");
 | 
								let config = Config::new(config_content,"quiet");
 | 
				
			||||||
			loop_duration = config.loop_duration;
 | 
								loop_duration = config.loop_duration;
 | 
				
			||||||
			// 	loop_duration = 10;
 | 
								// 	loop_duration = 10;
 | 
				
			||||||
 | 
								run_websrvrs = config.run_websrvrs;
 | 
				
			||||||
			run_cache = config.run_cache;
 | 
								run_cache = config.run_cache;
 | 
				
			||||||
			run_check = config.run_check;
 | 
								run_check = config.run_check;
 | 
				
			||||||
 | 
								run_monitor = config.run_monitor;
 | 
				
			||||||
			websrvrs = config.websrvrs;
 | 
								websrvrs = config.websrvrs;
 | 
				
			||||||
			if run_cache {
 | 
								if run_cache {
 | 
				
			||||||
			  println!("Running 'cloud_cache' every {} seconds in LOOP",&loop_duration);
 | 
								  println!("Running 'cloud_cache' every {} seconds in LOOP",&loop_duration);
 | 
				
			||||||
@ -344,8 +381,10 @@ pub fn main() -> Result<()> {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			loop_duration = 0;
 | 
								loop_duration = 0;
 | 
				
			||||||
 | 
								run_websrvrs = false;
 | 
				
			||||||
			run_cache = false;
 | 
								run_cache = false;
 | 
				
			||||||
			run_check = false;
 | 
								run_check = false;
 | 
				
			||||||
 | 
								run_monitor = false;
 | 
				
			||||||
			websrvrs = Vec::new();
 | 
								websrvrs = Vec::new();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -354,16 +393,20 @@ pub fn main() -> Result<()> {
 | 
				
			|||||||
	let rt = tokio::runtime::Runtime::new().unwrap_or_else(|e| 
 | 
						let rt = tokio::runtime::Runtime::new().unwrap_or_else(|e| 
 | 
				
			||||||
		panic!("Error create tokio runtime {}",e)
 | 
							panic!("Error create tokio runtime {}",e)
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
	// let mut web_tasks = Vec::new();
 | 
						if run_websrvrs {
 | 
				
			||||||
	websrvrs.iter().enumerate().for_each(|(pos,it)| {
 | 
							websrvrs.iter().enumerate().for_each(|(pos,it)| {
 | 
				
			||||||
		rt.block_on(async move {
 | 
								rt.block_on(async move {
 | 
				
			||||||
			println!("{} -> {}",it.name,pos);
 | 
									println!("{} -> {}",it.name,pos);
 | 
				
			||||||
			tokio::spawn(async move {up_web_server(pos).await});
 | 
									tokio::spawn(async move {up_web_server(pos).await});
 | 
				
			||||||
			tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
 | 
									tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	});
 | 
						}
 | 
				
			||||||
	loop {
 | 
						loop {
 | 
				
			||||||
		rt.block_on(async move {
 | 
							rt.block_on(async move {
 | 
				
			||||||
 | 
								if run_monitor {
 | 
				
			||||||
 | 
									tokio::spawn(async {run_clouds_monitor().await }); // For async task
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			if run_check {
 | 
								if run_check {
 | 
				
			||||||
			  tokio::spawn(async {run_check_clouds().await }); // For async task
 | 
								  tokio::spawn(async {run_check_clouds().await }); // For async task
 | 
				
			||||||
			  tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
 | 
								  tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user