STUFUFUFUFF

This commit is contained in:
2024-09-21 14:08:24 +02:00
parent d180e72373
commit 7110a9e8f6
21 changed files with 1190 additions and 370 deletions

54
snitch-cli/src/main.rs Normal file
View File

@ -0,0 +1,54 @@
use chrono::Local;
use clap::Parser;
use eyre::{eyre, WrapErr};
use snitch_lib::{probe_hostname, LogMsg, Severity};
#[derive(Parser)]
struct Opt {
/// URL of snitch
#[clap(long, env = "SNITCH_URL")]
url: String,
/// Name of this service
#[clap(long, env = "SNITCH_SERVICE")]
service: String,
/// Name of this service
#[clap(short, long, env = "SNITCH_SEVERITY", default_value = "Error")]
severity: Severity,
/// Name of this service
#[clap(env = "SNITCH_MESSAGE")]
message: String,
}
fn main() {
if let Err(e) = run() {
eprintln!("snitch error: {e:?}");
}
}
fn run() -> eyre::Result<()> {
let opt = Opt::parse();
color_eyre::install()?;
let message = LogMsg {
time: Some(Local::now()),
severity: opt.severity,
service: opt.service,
message: opt.message,
hostname: probe_hostname(),
file: None,
line: None,
};
let message = serde_json::to_string(&message).wrap_err("Failed to serialize log message")?;
let client = reqwest::blocking::Client::new();
client
.post(&opt.url)
.body(message)
.send()
.wrap_err(eyre!("Failed to upload log message to {:?}", opt.url))?;
Ok(())
}