diff --git a/.gitignore b/.gitignore index ac0a1e9..7b7cd81 100644 --- a/.gitignore +++ b/.gitignore @@ -42,8 +42,8 @@ go.work.sum /frp_client /configs agent.md -super-frpc -super-frpc.exe +Watchdog_Linux-systemd +Watchdog_Linux-systemd.exe *.db database.db logs.html \ No newline at end of file diff --git a/command/commandParse.go b/command/commandParse.go index c74a6ac..211457b 100644 --- a/command/commandParse.go +++ b/command/commandParse.go @@ -1,7 +1,10 @@ package command import ( + "Watchdog_Linux-systemd/monitor" + "fmt" "strings" + "os" ) func getTextMiddle(text, left, right string) string { @@ -32,10 +35,31 @@ func getCommand(content string) string { return getTextMiddle(content, "[", "]") } -func parseCommand(content, cmdType string) string { +func getContent(content, cmdType string) string { return getTextMiddle(content, "<" + cmdType + ">", "") } func ExecuteCommand(input string) error { - return nil + cmdType := getCommand(input) + switch cmdType { + case "monitor.add": + serviceName := getContent(input, "serviceName") + if len(serviceName) != 0 { + err := monitor.AddServiceMonitor(serviceName) + if err != nil { + return fmt.Errorf("failed to add service monitor: %v", err) + } + } + case "monitor.remove": + serviceName := getContent(input, "serviceName") + if len(serviceName) != 0 { + err := monitor.RemoveServiceMonitor(serviceName) + if err != nil { + return fmt.Errorf("failed to remove service monitor: %v", err) + } + } + case "watchdog.shutdown": + os.Exit(0) + } + return fmt.Errorf("unknown command") } \ No newline at end of file