60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"bee/audit/internal/platform"
|
|
)
|
|
|
|
func (a *App) ListBeeServices() ([]string, error) {
|
|
return a.services.ListBeeServices()
|
|
}
|
|
|
|
func (a *App) ServiceState(name string) string {
|
|
return a.services.ServiceState(name)
|
|
}
|
|
|
|
func (a *App) ServiceStatus(name string) (string, error) {
|
|
return a.services.ServiceStatus(name)
|
|
}
|
|
|
|
func (a *App) ServiceStatusResult(name string) (ActionResult, error) {
|
|
body, err := a.services.ServiceStatus(name)
|
|
return ActionResult{Title: "service status: " + name, Body: bodyOr(body, "No status output.")}, err
|
|
}
|
|
|
|
func (a *App) ServiceActionResult(name string, action platform.ServiceAction) (ActionResult, error) {
|
|
body, err := a.services.ServiceDo(name, action)
|
|
return ActionResult{Title: "service " + string(action) + ": " + name, Body: bodyOr(body, "Action completed.")}, err
|
|
}
|
|
|
|
func (a *App) CheckTools(names []string) []platform.ToolStatus {
|
|
return a.tools.CheckTools(names)
|
|
}
|
|
|
|
func (a *App) ToolCheckResult(names []string) ActionResult {
|
|
if len(names) == 0 {
|
|
return ActionResult{Title: "Required tools", Body: "No tools checked."}
|
|
}
|
|
var body strings.Builder
|
|
for _, tool := range a.tools.CheckTools(names) {
|
|
status := "MISSING"
|
|
if tool.OK {
|
|
status = "OK (" + tool.Path + ")"
|
|
}
|
|
fmt.Fprintf(&body, "- %s: %s\n", tool.Name, status)
|
|
}
|
|
return ActionResult{Title: "Required tools", Body: strings.TrimSpace(body.String())}
|
|
}
|
|
|
|
func (a *App) AuditLogTailResult() ActionResult {
|
|
logTail := strings.TrimSpace(a.tools.TailFile(DefaultAuditLogPath, 40))
|
|
jsonTail := strings.TrimSpace(a.tools.TailFile(DefaultAuditJSONPath, 20))
|
|
body := strings.TrimSpace(logTail + "\n\n" + jsonTail)
|
|
if body == "" {
|
|
body = "No audit logs found."
|
|
}
|
|
return ActionResult{Title: "Audit log tail", Body: body}
|
|
}
|