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.
30 lines
687 B
Go
30 lines
687 B
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func (s *Server) 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", s.isAdminMiddleware, func(c *fiber.Ctx) error {
|
|
if qScript := c.Query("script"); qScript != "" {
|
|
output, err := s.Monitor.GetOutput(qScript)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return c.JSON(output)
|
|
}
|
|
|
|
return fmt.Errorf("no script, device or entity provided")
|
|
})
|
|
|
|
api.Get("/invalidate-cache", s.isAdminMiddleware, func(c *fiber.Ctx) error {
|
|
s.Monitor.InvalidateCache()
|
|
return c.JSON("ok")
|
|
})
|
|
}
|