Add frigate connectivity check endpoint

This commit is contained in:
eduard256
2026-03-25 18:15:31 +00:00
parent 0bf2a83e9d
commit b060a5372e
2 changed files with 49 additions and 0 deletions
+47
View File
@@ -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),
})
}
+2
View File
@@ -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 {