feat: handle logging from the agent
This commit is contained in:
parent
bcd87453bd
commit
8fc657f86a
10 changed files with 63 additions and 235 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue