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.
26 lines
536 B
Go
26 lines
536 B
Go
package routes
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"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 != "" {
|
|
|
|
output, err := r.Monitor.GetLastOutput(qScript)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return c.JSON(output)
|
|
}
|
|
|
|
return fmt.Errorf("no script, device or entity provided")
|
|
})
|
|
}
|