First commit
This commit is contained in:
commit
4cedb17b60
6 changed files with 2094 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
/target
|
||||||
2010
Cargo.lock
generated
Normal file
2010
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
12
Cargo.toml
Normal file
12
Cargo.toml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
[package]
|
||||||
|
name = "uptime-kuma-dashboard"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
clap = { version = "4.5", features = ["derive", "env"] }
|
||||||
|
reqwest = { version = "0.12", features = ["blocking", "json"] }
|
||||||
|
anyhow = "1.0"
|
||||||
|
fluent-templates = "0.13.2"
|
||||||
|
unic-langid = "0.9.6"
|
||||||
|
sys-locale = "0.3.2"
|
||||||
5
src/locales/en-US/main.ftl
Normal file
5
src/locales/en-US/main.ftl
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
missing_url = ❌ URL not provided. Use --url or environment variable UPTIME_KUMA_URL
|
||||||
|
missing_api_key = ❌ API key not provided. Use --api-key or environment variable UPTIME_KUMA_API_KEY
|
||||||
|
success = ✅ Metrics received successfully!
|
||||||
|
metrics_preview = 📋 First 200 characters of metrics:
|
||||||
|
Response = Response
|
||||||
5
src/locales/pt-BR/main.ftl
Normal file
5
src/locales/pt-BR/main.ftl
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
success = ✅ Métricas recebidas com sucesso!
|
||||||
|
metrics_preview = 📋 Primeiras 200 caracteres das métricas:
|
||||||
|
missing_api_key = ❌ API key não fornecida. Use --api-key ou a variável de ambiente UPTIME_API_KEY
|
||||||
|
missing_url = ❌ URL não fornecida. Use --url ou a variável de ambiente UPTIME_URL
|
||||||
|
Response = Resposta
|
||||||
61
src/main.rs
Normal file
61
src/main.rs
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use anyhow::{Ok, Result};
|
||||||
|
use clap::Parser;
|
||||||
|
use fluent_templates::{Loader, static_loader};
|
||||||
|
use reqwest::blocking::Client;
|
||||||
|
use unic_langid::LanguageIdentifier;
|
||||||
|
|
||||||
|
static_loader! {
|
||||||
|
static LOCALES = {
|
||||||
|
locales: "./src/locales",
|
||||||
|
fallback_language: "pt-BR",
|
||||||
|
customise: |bundle| bundle.set_use_isolating(false),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Parser)]
|
||||||
|
#[command(author, version, about)]
|
||||||
|
struct Args {
|
||||||
|
#[arg(short, long, env = "UPTIME_KUMA_URL")]
|
||||||
|
url: Option<String>,
|
||||||
|
|
||||||
|
#[arg(short, long, env = "UPTIME_KUMA_API_KEY")]
|
||||||
|
api_key: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_sys_locale() -> LanguageIdentifier {
|
||||||
|
let sys_lang = sys_locale::get_locale().unwrap_or_else(|| String::from("pt-BR"));
|
||||||
|
LanguageIdentifier::from_str(&sys_lang).expect("Invalid language")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn t(key: &str) -> String {
|
||||||
|
LOCALES.lookup(&get_sys_locale(), key)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
let args = Args::parse();
|
||||||
|
let url = args
|
||||||
|
.url
|
||||||
|
.as_deref()
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("{}", t("missing_url")))?;
|
||||||
|
let api_key = args
|
||||||
|
.api_key
|
||||||
|
.as_deref()
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("{}", t("missing_api_key")))?;
|
||||||
|
|
||||||
|
let client = Client::new();
|
||||||
|
|
||||||
|
let response = client.get(url).basic_auth("", Some(api_key)).send()?;
|
||||||
|
|
||||||
|
if response.status().is_success() {
|
||||||
|
let metrics = response.text()?;
|
||||||
|
println!("{}", t("success"));
|
||||||
|
println!("{}", t("metrics_preview"));
|
||||||
|
println!("{}", &metrics[..200.min(metrics.len())]);
|
||||||
|
} else {
|
||||||
|
println!("{}", response.status());
|
||||||
|
println!("{}: {}", t("Response"), response.text()?);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue