MCPcopy
hub / github.com/nextdns/nextdns / queryWindowsEvents

Function queryWindowsEvents

host/log_windows.go:140–164  ·  view source on GitHub ↗
(name string, count int)

Source from the content-addressed store, hash-verified

138}
139
140func queryWindowsEvents(name string, count int) ([]windowsEvent, error) {
141 if _, err := exec.LookPath("wevtutil"); err != nil {
142 return nil, fmt.Errorf("Windows Event Log utility not found")
143 }
144 if count <= 0 {
145 count = 1
146 }
147 q := fmt.Sprintf(`*[System[Provider[@Name="%s"]]]`, strings.ReplaceAll(name, `"`, `\"`))
148 args := []string{
149 "qe", "Application",
150 "/q:" + q,
151 "/f:text",
152 "/rd:true",
153 fmt.Sprintf("/c:%d", count),
154 }
155 out, err := exec.Command("wevtutil", args...).CombinedOutput()
156 if err != nil {
157 msg := strings.TrimSpace(string(out))
158 if msg != "" {
159 return nil, fmt.Errorf("query windows logs: %s", msg)
160 }
161 return nil, fmt.Errorf("query windows logs: %w", err)
162 }
163 return parseWindowsEventText(string(out)), nil
164}
165
166func parseWindowsEventText(out string) []windowsEvent {
167 var blocks []string

Callers 2

ReadLogFunction · 0.85
FollowLogFunction · 0.85

Calls 3

parseWindowsEventTextFunction · 0.85
CommandMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…