summaryrefslogtreecommitdiffstats
path: root/src/receive.go
blob: c0dea00927f79a0249e1074110f31be49a69cdd8 (plain) (blame)
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
package main

import (
	"fmt"

	"github.com/elastic/go-libaudit/v2"
	"github.com/elastic/go-libaudit/v2/auparse"
	"github.com/mohae/deepcopy"
)

func receive(r *libaudit.AuditClient) error {
	defer wg.Done()
	defer close(rawChan)
	for {
		rawEvent, err := r.Receive(false)
		if err != nil {
			return fmt.Errorf("receive failed: %w", err)
		}

		// Messages from 1300-2999 are valid audit messages.
		if rawEvent.Type < auparse.AUDIT_USER_AUTH ||
			rawEvent.Type > auparse.AUDIT_LAST_USER_MSG2 {
			continue
		}

		rawEventMessage := deepcopy.Copy(*rawEvent)
		rawChan <- rawEventMessage
	}
}