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

16
snitch-cli/Cargo.toml Normal file
View File

@ -0,0 +1,16 @@
[package]
name = "snitch"
version = "1.0.0"
edition = "2021"
[dependencies]
snitch-lib = { path = "../snitch-lib" }
log = "0.4"
serde = { version = "1", features = ["derive"] }
chrono = { version = "0.4", features = ["serde"] }
clap = { version = "4.0.23", features = ["derive", "env"] }
eyre = "0.6.12"
color-eyre = "0.6.3"
reqwest = { version = "0.12.7", default-features = false, features = ["rustls-tls", "json", "blocking"] }
serde_json = "1.0.128"

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(())
}