Skip to content

Commit

Permalink
go fmt run
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrownus committed Jun 8, 2016
1 parent dc99cdc commit 3cdf789
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 143 deletions.
16 changes: 8 additions & 8 deletions audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
package main

import (
"os/exec"
"strings"
"flag"
"github.com/pkg/profile"
"github.com/spf13/viper"
"log"
"log/syslog"
"flag"
"os"
"log"
"os/exec"
"strings"
)

var l = log.New(os.Stdout, "", 0)
Expand All @@ -23,13 +23,13 @@ func loadConfig(config *viper.Viper) {
config.SetDefault("message_tracking.log_out_of_order", false)
config.SetDefault("message_tracking.max_out_of_order", 500)
config.SetDefault("output.syslog.enabled", false)
config.SetDefault("output.syslog.priority", int(syslog.LOG_LOCAL0 | syslog.LOG_WARNING))
config.SetDefault("output.syslog.priority", int(syslog.LOG_LOCAL0|syslog.LOG_WARNING))
config.SetDefault("output.syslog.tag", "go-audit")
config.SetDefault("output.syslog.attempts", "3")
config.SetDefault("log.flags", 0)

err := config.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
if err != nil { // Handle errors reading the config file
el.Printf("Config file has an error: %s\n", err)
os.Exit(1)
}
Expand All @@ -54,10 +54,10 @@ func setRules(config *viper.Viper) {

err := exec.Command("auditctl", strings.Fields(v)...).Run()
if err != nil {
el.Fatalf("Failed to add rule #%d. Error: %s \n", i + 1, err)
el.Fatalf("Failed to add rule #%d. Error: %s \n", i+1, err)
}

l.Printf("Added audit rule #%d\n", i + 1)
l.Printf("Added audit rule #%d\n", i+1)
}
} else {
el.Fatalln("No audit rules found. exiting")
Expand Down
27 changes: 13 additions & 14 deletions audit_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main

import (
"testing"
"syscall"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"syscall"
"testing"
)

func Test_loadConfig(t *testing.T) {
Expand Down Expand Up @@ -68,34 +68,33 @@ func Benchmark_MultiPacketMessage(b *testing.B) {
data := make([][]byte, 6)

//&{1300,,arch=c000003e,syscall=59,success=yes,exit=0,a0=cc4e68,a1=d10bc8,a2=c69808,a3=7fff2a700900,items=2,ppid=11552,pid=11623,auid=1000,uid=1000,gid=1000,euid=1000,suid=1000,fsuid=1000,egid=1000,sgid=1000,fsgid=1000,tty=pts0,ses=35,comm="ls",exe="/bin/ls",key=(null),1222763,1459376866.885}
data[0] = []byte{34,1,0,0,20,5,0,0,0,0,0,0,0,0,0,0,97,117,100,105,116,40,49,52,53,57,51,55,54,56,54,54,46,56,56,53,58,49,50,50,50,55,54,51,41,58,32,97,114,99,104,61,99,48,48,48,48,48,51,101,32,115,121,115,99,97,108,108,61,53,57,32,115,117,99,99,101,115,115,61,121,101,115,32,101,120,105,116,61,48,32,97,48,61,99,99,52,101,54,56,32,97,49,61,100,49,48,98,99,56,32,97,50,61,99,54,57,56,48,56,32,97,51,61,55,102,102,102,50,97,55,48,48,57,48,48,32,105,116,101,109,115,61,50,32,112,112,105,100,61,49,49,53,53,50,32,112,105,100,61,49,49,54,50,51,32,97,117,105,100,61,49,48,48,48,32,117,105,100,61,49,48,48,48,32,103,105,100,61,49,48,48,48,32,101,117,105,100,61,49,48,48,48,32,115,117,105,100,61,49,48,48,48,32,102,115,117,105,100,61,49,48,48,48,32,101,103,105,100,61,49,48,48,48,32,115,103,105,100,61,49,48,48,48,32,102,115,103,105,100,61,49,48,48,48,32,116,116,121,61,112,116,115,48,32,115,101,115,61,51,53,32,99,111,109,109,61,34,108,115,34,32,101,120,101,61,34,47,98,105,110,47,108,115,34,32,107,101,121,61,40,110,117,108,108,41}
data[0] = []byte{34, 1, 0, 0, 20, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97, 117, 100, 105, 116, 40, 49, 52, 53, 57, 51, 55, 54, 56, 54, 54, 46, 56, 56, 53, 58, 49, 50, 50, 50, 55, 54, 51, 41, 58, 32, 97, 114, 99, 104, 61, 99, 48, 48, 48, 48, 48, 51, 101, 32, 115, 121, 115, 99, 97, 108, 108, 61, 53, 57, 32, 115, 117, 99, 99, 101, 115, 115, 61, 121, 101, 115, 32, 101, 120, 105, 116, 61, 48, 32, 97, 48, 61, 99, 99, 52, 101, 54, 56, 32, 97, 49, 61, 100, 49, 48, 98, 99, 56, 32, 97, 50, 61, 99, 54, 57, 56, 48, 56, 32, 97, 51, 61, 55, 102, 102, 102, 50, 97, 55, 48, 48, 57, 48, 48, 32, 105, 116, 101, 109, 115, 61, 50, 32, 112, 112, 105, 100, 61, 49, 49, 53, 53, 50, 32, 112, 105, 100, 61, 49, 49, 54, 50, 51, 32, 97, 117, 105, 100, 61, 49, 48, 48, 48, 32, 117, 105, 100, 61, 49, 48, 48, 48, 32, 103, 105, 100, 61, 49, 48, 48, 48, 32, 101, 117, 105, 100, 61, 49, 48, 48, 48, 32, 115, 117, 105, 100, 61, 49, 48, 48, 48, 32, 102, 115, 117, 105, 100, 61, 49, 48, 48, 48, 32, 101, 103, 105, 100, 61, 49, 48, 48, 48, 32, 115, 103, 105, 100, 61, 49, 48, 48, 48, 32, 102, 115, 103, 105, 100, 61, 49, 48, 48, 48, 32, 116, 116, 121, 61, 112, 116, 115, 48, 32, 115, 101, 115, 61, 51, 53, 32, 99, 111, 109, 109, 61, 34, 108, 115, 34, 32, 101, 120, 101, 61, 34, 47, 98, 105, 110, 47, 108, 115, 34, 32, 107, 101, 121, 61, 40, 110, 117, 108, 108, 41}

//&{1309,,argc=3,a0="ls",a1="--color=auto",a2="-alF",1222763,1459376866.885}
data[1] = []byte{73,0,0,0,29,5,0,0,0,0,0,0,0,0,0,0,97,117,100,105,116,40,49,52,53,57,51,55,54,56,54,54,46,56,56,53,58,49,50,50,50,55,54,51,41,58,32,97,114,103,99,61,51,32,97,48,61,34,108,115,34,32,97,49,61,34,45,45,99,111,108,111,114,61,97,117,116,111,34,32,97,50,61,34,45,97,108,70,34}
data[1] = []byte{73, 0, 0, 0, 29, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97, 117, 100, 105, 116, 40, 49, 52, 53, 57, 51, 55, 54, 56, 54, 54, 46, 56, 56, 53, 58, 49, 50, 50, 50, 55, 54, 51, 41, 58, 32, 97, 114, 103, 99, 61, 51, 32, 97, 48, 61, 34, 108, 115, 34, 32, 97, 49, 61, 34, 45, 45, 99, 111, 108, 111, 114, 61, 97, 117, 116, 111, 34, 32, 97, 50, 61, 34, 45, 97, 108, 70, 34}

//&{1307,,,cwd="/home/ubuntu/src/slack-github.com/rhuber/go-audit-new",1222763,1459376866.885}
data[2] = []byte{91,0,0,0,27,5,0,0,0,0,0,0,0,0,0,0,97,117,100,105,116,40,49,52,53,57,51,55,54,56,54,54,46,56,56,53,58,49,50,50,50,55,54,51,41,58,32,32,99,119,100,61,34,47,104,111,109,101,47,117,98,117,110,116,117,47,115,114,99,47,115,108,97,99,107,45,103,105,116,104,117,98,46,99,111,109,47,114,104,117,98,101,114,47,103,111,45,97,117,100,105,116,45,110,101,119,34}
data[2] = []byte{91, 0, 0, 0, 27, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97, 117, 100, 105, 116, 40, 49, 52, 53, 57, 51, 55, 54, 56, 54, 54, 46, 56, 56, 53, 58, 49, 50, 50, 50, 55, 54, 51, 41, 58, 32, 32, 99, 119, 100, 61, 34, 47, 104, 111, 109, 101, 47, 117, 98, 117, 110, 116, 117, 47, 115, 114, 99, 47, 115, 108, 97, 99, 107, 45, 103, 105, 116, 104, 117, 98, 46, 99, 111, 109, 47, 114, 104, 117, 98, 101, 114, 47, 103, 111, 45, 97, 117, 100, 105, 116, 45, 110, 101, 119, 34}

//&{1302,,item=0,name="/bin/ls",inode=262316,dev=ca:01,mode=0100755,ouid=0,ogid=0,rdev=00:00,nametype=NORMAL,1222763,1459376866.885}
data[3] = []byte{129,0,0,0,22,5,0,0,0,0,0,0,0,0,0,0,97,117,100,105,116,40,49,52,53,57,51,55,54,56,54,54,46,56,56,53,58,49,50,50,50,55,54,51,41,58,32,105,116,101,109,61,48,32,110,97,109,101,61,34,47,98,105,110,47,108,115,34,32,105,110,111,100,101,61,50,54,50,51,49,54,32,100,101,118,61,99,97,58,48,49,32,109,111,100,101,61,48,49,48,48,55,53,53,32,111,117,105,100,61,48,32,111,103,105,100,61,48,32,114,100,101,118,61,48,48,58,48,48,32,110,97,109,101,116,121,112,101,61,78,79,82,77,65,76}
data[3] = []byte{129, 0, 0, 0, 22, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97, 117, 100, 105, 116, 40, 49, 52, 53, 57, 51, 55, 54, 56, 54, 54, 46, 56, 56, 53, 58, 49, 50, 50, 50, 55, 54, 51, 41, 58, 32, 105, 116, 101, 109, 61, 48, 32, 110, 97, 109, 101, 61, 34, 47, 98, 105, 110, 47, 108, 115, 34, 32, 105, 110, 111, 100, 101, 61, 50, 54, 50, 51, 49, 54, 32, 100, 101, 118, 61, 99, 97, 58, 48, 49, 32, 109, 111, 100, 101, 61, 48, 49, 48, 48, 55, 53, 53, 32, 111, 117, 105, 100, 61, 48, 32, 111, 103, 105, 100, 61, 48, 32, 114, 100, 101, 118, 61, 48, 48, 58, 48, 48, 32, 110, 97, 109, 101, 116, 121, 112, 101, 61, 78, 79, 82, 77, 65, 76}

//&{1302,,item=1,name="/lib64/ld-linux-x86-64.so.2",inode=396037,dev=ca:01,mode=0100755,ouid=0,ogid=0,rdev=00:00,nametype=NORMAL,1222763,1459376866.885}
data[4] = []byte{149,0,0,0,22,5,0,0,0,0,0,0,0,0,0,0,97,117,100,105,116,40,49,52,53,57,51,55,54,56,54,54,46,56,56,53,58,49,50,50,50,55,54,51,41,58,32,105,116,101,109,61,49,32,110,97,109,101,61,34,47,108,105,98,54,52,47,108,100,45,108,105,110,117,120,45,120,56,54,45,54,52,46,115,111,46,50,34,32,105,110,111,100,101,61,51,57,54,48,51,55,32,100,101,118,61,99,97,58,48,49,32,109,111,100,101,61,48,49,48,48,55,53,53,32,111,117,105,100,61,48,32,111,103,105,100,61,48,32,114,100,101,118,61,48,48,58,48,48,32,110,97,109,101,116,121,112,101,61,78,79,82,77,65,76}
data[4] = []byte{149, 0, 0, 0, 22, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97, 117, 100, 105, 116, 40, 49, 52, 53, 57, 51, 55, 54, 56, 54, 54, 46, 56, 56, 53, 58, 49, 50, 50, 50, 55, 54, 51, 41, 58, 32, 105, 116, 101, 109, 61, 49, 32, 110, 97, 109, 101, 61, 34, 47, 108, 105, 98, 54, 52, 47, 108, 100, 45, 108, 105, 110, 117, 120, 45, 120, 56, 54, 45, 54, 52, 46, 115, 111, 46, 50, 34, 32, 105, 110, 111, 100, 101, 61, 51, 57, 54, 48, 51, 55, 32, 100, 101, 118, 61, 99, 97, 58, 48, 49, 32, 109, 111, 100, 101, 61, 48, 49, 48, 48, 55, 53, 53, 32, 111, 117, 105, 100, 61, 48, 32, 111, 103, 105, 100, 61, 48, 32, 114, 100, 101, 118, 61, 48, 48, 58, 48, 48, 32, 110, 97, 109, 101, 116, 121, 112, 101, 61, 78, 79, 82, 77, 65, 76}

//&{1320,,,1222763,1459376866.885}
data[5] = []byte{31,0,0,0,40,5,0,0,0,0,0,0,0,0,0,0,97,117,100,105,116,40,49,52,53,57,51,55,54,56,54,54,46,56,56,53,58,49,50,50,50,55,54,51,41,58,32}
data[5] = []byte{31, 0, 0, 0, 40, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97, 117, 100, 105, 116, 40, 49, 52, 53, 57, 51, 55, 54, 56, 54, 54, 46, 56, 56, 53, 58, 49, 50, 50, 50, 55, 54, 51, 41, 58, 32}


for i := 0; i < b.N; i++ {
for n := 0; n < len(data); n++ {
nlen := len(data[n])
msg := &syscall.NetlinkMessage{
Header: syscall.NlMsghdr{
Len: Endianness.Uint32(data[n][0:4]),
Type: Endianness.Uint16(data[n][4:6]),
Len: Endianness.Uint32(data[n][0:4]),
Type: Endianness.Uint16(data[n][4:6]),
Flags: Endianness.Uint16(data[n][6:8]),
Seq: Endianness.Uint32(data[n][8:12]),
Pid: Endianness.Uint32(data[n][12:16]),
Seq: Endianness.Uint32(data[n][8:12]),
Pid: Endianness.Uint32(data[n][12:16]),
},
Data: data[n][syscall.SizeofNlMsghdr:nlen],
}
Expand All @@ -104,7 +103,7 @@ func Benchmark_MultiPacketMessage(b *testing.B) {
}
}

type noopWriter struct { t *testing.T }
type noopWriter struct{ t *testing.T }

func (t *noopWriter) Write(a []byte) (int, error) {
return 0, nil
Expand Down
36 changes: 18 additions & 18 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main

import (
"syscall"
"sync/atomic"
"bytes"
"encoding/binary"
"time"
"errors"
"sync/atomic"
"syscall"
"time"
)

var Endianness = binary.LittleEndian
Expand Down Expand Up @@ -34,20 +34,20 @@ type AuditStatusPayload struct {
type NetlinkPacket syscall.NlMsghdr

type NetlinkClient struct {
fd int
address syscall.Sockaddr
seq uint32
buf []byte
fd int
address syscall.Sockaddr
seq uint32
buf []byte
}

func NewNetlinkClient(recvSize int) (*NetlinkClient) {
func NewNetlinkClient(recvSize int) *NetlinkClient {
fd, err := syscall.Socket(syscall.AF_NETLINK, syscall.SOCK_RAW, syscall.NETLINK_AUDIT)
if err != nil {
el.Fatalln("Could not create a socket:", err)
}

n := &NetlinkClient{
fd: fd,
fd: fd,
address: &syscall.SockaddrNetlink{Family: syscall.AF_NETLINK, Groups: 0, Pid: 0},
buf: make([]byte, MAX_AUDIT_MESSAGE_LENGTH),
}
Expand All @@ -58,7 +58,7 @@ func NewNetlinkClient(recvSize int) (*NetlinkClient) {
}

// Set the buffer size if we were asked
if (recvSize > 0) {
if recvSize > 0 {
err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_RCVBUF, recvSize)
}

Expand Down Expand Up @@ -115,11 +115,11 @@ func (n *NetlinkClient) Receive() (*syscall.NetlinkMessage, error) {

msg := &syscall.NetlinkMessage{
Header: syscall.NlMsghdr{
Len: Endianness.Uint32(n.buf[0:4]),
Type: Endianness.Uint16(n.buf[4:6]),
Len: Endianness.Uint32(n.buf[0:4]),
Type: Endianness.Uint16(n.buf[4:6]),
Flags: Endianness.Uint16(n.buf[6:8]),
Seq: Endianness.Uint32(n.buf[8:12]),
Pid: Endianness.Uint32(n.buf[12:16]),
Seq: Endianness.Uint32(n.buf[8:12]),
Pid: Endianness.Uint32(n.buf[12:16]),
},
Data: n.buf[syscall.SizeofNlMsghdr:nlen],
}
Expand All @@ -129,16 +129,16 @@ func (n *NetlinkClient) Receive() (*syscall.NetlinkMessage, error) {

func (n *NetlinkClient) KeepConnection() {
payload := &AuditStatusPayload{
Mask: 4,
Mask: 4,
Enabled: 1,
Pid: uint32(syscall.Getpid()),
Pid: uint32(syscall.Getpid()),
//TODO: Failure: http://lxr.free-electrons.com/source/include/uapi/linux/audit.h#L338
}

packet := &NetlinkPacket{
Type: uint16(1001),
Type: uint16(1001),
Flags: syscall.NLM_F_REQUEST | syscall.NLM_F_ACK,
Pid: uint32(syscall.Getpid()),
Pid: uint32(syscall.Getpid()),
}

err := n.Send(packet, payload)
Expand Down
26 changes: 13 additions & 13 deletions client_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main

import (
"testing"
"syscall"
"os"
"github.com/stretchr/testify/assert"
"bytes"
"encoding/binary"
"github.com/stretchr/testify/assert"
"os"
"syscall"
"testing"
)

func TestNetlinkClient_KeepConnection(t *testing.T) {
Expand All @@ -19,7 +19,7 @@ func TestNetlinkClient_KeepConnection(t *testing.T) {
t.Fatal("Did not expect an error", err)
}

expectedData := []byte{4,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
expectedData := []byte{4, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
binary.LittleEndian.PutUint32(expectedData[12:16], uint32(os.Getpid()))

assert.Equal(t, uint16(1001), msg.Header.Type, "Header.Type mismatch")
Expand All @@ -43,19 +43,19 @@ func TestNetlinkClient_SendReceive(t *testing.T) {

// Build our client
n := makeNelinkClient(t)
defer syscall.Close(n.fd)
defer syscall.Close(n.fd)

// Make sure we can encode/decode properly
payload := &AuditStatusPayload{
Mask: 4,
Mask: 4,
Enabled: 1,
Pid: uint32(1006),
Pid: uint32(1006),
}

packet := &NetlinkPacket{
Type: uint16(1001),
Type: uint16(1001),
Flags: syscall.NLM_F_REQUEST | syscall.NLM_F_ACK,
Pid: uint32(1006),
Pid: uint32(1006),
}

msg = sendReceive(t, n, packet, payload)
Expand All @@ -65,7 +65,7 @@ func TestNetlinkClient_SendReceive(t *testing.T) {
assert.Equal(t, packet.Flags, msg.Header.Flags, "Header.Flags mismatch")
assert.Equal(t, uint32(1), msg.Header.Seq, "Header.Seq mismatch")
assert.Equal(t, uint32(56), msg.Header.Len, "Packet size is wrong - this test is brittle though")
assert.EqualValues(t, msg.Data[:40], []byte{4,0,0,0,1,0,0,0,0,0,0,0,238,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, "data was wrong")
assert.EqualValues(t, msg.Data[:40], []byte{4, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 238, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, "data was wrong")

// Make sure sequences numbers increment on our side
msg = sendReceive(t, n, packet, payload)
Expand Down Expand Up @@ -111,7 +111,7 @@ func makeNelinkClient(t *testing.T) *NetlinkClient {
}

n := &NetlinkClient{
fd: fd,
fd: fd,
address: &syscall.SockaddrUnix{Name: "go-audit.test.sock"},
buf: make([]byte, MAX_AUDIT_MESSAGE_LENGTH),
}
Expand All @@ -125,7 +125,7 @@ func makeNelinkClient(t *testing.T) *NetlinkClient {
}

// Helper to send and then receive a message with the netlink client
func sendReceive(t *testing.T, n *NetlinkClient, packet *NetlinkPacket, payload *AuditStatusPayload) (*syscall.NetlinkMessage) {
func sendReceive(t *testing.T, n *NetlinkClient, packet *NetlinkPacket, payload *AuditStatusPayload) *syscall.NetlinkMessage {
err := n.Send(packet, payload)
if err != nil {
t.Fatal("Failed to send:", err)
Expand Down
46 changes: 23 additions & 23 deletions marshaller.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
package main

import (
"time"
"syscall"
"os"
"syscall"
"time"
)

const (
EVENT_START = 1300 // Start of the audit type ids that we care about
EVENT_END = 1399 // End of the audit type ids that we care about
EVENT_EOE = 1320 // End of multi packet event
EVENT_END = 1399 // End of the audit type ids that we care about
EVENT_EOE = 1320 // End of multi packet event
)

type AuditMarshaller struct {
msgs map[int]*AuditMessageGroup
writer *AuditWriter
lastSeq int
missed map[int]bool
worstLag int
msgs map[int]*AuditMessageGroup
writer *AuditWriter
lastSeq int
missed map[int]bool
worstLag int
trackMessages bool
logOutOfOrder bool
maxOutOfOrder int
attempts int
attempts int
}

// Create a new marshaller
func NewAuditMarshaller(w *AuditWriter, trackMessages, logOOO bool, maxOOO int) (*AuditMarshaller){
func NewAuditMarshaller(w *AuditWriter, trackMessages, logOOO bool, maxOOO int) *AuditMarshaller {
return &AuditMarshaller{
writer: w,
msgs: make(map[int]*AuditMessageGroup, 5), // It is not typical to have more than 2 message groups at any given time
missed: make(map[int]bool, 10),
writer: w,
msgs: make(map[int]*AuditMessageGroup, 5), // It is not typical to have more than 2 message groups at any given time
missed: make(map[int]bool, 10),
trackMessages: trackMessages,
logOutOfOrder: logOOO,
maxOutOfOrder: maxOOO,
Expand All @@ -47,11 +47,11 @@ func (a *AuditMarshaller) Consume(nlMsg *syscall.NetlinkMessage) {
return
}

if (a.trackMessages) {
if a.trackMessages {
a.detectMissing(aMsg.Seq)
}

if (nlMsg.Header.Type < EVENT_START || nlMsg.Header.Type > EVENT_END) {
if nlMsg.Header.Type < EVENT_START || nlMsg.Header.Type > EVENT_END {
// Drop all audit messages that aren't things we care about or end a multi packet event
a.flushOld()
return
Expand Down Expand Up @@ -103,7 +103,7 @@ func (a *AuditMarshaller) completeMessage(seq int) {

// Track sequence numbers and log if we suspect we missed a message
func (a *AuditMarshaller) detectMissing(seq int) {
if seq > a.lastSeq + 1 && a.lastSeq != 0 {
if seq > a.lastSeq+1 && a.lastSeq != 0 {
// We likely leap frogged over a msg, wait until the next sequence to make sure
for i := a.lastSeq + 1; i < seq; i++ {
a.missed[i] = true
Expand All @@ -117,18 +117,18 @@ func (a *AuditMarshaller) detectMissing(seq int) {
a.worstLag = lag
}

if (a.logOutOfOrder) {
if a.logOutOfOrder {
el.Println("Got sequence", missedSeq, "after", lag, "messages. Worst lag so far", a.worstLag, "messages")
}
delete(a.missed, missedSeq)
} else if seq - missedSeq > a.maxOutOfOrder {
} else if seq-missedSeq > a.maxOutOfOrder {
el.Printf("Likely missed sequence %d, current %d, worst message delay %d\n", missedSeq, seq, a.worstLag)
delete(a.missed, missedSeq)
}
}

if seq > a.lastSeq {
// Keep track of the largest sequence
a.lastSeq = seq
}
if seq > a.lastSeq {
// Keep track of the largest sequence
a.lastSeq = seq
}
}
Loading

0 comments on commit 3cdf789

Please sign in to comment.