mirror of
https://github.com/tale/headplane.git
synced 2026-08-06 04:07:41 +00:00
feat: handle logging from the agent
This commit is contained in:
+33
-10
@@ -1,11 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/tale/headplane/internal/config"
|
||||
"github.com/tale/headplane/internal/hpagent"
|
||||
"github.com/tale/headplane/internal/tsnet"
|
||||
"github.com/tale/headplane/internal/util"
|
||||
)
|
||||
@@ -24,15 +26,36 @@ func main() {
|
||||
|
||||
log.SetDebug(cfg.Debug)
|
||||
agent := tsnet.NewAgent(cfg)
|
||||
|
||||
agent.Connect()
|
||||
defer agent.Shutdown()
|
||||
|
||||
log.Msg(&Register{
|
||||
Type: "register",
|
||||
ID: agent.ID,
|
||||
})
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Bytes()
|
||||
directive := strings.TrimSpace(string(line))
|
||||
log.Debug("Received directive: %s", directive)
|
||||
|
||||
fmt.Println("READY")
|
||||
hpagent.FollowMaster(agent)
|
||||
switch directive {
|
||||
case "START":
|
||||
agent.Connect()
|
||||
fmt.Printf("READY %s\n", agent.ID)
|
||||
|
||||
case "SHUTDOWN":
|
||||
agent.Shutdown()
|
||||
os.Exit(0)
|
||||
|
||||
case "PING":
|
||||
fmt.Printf("PONG %s\n", agent.ID)
|
||||
|
||||
case "REFRESH":
|
||||
err := agent.DispatchHostInfo(context.Background())
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR %s\n", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
fmt.Printf("ERROR %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user