From b060a5372ee5a0421f11b0858fc992d70e3155f3 Mon Sep 17 00:00:00 2001 From: eduard256 Date: Wed, 25 Mar 2026 18:15:31 +0000 Subject: [PATCH] Add frigate connectivity check endpoint --- internal/frigate/frigate.go | 47 +++++++++++++++++++++++++++++++++++++ main.go | 2 ++ 2 files changed, 49 insertions(+) create mode 100644 internal/frigate/frigate.go diff --git a/internal/frigate/frigate.go b/internal/frigate/frigate.go new file mode 100644 index 0000000..7fbe507 --- /dev/null +++ b/internal/frigate/frigate.go @@ -0,0 +1,47 @@ +package frigate + +import ( + "fmt" + "net/http" + "time" + + "github.com/eduard256/strix/internal/api" + "github.com/eduard256/strix/internal/app" + "github.com/rs/zerolog" +) + +var log zerolog.Logger +var frigateURL string + +func Init() { + log = app.GetLogger("frigate") + + frigateURL = app.Env("STRIX_FRIGATE_URL", "http://localhost:5000") + + log.Info().Str("url", frigateURL).Msg("[frigate] target") + + api.HandleFunc("api/frigate/check", apiCheck) +} + +func apiCheck(w http.ResponseWriter, r *http.Request) { + client := &http.Client{Timeout: 3 * time.Second} + + resp, err := client.Get(frigateURL + "/api/config") + if err != nil { + api.ResponseJSON(w, map[string]any{ + "connected": false, + "url": frigateURL, + "error": err.Error(), + }) + return + } + resp.Body.Close() + + api.ResponseJSON(w, map[string]any{ + "connected": true, + "url": frigateURL, + "status_code": resp.StatusCode, + "version": resp.Header.Get("X-Frigate-Version"), + "message": fmt.Sprintf("Frigate API responded with %d", resp.StatusCode), + }) +} diff --git a/main.go b/main.go index 499e0de..eb097da 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "github.com/eduard256/strix/internal/api" "github.com/eduard256/strix/internal/app" + "github.com/eduard256/strix/internal/frigate" "github.com/eduard256/strix/internal/generate" "github.com/eduard256/strix/internal/probe" "github.com/eduard256/strix/internal/search" @@ -24,6 +25,7 @@ func main() { {"test", test.Init}, {"probe", probe.Init}, {"generate", generate.Init}, + {"frigate", frigate.Init}, } for _, m := range modules {