use rs_ansible::*; use std::process::Output; use std::str; #[macro_use] extern crate rocket; fn get_result(production: bool) -> Output { let conn_opts = AnsibleConnectionOptions { ask_pass: false, ..Default::default() }; let mut extra_vars_file = vec!["@credentials.yml".into()]; if production { extra_vars_file.push("@src/extra_vars_prod.yml".into()); } else { extra_vars_file.push("@src/extra_vars_testing.yml".into()); } let playbook_opts = AnsiblePlaybookOptions { inventory: "../deployment/inventory/".into(), extra_vars_file, vault_password_file: "pass".into(), ..Default::default() }; let playbook= AnsiblePlaybookCmd { playbooks: vec!["../deployment/playbook_o5gc_test.yml".into()], options: playbook_opts, connection_options: conn_opts, ..Default::default() }; let output = match playbook.run() { Ok(child) => child.wait_with_output(), Err(err) => panic!("Err: {}", err), }; output.unwrap() } #[get("/metrics")] fn hello() -> String { let result_prod = get_result(true); let result_testing = get_result(false); println!("Done running ansible playbooks"); println!("{}", str::from_utf8(&result_prod.stdout).unwrap()); format!("# HELP o5gc_connection_test_status Status code of the ue connection test # TYPE o5gc_connection_test_status gauge o5gc_connection_test_status{{production=\"true\"}} {} o5gc_connection_test_status{{production=\"false\"}} {}" , result_prod.status, result_testing.status ) } // format!(" // # HELP o5gc_connection_test_status Status code of the ue connection test // # TYPE o5gc_connection_test_status gauge // o5gc_connection_test_status {} // # HELP o5gc_connection_test_stdout stdout the ue connection test // # TYPE o5gc_connection_test_stdout untyped // o5gc_connection_test_stdout {} // # HELP o5gc_connection_test_stderr stderr the ue connection test // # TYPE o5gc_connection_test_stderr untyped // o5gc_connection_test_stderr {} // ", out.status, str::from_utf8(&out.stdout).unwrap(), str::from_utf8(&out.stderr).unwrap()) #[launch] fn rocket() -> _ { rocket::build().mount("/", routes![hello]) }