You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
579 B
Go

package routes
import (
"fmt"
"log"
"github.com/gofiber/fiber/v2"
)
func (r *Router) ApiMonitor(api fiber.Router) {
// Respond to requests like
// - "/api/monitor/status?script=SCRIPT_NAME" where SCRIPT_NAME is the name of a file inside "./scripts"
api.Get("/status", func(c *fiber.Ctx) error {
if qScript := c.Query("script"); qScript != "" {
log.Printf("Script %q", qScript)
output, err := r.Monitor.GetLastOutput(qScript)
if err != nil {
return err
}
return c.JSON(output)
}
return fmt.Errorf("no script, device or entity provided")
})
}