diff --git a/agent/collector/security.go b/agent/collector/security.go index 06f585b..a80daca 100644 --- a/agent/collector/security.go +++ b/agent/collector/security.go @@ -3,6 +3,7 @@ package collector import ( "bufio" "fmt" + "log" "os" "os/exec" "regexp" @@ -72,7 +73,12 @@ func CollectSecurity() *SecurityData { seen := make(map[string]bool) for _, path := range logFiles { - events := parseAuditLog(path) + events, err := parseAuditLog(path) + if err != nil { + log.Printf("Security: %s: %v", path, err) + continue + } + log.Printf("Security: %s: %d events", path, len(events)) for _, e := range events { key := e.Timestamp + e.User + e.Source + e.Port + e.Status if !seen[key] { @@ -118,10 +124,10 @@ func CollectSecurity() *SecurityData { return data } -func parseAuditLog(path string) []LoginEvent { +func parseAuditLog(path string) ([]LoginEvent, error) { f, err := os.Open(path) if err != nil { - return nil + return nil, err } defer f.Close() @@ -166,7 +172,7 @@ func parseAuditLog(path string) []LoginEvent { } } - return events + return events, nil } func extractTimestamp(line string) string {