mirror of
https://github.com/moghtech/komodo.git
synced 2026-05-05 15:34:09 -05:00
1.15.9 (#127)
* add close alert threshold to prevent Ok - Warning back and forth * remove part about repo being deleted, no longer behavior * resource sync share general common * remove this changelog. use releases * remove changelog from readme * write commit file clean up path * docs: supports any git provider repo * fix docs: authorization * multiline command supports escaped newlines * move webhook to build config advanced * parser comments with escaped newline * improve parser * save use Enter. escape monaco using escape * improve logic when deployment / stack action buttons shown * used_mem = total - available * Fix unrecognized path have 404 * webhooks will 404 if misconfigured * move update logger / alerter * delete migrator * update examples * publish typescript client komodo_client
This commit is contained in:
23
example/alerter/Cargo.toml
Normal file
23
example/alerter/Cargo.toml
Normal file
@@ -0,0 +1,23 @@
|
||||
[package]
|
||||
name = "alerter"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
homepage.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
# local
|
||||
komodo_client.workspace = true
|
||||
logger.workspace = true
|
||||
# external
|
||||
tokio.workspace = true
|
||||
tracing.workspace = true
|
||||
axum.workspace = true
|
||||
anyhow.workspace = true
|
||||
serde.workspace = true
|
||||
dotenvy.workspace = true
|
||||
envy.workspace = true
|
||||
14
example/alerter/Dockerfile
Normal file
14
example/alerter/Dockerfile
Normal file
@@ -0,0 +1,14 @@
|
||||
FROM rust:1.80.1 as builder
|
||||
WORKDIR /builder
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN cargo build -p alert_logger --release
|
||||
|
||||
FROM gcr.io/distroless/debian-cc
|
||||
|
||||
COPY --from=builder /builder/target/release/alert_logger /
|
||||
|
||||
EXPOSE 7000
|
||||
|
||||
CMD ["./alert_logger"]
|
||||
4
example/alerter/README.md
Normal file
4
example/alerter/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# Alerter
|
||||
|
||||
This crate sets up a basic axum server that listens for incoming alert POSTs.
|
||||
It can be used as a Komodo alerting endpoint, and serves as a template for other custom alerter implementations.
|
||||
73
example/alerter/src/main.rs
Normal file
73
example/alerter/src/main.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
||||
use std::{net::SocketAddr, str::FromStr};
|
||||
|
||||
use anyhow::Context;
|
||||
use axum::{routing::post, Json, Router};
|
||||
use komodo_client::entities::alert::{Alert, SeverityLevel};
|
||||
use serde::Deserialize;
|
||||
|
||||
/// Entrypoint for handling each incoming alert.
|
||||
async fn handle_incoming_alert(Json(alert): Json<Alert>) {
|
||||
if alert.resolved {
|
||||
info!("Alert Resolved!: {alert:?}");
|
||||
return;
|
||||
}
|
||||
match alert.level {
|
||||
SeverityLevel::Ok => info!("{alert:?}"),
|
||||
SeverityLevel::Warning => warn!("{alert:?}"),
|
||||
SeverityLevel::Critical => error!("{alert:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// ========================
|
||||
/// Http server boilerplate.
|
||||
/// ========================
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Env {
|
||||
#[serde(default = "default_port")]
|
||||
port: u16,
|
||||
}
|
||||
|
||||
fn default_port() -> u16 {
|
||||
7000
|
||||
}
|
||||
|
||||
async fn app() -> anyhow::Result<()> {
|
||||
dotenvy::dotenv().ok();
|
||||
logger::init(&Default::default())?;
|
||||
|
||||
let Env { port } =
|
||||
envy::from_env().context("failed to parse env")?;
|
||||
|
||||
let socket_addr = SocketAddr::from_str(&format!("0.0.0.0:{port}"))
|
||||
.context("invalid socket addr")?;
|
||||
|
||||
info!("v {} | {socket_addr}", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
let app = Router::new().route("/", post(handle_incoming_alert));
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(socket_addr)
|
||||
.await
|
||||
.context("failed to bind tcp listener")?;
|
||||
|
||||
axum::serve(listener, app).await.context("server crashed")
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let mut term_signal = tokio::signal::unix::signal(
|
||||
tokio::signal::unix::SignalKind::terminate(),
|
||||
)?;
|
||||
|
||||
let app = tokio::spawn(app());
|
||||
|
||||
tokio::select! {
|
||||
res = app => return res?,
|
||||
_ = term_signal.recv() => {},
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
19
example/update_logger/Cargo.toml
Normal file
19
example/update_logger/Cargo.toml
Normal file
@@ -0,0 +1,19 @@
|
||||
[package]
|
||||
name = "update_logger"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
homepage.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
# local
|
||||
komodo_client.workspace = true
|
||||
logger.workspace = true
|
||||
# external
|
||||
tokio.workspace = true
|
||||
tracing.workspace = true
|
||||
anyhow.workspace = true
|
||||
14
example/update_logger/Dockerfile
Normal file
14
example/update_logger/Dockerfile
Normal file
@@ -0,0 +1,14 @@
|
||||
FROM rust:1.80.1 as builder
|
||||
WORKDIR /builder
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN cargo build -p update_logger --release
|
||||
|
||||
FROM gcr.io/distroless/debian-cc
|
||||
|
||||
COPY --from=builder /builder/target/release/update_logger /
|
||||
|
||||
EXPOSE 7000
|
||||
|
||||
CMD ["./update_logger"]
|
||||
52
example/update_logger/src/main.rs
Normal file
52
example/update_logger/src/main.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
||||
use komodo_client::{ws::UpdateWsMessage, KomodoClient};
|
||||
|
||||
/// Entrypoint for handling each incoming update.
|
||||
async fn handle_incoming_update(update: UpdateWsMessage) {
|
||||
info!("{update:?}");
|
||||
}
|
||||
|
||||
/// ========================
|
||||
/// Ws Listener boilerplate.
|
||||
/// ========================
|
||||
|
||||
async fn app() -> anyhow::Result<()> {
|
||||
logger::init(&Default::default())?;
|
||||
|
||||
info!("v {}", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
let komodo = KomodoClient::new_from_env().await?;
|
||||
|
||||
let (mut rx, _) = komodo.subscribe_to_updates(1000, 5)?;
|
||||
|
||||
loop {
|
||||
let update = match rx.recv().await {
|
||||
Ok(msg) => msg,
|
||||
Err(e) => {
|
||||
error!("🚨 recv error | {e:?}");
|
||||
break;
|
||||
}
|
||||
};
|
||||
handle_incoming_update(update).await
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let mut term_signal = tokio::signal::unix::signal(
|
||||
tokio::signal::unix::SignalKind::terminate(),
|
||||
)?;
|
||||
|
||||
let app = tokio::spawn(app());
|
||||
|
||||
tokio::select! {
|
||||
res = app => return res?,
|
||||
_ = term_signal.recv() => {},
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user