-
Notifications
You must be signed in to change notification settings - Fork 1
/
windows.go
61 lines (52 loc) · 1.82 KB
/
windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//go:build windows
// +build windows
package main
import (
"log"
"os/exec"
"strings"
"time"
)
func getIconPath() string {
return "assets/wazuh-logo.ico" // Path to the PNG icon for Linux
}
// checkServiceStatus checks the status of Wazuh agent and its connection on Windows
func checkServiceStatus() (string, string) {
cmd := exec.Command("cmd", "/C", `C:\Program Files (x86)\ossec\bin\wazuh-control status`)
output, err := cmd.Output()
if err != nil {
return "Inactive", "Disconnected"
}
status := "Inactive"
if strings.Contains(string(output), "wazuh-agentd is running") {
status = "Active"
}
// Check connection status
connCmd := exec.Command("cmd", "/C", `powershell -Command "Select-String -Path 'C:\Program Files (x86)\ossec-agent\wazuh-agent.state' -Pattern '^status'"`)
connOutput, connErr := connCmd.Output()
connection := "Disconnected"
if connErr == nil && strings.Contains(string(connOutput), "status='connected'") {
connection = "Connected"
}
return status, connection
}
// pauseAgent pauses the Wazuh agent on Windows
func pauseAgent() {
log.Printf("[%s] Pausing Wazuh agent...\n", time.Now().Format(time.RFC3339))
err := exec.Command("net", "stop", "wazuh-agent").Run()
if err != nil {
log.Printf("[%s] Failed to pause Wazuh agent: %v\n", time.Now().Format(time.RFC3339), err)
} else {
log.Printf("[%s] Wazuh agent paused successfully\n", time.Now().Format(time.RFC3339))
}
}
// restartAgent restarts the Wazuh agent on Windows
func restartAgent() {
log.Printf("[%s] Restarting Wazuh agent...\n", time.Now().Format(time.RFC3339))
err := exec.Command("net", "start", "wazuh-agent").Run()
if err != nil {
log.Printf("[%s] Failed to restart Wazuh agent: %v\n", time.Now().Format(time.RFC3339), err)
} else {
log.Printf("[%s] Wazuh agent restarted successfully\n", time.Now().Format(time.RFC3339))
}
}