initial
This commit is contained in:
commit
32fe95d298
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/target
|
||||||
|
credentials*
|
||||||
|
pass
|
||||||
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "exporter"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rocket = "=0.5.0-rc.3"
|
||||||
|
rs-ansible = { git = "https://github.com/snowlaboratories/rs-ansible.git" }
|
||||||
1
src/extra_vars_prod.yml
Normal file
1
src/extra_vars_prod.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
deploy_production: true
|
||||||
1
src/extra_vars_testing.yml
Normal file
1
src/extra_vars_testing.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
deploy_production: false
|
||||||
73
src/main.rs
Normal file
73
src/main.rs
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
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])
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user