Get info from status page json
This commit is contained in:
parent
d024280878
commit
dbe196f388
8 changed files with 113 additions and 30 deletions
37
src/main.rs
37
src/main.rs
|
|
@ -5,6 +5,7 @@ use std::result::Result::Ok;
|
|||
mod i18n;
|
||||
use i18n::{init_locales, t};
|
||||
mod heartbeat;
|
||||
mod status_page;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(author, version, about)]
|
||||
|
|
@ -19,27 +20,49 @@ struct Args {
|
|||
fn main() -> Result<()> {
|
||||
init_locales()?;
|
||||
let args = Args::parse();
|
||||
let base_url = args.base_url.trim_end_matches("/");
|
||||
|
||||
let heartbeat_url = format!(
|
||||
"{}/api/status-page/heartbeat/{}",
|
||||
args.base_url.trim_end_matches("/"),
|
||||
base_url,
|
||||
args.slug
|
||||
);
|
||||
let status_page_url = format!(
|
||||
"{}/api/status-page/{}",
|
||||
base_url,
|
||||
args.slug
|
||||
);
|
||||
|
||||
let client = Client::new();
|
||||
|
||||
println!("{}", heartbeat_url);
|
||||
println!("Heartbeat URL: {}", heartbeat_url);
|
||||
|
||||
let response = client.get(heartbeat_url).send()?;
|
||||
let heartbeat_response = client.get(heartbeat_url).send()?;
|
||||
|
||||
if response.status().is_success() {
|
||||
let json_text = response.text()?;
|
||||
if heartbeat_response.status().is_success() {
|
||||
let json_text = heartbeat_response.text()?;
|
||||
match heartbeat::parse_response(&json_text) {
|
||||
Ok(data) => println!("moises: {}", data.uptime_data[0].get_perc_formated()),
|
||||
Err(e) => println!("{}", e),
|
||||
}
|
||||
} else {
|
||||
println!("{}", response.status());
|
||||
println!("{}: {}", t("Response"), response.text()?);
|
||||
println!("{}", heartbeat_response.status());
|
||||
println!("{}: {}", t("Response"), heartbeat_response.text()?);
|
||||
}
|
||||
|
||||
println!("Status Page URL: {}", status_page_url);
|
||||
|
||||
let status_page_response = client.get(status_page_url).send()?;
|
||||
|
||||
if status_page_response.status().is_success() {
|
||||
let json_text = status_page_response.text()?;
|
||||
match status_page::parse_response(&json_text) {
|
||||
Ok(data) => println!("moises: {}", data.config.title),
|
||||
Err(e) => println!("{}", e),
|
||||
}
|
||||
} else {
|
||||
println!("{}", status_page_response.status());
|
||||
println!("{}: {}", t("Response"), status_page_response.text()?);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue