diff --git a/.github/workflows/docker-build-push.yml b/.github/workflows/docker-build-push.yml index e73d532..daf91ab 100644 --- a/.github/workflows/docker-build-push.yml +++ b/.github/workflows/docker-build-push.yml @@ -16,8 +16,20 @@ jobs: include: - name: "ghcr.io/bigboot/autokuma" dockerfile: Dockerfile + build_args: "" + tag_prefix: "" - name: "ghcr.io/bigboot/kuma" dockerfile: Dockerfile.cli + build_args: "" + tag_prefix: "" + - name: "ghcr.io/bigboot/autokuma" + dockerfile: Dockerfile + build_args: "FEATURES=uptime-kuma-v2" + tag_prefix: "uptime-kuma-v2-" + - name: "ghcr.io/bigboot/kuma" + dockerfile: Dockerfile.cli + build_args: "FEATURES=uptime-kuma-v2" + tag_prefix: "uptime-kuma-v2-" steps: - uses: actions/checkout@v4 @@ -37,6 +49,10 @@ jobs: type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} type=sha + flavor: | + latest=auto + prefix=${{ matrix.tag_prefix }},onlatest=true + suffix= - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -56,7 +72,7 @@ jobs: uses: docker/build-push-action@v5 with: context: . - platforms: ${{ contains(github.ref, 'tags/') && 'linux/amd64,linux/arm64' || 'linux/amd64' }} + platforms: ${{ 'linux/amd64,linux/arm64' }} file: ${{ matrix.dockerfile }} push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} diff --git a/Dockerfile b/Dockerfile index daf6c86..e1241db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,10 @@ -FROM rust:1.81 as builder +ARG FEATURES= + +FROM rust:1.81 AS builder +ARG FEATURES WORKDIR /usr/src/autokuma COPY . . -RUN cargo install --path ./autokuma +RUN cargo install --features "${FEATURES}" --path ./autokuma FROM debian:bookworm-slim RUN apt-get update && apt-get install -y \ diff --git a/Dockerfile.cli b/Dockerfile.cli index 4d36b5f..76655b1 100644 --- a/Dockerfile.cli +++ b/Dockerfile.cli @@ -1,7 +1,10 @@ -FROM rust:1.81 as builder +ARG FEATURES= + +FROM rust:1.81 AS builder +ARG FEATURES WORKDIR /usr/src/autokuma COPY . . -RUN cargo install --path ./kuma-cli +RUN cargo install --features "${FEATURES}" --path ./kuma-cli FROM debian:bookworm-slim RUN apt-get update && apt-get install -y \ diff --git a/autokuma/Cargo.toml b/autokuma/Cargo.toml index 41238a0..afab57a 100644 --- a/autokuma/Cargo.toml +++ b/autokuma/Cargo.toml @@ -19,6 +19,7 @@ required-features = ["kubernetes"] default = ["kubernetes"] kubernetes = ["dep:kube", "dep:k8s-openapi", "dep:schemars", "dep:serde_yaml"] tokio-console = ["dep:console-subscriber", "tokio/tracing"] +uptime-kuma-v2 = ["kuma-client/uptime-kuma-v2"] [dependencies] kuma-client = { path = "../kuma-client", version = "0.0.0", features = [ diff --git a/kuma-cli/Cargo.toml b/kuma-cli/Cargo.toml index f99f19b..2ce0863 100644 --- a/kuma-cli/Cargo.toml +++ b/kuma-cli/Cargo.toml @@ -14,6 +14,9 @@ keywords = ["uptime-kuma", "api", "automation", "monitoring", "socketio"] name = "kuma" path = "src/main.rs" +[features] +uptime-kuma-v2 = ["kuma-client/uptime-kuma-v2"] + [dependencies] kuma-client = { path = "../kuma-client", version = "0.0.0" } diff --git a/kuma-client/Cargo.toml b/kuma-client/Cargo.toml index d04df27..144be59 100644 --- a/kuma-client/Cargo.toml +++ b/kuma-client/Cargo.toml @@ -12,6 +12,7 @@ keywords = ["uptime-kuma", "api", "monitoring"] [features] private-api = [] +uptime-kuma-v2 = [] [dependencies] config = { workspace = true } diff --git a/kuma-client/src/models/monitor.rs b/kuma-client/src/models/monitor.rs index 9fb4b84..676ba67 100644 --- a/kuma-client/src/models/monitor.rs +++ b/kuma-client/src/models/monitor.rs @@ -157,6 +157,13 @@ macro_rules! monitor_type { #[serde_as(as = "Option>")] pub tag_names: Option>, + + #[cfg(feature = "uptime-kuma-v2")] + #[serde(rename = "conditions")] + #[serde_as(as = "Option>")] + #[serde_inline_default(Some(vec![]))] + pub conditions: Option>, + $($field)* } @@ -281,6 +288,14 @@ pub enum MonitorType { #[serde(rename = "tailscale-ping")] TailscalePing, + + #[cfg(feature = "uptime-kuma-v2")] + #[serde(rename = "snmp")] + SNMP, + + #[cfg(feature = "uptime-kuma-v2")] + #[serde(rename = "rabbitmq")] + RabbitMQ, } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -444,6 +459,114 @@ pub enum HttpAuth { }, } +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub enum MonitorConditionOperator { + #[serde(rename = "equals")] + Equals, + #[serde(rename = "not_equals")] + NotEquals, + #[serde(rename = "contains")] + Contains, + #[serde(rename = "not_contains")] + NotContains, + #[serde(rename = "starts_with")] + StartsWith, + #[serde(rename = "not_starts_with")] + NotStartsWith, + #[serde(rename = "ends_with")] + EndsWith, + #[serde(rename = "not_ends_with")] + NotEndsWith, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub enum MonitorConditionConjunction { + #[serde(rename = "and")] + And, + #[serde(rename = "or")] + Or, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(tag = "type")] +pub enum MonitorCondition { + #[serde(rename = "expression")] + Expression { + #[serde(rename = "variable")] + variable: Option, + #[serde(rename = "operator")] + operator: Option, + #[serde(rename = "value")] + value: Option, + #[serde(rename = "andOr")] + conjunction: Option, + }, + + #[serde(rename = "group")] + Group { + #[serde(rename = "children")] + children: Option>, + }, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub enum SNMPVersion { + #[serde(rename = "1")] + SNMPv1, + + #[serde(rename = "2c")] + SNMPv2c, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Default)] +pub enum HttpBodyEncoding { + #[default] + #[serde(rename = "json")] + Json, + + #[cfg(feature = "uptime-kuma-v2")] + #[serde(rename = "form")] + Form, + + #[serde(rename = "xml")] + Xml, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Default)] +pub enum MqttCheckType { + #[default] + #[serde(rename = "keyword")] + Keyword, + + #[serde(rename = "json-query")] + JsonQuery, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Default)] +pub enum JsonPathOperator { + #[serde(rename = ">")] + Greater, + + #[serde(rename = ">=")] + GreaterEqual, + + #[serde(rename = "<")] + Less, + + #[serde(rename = "<=")] + LessEqual, + + #[serde(rename = "!=")] + NotEqual, + + #[default] + #[serde(rename = "==")] + Equal, + + #[serde(rename = "contains")] + Contains, +} + monitor_type! { MonitorGroup Group { @@ -479,6 +602,21 @@ monitor_type! { #[serde(rename = "databaseConnectionString")] #[serde(alias = "database_connection_string")] pub database_connection_string: Option, + + #[cfg(feature = "uptime-kuma-v2")] + #[serde(rename = "databaseQuery")] + #[serde(alias = "command")] + pub command: Option, + + #[cfg(feature = "uptime-kuma-v2")] + #[serde(rename = "jsonPath")] + #[serde(alias = "json_path")] + pub json_path: Option, + + #[cfg(feature = "uptime-kuma-v2")] + #[serde(rename = "expectedValue")] + #[serde(alias = "expected_value")] + pub expected_value: Option, } } @@ -503,6 +641,12 @@ monitor_type! { #[serde(rename = "databaseConnectionString")] #[serde(alias = "database_connection_string")] pub database_connection_string: Option, + + #[cfg(feature = "uptime-kuma-v2")] + #[serde(rename = "ignoreTls")] + #[serde(alias = "ignore_tls")] + #[serde_as(as = "Option")] + pub ignore_tls: Option, } } @@ -603,6 +747,12 @@ monitor_type! { #[serde(rename = "grpcMetadata")] #[serde(alias = "grpc_metadata")] pub grpc_metadata: Option, + + #[cfg(feature = "uptime-kuma-v2")] + #[serde(rename = "grpcMetadata")] + #[serde(alias = "grpc_metadata")] + #[serde_as(as = "Option")] + pub cache_bust: Option, } } @@ -647,7 +797,7 @@ monitor_type! { #[serde(rename = "httpBodyEncoding")] #[serde(alias = "http_body_encoding")] - pub http_body_encoding: Option, + pub http_body_encoding: Option, #[serde(rename = "body")] pub body: Option, @@ -657,6 +807,12 @@ monitor_type! { #[serde(flatten)] pub auth: Option, + + #[cfg(feature = "uptime-kuma-v2")] + #[serde(rename = "cacheBust")] + #[serde(alias = "cache_bust")] + #[serde_as(as = "Option")] + pub cache_bust: Option, } } @@ -666,6 +822,11 @@ monitor_type! { #[serde(alias = "json_path")] pub json_path: Option, + #[cfg(feature = "uptime-kuma-v2")] + #[serde(rename = "jsonPathOperator")] + #[serde(alias = "json_path_operator")] + pub json_path_operator: Option, + #[serde(rename = "expectedValue")] #[serde(alias = "expected_value")] pub expected_value: Option, @@ -708,7 +869,7 @@ monitor_type! { #[serde(rename = "httpBodyEncoding")] #[serde(alias = "http_body_encoding")] - pub http_body_encoding: Option, + pub http_body_encoding: Option, #[serde(rename = "body")] pub body: Option, @@ -718,6 +879,12 @@ monitor_type! { #[serde(flatten)] pub auth: Option, + + #[cfg(feature = "uptime-kuma-v2")] + #[serde(rename = "grpcMetadata")] + #[serde(alias = "grpc_metadata")] + #[serde_as(as = "Option")] + pub cache_bust: Option, } } @@ -800,7 +967,7 @@ monitor_type! { #[serde(rename = "httpBodyEncoding")] #[serde(alias = "http_body_encoding")] - pub http_body_encoding: Option, + pub http_body_encoding: Option, #[serde(rename = "body")] pub body: Option, @@ -836,11 +1003,25 @@ monitor_type! { #[serde(rename = "mqttCheckType")] #[serde(alias = "mqtt_check_type")] - pub mqtt_check_type: Option, + pub mqtt_check_type: Option, #[serde(rename = "mqttSuccessMessage")] #[serde(alias = "mqtt_success_message")] pub mqtt_success_message: Option, + + #[cfg(feature = "uptime-kuma-v2")] + #[serde(rename = "jsonPath")] + #[serde(alias = "json_path")] + pub json_path: Option, + + #[cfg(feature = "uptime-kuma-v2")] + #[serde(rename = "jsonPathOperator")] + #[serde(alias = "json_path_operator")] + pub json_path_operator: Option, + + #[serde(rename = "expectedValue")] + #[serde(alias = "expected_value")] + pub expected_value: Option, } } @@ -940,6 +1121,61 @@ monitor_type! { } } +#[cfg(feature = "uptime-kuma-v2")] +monitor_type! { + MonitorSNMP SNMP { + #[serde(rename = "hostname")] + pub hostname: Option, + + #[serde(rename = "port")] + #[serde_as(as = "Option")] + pub port: Option, + + #[serde(rename = "radiusPassword")] + #[serde(alias = "radius_password")] + pub password: Option, + + #[serde(rename = "snmpOid")] + #[serde(alias = "oid")] + pub oid: Option, + + #[serde(rename = "snmp_version")] + #[serde(alias = "version")] + pub version: Option, + + #[serde(rename = "jsonPath")] + #[serde(alias = "json_path")] + pub json_path: Option, + + #[cfg(feature = "uptime-kuma-v2")] + #[serde(rename = "jsonPathOperator")] + #[serde(alias = "json_path_operator")] + pub json_path_operator: Option, + + #[serde(rename = "expectedValue")] + #[serde(alias = "expected_value")] + pub expected_value: Option, + } +} + +#[cfg(feature = "uptime-kuma-v2")] +monitor_type! { + MonitorRabbitMQ RabbitMQ { + #[serde(rename = "rabbitmqNodes")] + #[serde_as(as = "DeserializeVecLenient")] + #[serde_inline_default(vec![])] + pub nodes: Vec, + + #[serde(rename = "rabbitmqUsername")] + #[serde(alias = "username")] + pub username: Option, + + #[serde(rename = "rabbitmqUsername")] + #[serde(alias = "password")] + pub password: Option, + } +} + #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(tag = "type")] pub enum Monitor { @@ -1074,6 +1310,18 @@ pub enum Monitor { #[serde(flatten)] value: MonitorTailscalePing, }, + #[cfg(feature = "uptime-kuma-v2")] + #[serde(rename = "snmp")] + SNMP { + #[serde(flatten)] + value: MonitorSNMP, + }, + #[cfg(feature = "uptime-kuma-v2")] + #[serde(rename = "rabbitmq")] + RabbitMQ { + #[serde(flatten)] + value: MonitorRabbitMQ, + }, } impl Monitor { @@ -1101,6 +1349,10 @@ impl Monitor { Monitor::Radius { .. } => MonitorType::Radius, Monitor::Redis { .. } => MonitorType::Redis, Monitor::TailscalePing { .. } => MonitorType::TailscalePing, + #[cfg(feature = "uptime-kuma-v2")] + Monitor::SNMP { .. } => MonitorType::SNMP, + #[cfg(feature = "uptime-kuma-v2")] + Monitor::RabbitMQ { .. } => MonitorType::RabbitMQ, } } @@ -1128,6 +1380,10 @@ impl Monitor { Monitor::Radius { value } => Box::new(value), Monitor::Redis { value } => Box::new(value), Monitor::TailscalePing { value } => Box::new(value), + #[cfg(feature = "uptime-kuma-v2")] + Monitor::SNMP { value } => Box::new(value), + #[cfg(feature = "uptime-kuma-v2")] + Monitor::RabbitMQ { value } => Box::new(value), } } @@ -1155,6 +1411,10 @@ impl Monitor { Monitor::Radius { value } => Box::new(value), Monitor::Redis { value } => Box::new(value), Monitor::TailscalePing { value } => Box::new(value), + #[cfg(feature = "uptime-kuma-v2")] + Monitor::SNMP { value } => Box::new(value), + #[cfg(feature = "uptime-kuma-v2")] + Monitor::RabbitMQ { value } => Box::new(value), } }