feat(command): implement command execution for service monitoring
Add functionality to parse and execute commands for adding/removing service monitors and shutting down the watchdog. The ExecuteCommand function now handles "monitor.add", "monitor.remove" and "watchdog.shutdown" commands by interacting with the monitor package and system operations.
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -42,8 +42,8 @@ go.work.sum
|
|||||||
/frp_client
|
/frp_client
|
||||||
/configs
|
/configs
|
||||||
agent.md
|
agent.md
|
||||||
super-frpc
|
Watchdog_Linux-systemd
|
||||||
super-frpc.exe
|
Watchdog_Linux-systemd.exe
|
||||||
*.db
|
*.db
|
||||||
database.db
|
database.db
|
||||||
logs.html
|
logs.html
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"Watchdog_Linux-systemd/monitor"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getTextMiddle(text, left, right string) string {
|
func getTextMiddle(text, left, right string) string {
|
||||||
@@ -32,10 +35,31 @@ func getCommand(content string) string {
|
|||||||
return getTextMiddle(content, "[", "]")
|
return getTextMiddle(content, "[", "]")
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCommand(content, cmdType string) string {
|
func getContent(content, cmdType string) string {
|
||||||
return getTextMiddle(content, "<" + cmdType + ">", "</" + cmdType + ">")
|
return getTextMiddle(content, "<" + cmdType + ">", "</" + cmdType + ">")
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExecuteCommand(input string) error {
|
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")
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user