diff --git a/modules/system/exports/freepbx.nix b/modules/system/exports/freepbx.nix index c654701c..1d1a18eb 100644 --- a/modules/system/exports/freepbx.nix +++ b/modules/system/exports/freepbx.nix @@ -8,7 +8,16 @@ in { config.exports.services.freepbx = {config, ...}: { displayName = mkAlmostOptionDefault "FreePBX"; id = mkAlmostOptionDefault "pbx"; - ports = { + ports = let + ucpGtatus = { + client.network = mkAlmostOptionDefault "ip4"; + http = { + websocket.enable = mkAlmostOptionDefault true; + path = mkAlmostOptionDefault "/socket.io/?transport=websocket"; + statusCondition = mkAlmostOptionDefault "[BODY] == pat(*\"sid\":*)"; + }; + }; + in { http = { displayName = mkAlmostOptionDefault null; port = mkAlmostOptionDefault 80; @@ -25,12 +34,13 @@ in { displayName = mkAlmostOptionDefault "UCP"; status = { enable = mkAlmostOptionDefault config.ports.http.status.enable; - gatus.client.network = mkAlmostOptionDefault "ip4"; + gatus = ucpGtatus; }; }; ucp-ssl = { port = mkAlmostOptionDefault 8003; protocol = "https"; + status.gatus = ucpGtatus; }; asterisk = { port = mkAlmostOptionDefault 8088; diff --git a/modules/system/exports/monitoring.nix b/modules/system/exports/monitoring.nix index 0e3a53ff..5eb6d119 100644 --- a/modules/system/exports/monitoring.nix +++ b/modules/system/exports/monitoring.nix @@ -6,7 +6,7 @@ let lib, ... }: let - inherit (gensokyo-zone.lib) unmerged; + inherit (gensokyo-zone.lib) mapOptionDefaults unmerged; inherit (lib.options) mkOption mkEnableOption; inherit (lib.modules) mkIf mkMerge mkOptionDefault; in { @@ -43,6 +43,13 @@ let statusCondition = mkOption { type = nullOr str; }; + websocket = { + enable = mkEnableOption "ws://"; + status = mkOption { + type = int; + default = 200; + }; + }; }; protocol = mkOption { type = str; @@ -56,8 +63,22 @@ let config = { status.gatus = let cfg = config.status.gatus; + useWebsocket = cfg.http.websocket.enable && cfg.http.websocket.status == 200; + mockWebsocket = cfg.http.websocket.enable && cfg.http.websocket.status != 200; + protocolWs = + if config.ssl || config.protocol == "https" + then "wss" + else "ws"; + protocolHttp = + if config.ssl || config.protocol == "https" + then "https" + else "http"; defaultProtocol = - if config.protocol != null + if useWebsocket + then mkOptionDefault protocolWs + else if cfg.http.websocket.enable + then mkOptionDefault protocolHttp + else if config.protocol != null then mkOptionDefault config.protocol else if config.starttls then mkOptionDefault "starttls" @@ -69,7 +90,9 @@ let in { protocol = defaultProtocol; http.statusCondition = mkOptionDefault ( - if cfg.protocol == "http" || cfg.protocol == "https" + if mockWebsocket + then "[STATUS] == ${toString cfg.http.websocket.status}" + else if cfg.protocol == "http" || cfg.protocol == "https" then "[STATUS] == 200" else null ); @@ -91,6 +114,14 @@ let "[DNS_RCODE] == NOERROR" ]; }) + (mkIf mockWebsocket { + headers = mapOptionDefaults { + Connection = "Upgrade"; + Upgrade = "websocket"; + Sec-WebSocket-Version = "13"; + Sec-WebSocket-Key = "SGVsbG8sIHdvcmxkIQ=="; + }; + }) ]; }; }; diff --git a/modules/system/exports/vaultwarden.nix b/modules/system/exports/vaultwarden.nix index c5aa8070..85ce01af 100644 --- a/modules/system/exports/vaultwarden.nix +++ b/modules/system/exports/vaultwarden.nix @@ -38,7 +38,10 @@ in { displayName = mkAlmostOptionDefault "WebSocket"; status = { enable = mkAlmostOptionDefault true; - gatus.protocol = "ws"; + gatus.http.websocket = { + enable = mkAlmostOptionDefault true; + status = mkAlmostOptionDefault 401; + }; }; }; }; diff --git a/nixos/monitoring/gatus.nix b/nixos/monitoring/gatus.nix index 99301077..11ed0495 100644 --- a/nixos/monitoring/gatus.nix +++ b/nixos/monitoring/gatus.nix @@ -6,7 +6,7 @@ ... }: let inherit (gensokyo-zone) systems; - inherit (gensokyo-zone.lib) mkAddress6 mkAlmostOptionDefault unmerged; + inherit (gensokyo-zone.lib) mkAddress6 mkAlmostOptionDefault mapOptionDefaults unmerged; inherit (lib.modules) mkIf mkMerge mkDefault mkOptionDefault; inherit (lib.attrsets) attrValues nameValuePair listToAttrs; inherit (lib.lists) filter length optional concatMap;