refactor(socket): decouple command handling and add message sending
- Move command handler to variable for better flexibility - Add SendMsg function for sending messages through socket - Fix missing return statements in command execution - Improve error handling in monitor exception reporting
This commit is contained in:
@@ -2,6 +2,7 @@ package monitor
|
||||
|
||||
import (
|
||||
"Watchdog_Linux-systemd/postLog"
|
||||
"Watchdog_Linux-systemd/socket"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
@@ -123,7 +124,11 @@ func checkServiceLogs(serviceName string) (bool, error) {
|
||||
|
||||
func throwException(serviceName, errorContent string) error {
|
||||
postLog.Error(fmt.Sprintf("[Monitor] Service: %s - Exception: %s", serviceName, errorContent))
|
||||
return fmt.Errorf("service %s exception: %s", serviceName, errorContent)
|
||||
err := socket.SendMsg(fmt.Sprintf("service %s exception: %s", serviceName, errorContent))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to send exception message: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetActiveMonitors() []string {
|
||||
|
||||
Reference in New Issue
Block a user