mod buffer;
mod client;
mod commands;
mod config;
mod daemon;
mod probe_docker;
mod probe_ports;
mod probe_resources;
mod probe_systemd;
mod style;
use std::path::PathBuf;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(
name = "stackpatrol",
version,
about = "Server monitoring CLI for StackPatrol"
)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
Init,
Daemon,
Status,
Watch,
AlertTest,
#[command(subcommand)]
Probe(ProbeAction),
}
#[derive(Subcommand)]
enum ProbeAction {
Ls,
#[command(subcommand)]
Add(ProbeTarget),
#[command(subcommand)]
Rm(ProbeTarget),
}
#[derive(Subcommand)]
enum ProbeTarget {
Docker {
path: PathBuf,
},
Systemd {
unit: String,
},
Port {
target: String,
},
}
fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.init();
let cli = Cli::parse();
match cli.command {
Command::Init => commands::init(),
Command::Daemon => runtime()?.block_on(daemon::run()),
Command::AlertTest => runtime()?.block_on(commands::alert_test()),
Command::Status => runtime()?.block_on(commands::status()),
Command::Watch => todo!("M5: tail events being reported"),
Command::Probe(ProbeAction::Ls) => commands::probe_ls(),
Command::Probe(ProbeAction::Add(target)) => match target {
ProbeTarget::Docker { path } => commands::probe_add_docker(path),
ProbeTarget::Systemd { unit } => commands::probe_add_systemd(unit),
ProbeTarget::Port { target } => commands::probe_add_port(target),
},
Command::Probe(ProbeAction::Rm(target)) => match target {
ProbeTarget::Docker { path } => commands::probe_rm_docker(path),
ProbeTarget::Systemd { unit } => commands::probe_rm_systemd(unit),
ProbeTarget::Port { target } => commands::probe_rm_port(target),
},
}
}
fn runtime() -> anyhow::Result<tokio::runtime::Runtime> {
Ok(tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?)
}