Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
2cbac9a0c3 | |||
aff1c5af75 | |||
145d061c52 | |||
ea673b809c | |||
b82615a974 | |||
8a4ba4486d | |||
2e6359fbc1 |
@ -43,10 +43,14 @@ const (
|
||||
UnbindRE = `(UNBIND)?`
|
||||
// group[40]
|
||||
ConnClosedRE = `(closed)?(?: \(connection lost\))?`
|
||||
// group[41]
|
||||
AddDnRE = `(?:ADD dn="(.*)")?`
|
||||
// group[42]
|
||||
DelDnRE = `(?:DEL dn="(.*)")?`
|
||||
|
||||
LogLineRE = SyslogPri + TimeRE + ` ` + HostRE + ` ` + ProcessRE + ` ` + ConnIdRE + ` ` + ConnFdRE + OperationIdRE + ` ` +
|
||||
AcceptRE + STARTTLSRE + BindMethodRE + BindMechRE + ResultRE + SearchBaseRE + SearchAttrRE + SearchResultRE + ModDnRE + ModAttrRE +
|
||||
PassModRE + UnbindRE + ConnClosedRE
|
||||
PassModRE + UnbindRE + ConnClosedRE + AddDnRE + DelDnRE
|
||||
)
|
||||
|
||||
type (
|
||||
@ -74,6 +78,8 @@ type (
|
||||
SSF string `json:"ssf"`
|
||||
ModDN string `json:"mod_dn"`
|
||||
ModAttr string `json:"mod_attr"`
|
||||
AddDN string `json:"add_dn"`
|
||||
DelDN string `json:"del_dn"`
|
||||
PassModDN string `json:"passmod_dn"`
|
||||
Result bool
|
||||
ResTag string `json:"result_tag"`
|
||||
@ -184,10 +190,12 @@ func (o *OpenldapLog) Parse(text []byte) (LogFormat, error) {
|
||||
ModDN: string(group[36]),
|
||||
ModAttr: string(group[37]),
|
||||
PassModDN: string(group[38]),
|
||||
AddDN: string(group[41]),
|
||||
DelDN: string(group[42]),
|
||||
}
|
||||
|
||||
// Now handle Operation Type
|
||||
if len(group[11]) > 0 || len(group[13]) > 0 || len(group[14]) > 0 || len(group[15]) > 0 {
|
||||
if len(group[12]) > 0 || len(group[13]) > 0 || len(group[14]) > 0 || len(group[15]) > 0 || len(group[16]) > 0 {
|
||||
logFormat.OpType = "bind"
|
||||
} else if len(group[11]) > 0 {
|
||||
logFormat.OpType = "starttls"
|
||||
@ -203,6 +211,10 @@ func (o *OpenldapLog) Parse(text []byte) (LogFormat, error) {
|
||||
logFormat.OpType = "unbind"
|
||||
} else if len(group[40]) > 0 {
|
||||
logFormat.OpType = "close"
|
||||
} else if len(group[41]) > 0 {
|
||||
logFormat.OpType = "add"
|
||||
} else if len(group[42]) > 0 {
|
||||
logFormat.OpType = "del"
|
||||
}
|
||||
|
||||
return logFormat, nil
|
||||
|
@ -57,6 +57,8 @@ type (
|
||||
SSF string `json:"ssf,omitempty"`
|
||||
ModDN string `json:"mod_dn,omitempty"`
|
||||
ModAttr string `json:"mod_attr,omitempty"`
|
||||
AddDN string `json:"add_dn,omitempty"`
|
||||
DelDN string `json:"del_dn,omitempty"`
|
||||
PassModDN string `json:"passmod_dn,omitempty"`
|
||||
ResTag string `json:"result_tag,omitempty"`
|
||||
ResOid string `json:"result_oid,omitempty"`
|
||||
@ -100,6 +102,8 @@ type (
|
||||
StartTLS bool `json:"starttls,omitempty"`
|
||||
ModDN string `json:"mod_dn,omitempty"`
|
||||
ModAttr string `json:"mod_attr,omitempty"`
|
||||
AddDN string `json:"add_dn,omitempty"`
|
||||
DelDN string `json:"del_dn,omitempty"`
|
||||
PassModDN string `json:"passmod_dn,omitempty"`
|
||||
ResTag string `json:"result_tag,omitempty"`
|
||||
ResOid string `json:"result_oid,omitempty"`
|
||||
@ -125,7 +129,7 @@ var (
|
||||
File os.File
|
||||
Writer *bufio.Writer
|
||||
|
||||
Version = "0.6.6"
|
||||
Version = "0.6.11"
|
||||
|
||||
BuildInfo = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "openldaplogparser_build_info",
|
||||
@ -151,35 +155,43 @@ var (
|
||||
Name: "openldaplogparser_client_count",
|
||||
Help: "Number of connected clients",
|
||||
})
|
||||
AcceptCnt = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
AcceptCnt = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "openldaplogparser_accept_count",
|
||||
Help: "Number of ACCEPT commands executed",
|
||||
}, []string{"host"})
|
||||
BindCnt = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
BindCnt = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "openldaplogparser_bind_count",
|
||||
Help: "Number of BIND commands executed",
|
||||
}, []string{"host"})
|
||||
SearchCnt = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
SearchCnt = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "openldaplogparser_search_count",
|
||||
Help: "Number of SRCH commands executed",
|
||||
}, []string{"host"})
|
||||
ModCnt = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
ModCnt = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "openldaplogparser_mod_count",
|
||||
Help: "Number of MOD commands executed",
|
||||
}, []string{"host"})
|
||||
PassModCnt = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
AddCnt = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "openldaplogparser_add_count",
|
||||
Help: "Number of ADD commands executed",
|
||||
}, []string{"host"})
|
||||
DelCnt = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "openldaplogparser_del_count",
|
||||
Help: "Number of DEL commands executed",
|
||||
}, []string{"host"})
|
||||
PassModCnt = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "openldaplogparser_passmod_count",
|
||||
Help: "Number of PASSMOD commands executed",
|
||||
}, []string{"host"})
|
||||
UnbindCnt = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
UnbindCnt = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "openldaplogparser_unbind_count",
|
||||
Help: "Number of UNBIND commands executed",
|
||||
}, []string{"host"})
|
||||
CloseCnt = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
CloseCnt = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "openldaplogparser_close_count",
|
||||
Help: "Number of closed connections",
|
||||
}, []string{"host"})
|
||||
StartTLSCnt = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
StartTLSCnt = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "openldaplogparser_starttlscount",
|
||||
Help: "Number of STARTTLS commands executed",
|
||||
}, []string{"host"})
|
||||
@ -217,7 +229,7 @@ func OlcToFlat(olc *OpenLdapConnection) []OpenLdapConnectionFlat {
|
||||
|
||||
for i := range olc.Operations {
|
||||
olcf[i] = OpenLdapConnectionFlat{
|
||||
Time: olc.Time,
|
||||
Time: olc.Operations[i].Time,
|
||||
Hostname: olc.Hostname,
|
||||
Process: olc.Process,
|
||||
ClientIp: olc.ClientIp,
|
||||
@ -273,6 +285,22 @@ func OlcToFlat(olc *OpenLdapConnection) []OpenLdapConnectionFlat {
|
||||
olcf[i].ResQTime = olc.Operations[i].ResQTime
|
||||
olcf[i].ResETime = olc.Operations[i].ResETime
|
||||
olcf[i].ResText = olc.Operations[i].ResText
|
||||
case "add":
|
||||
olcf[i].AddDN = olc.Operations[i].AddDN
|
||||
olcf[i].ResTag = olc.Operations[i].ResTag
|
||||
olcf[i].ResOid = olc.Operations[i].ResOid
|
||||
olcf[i].ResErr = olc.Operations[i].ResErr
|
||||
olcf[i].ResQTime = olc.Operations[i].ResQTime
|
||||
olcf[i].ResETime = olc.Operations[i].ResETime
|
||||
olcf[i].ResText = olc.Operations[i].ResText
|
||||
case "del":
|
||||
olcf[i].DelDN = olc.Operations[i].DelDN
|
||||
olcf[i].ResTag = olc.Operations[i].ResTag
|
||||
olcf[i].ResOid = olc.Operations[i].ResOid
|
||||
olcf[i].ResErr = olc.Operations[i].ResErr
|
||||
olcf[i].ResQTime = olc.Operations[i].ResQTime
|
||||
olcf[i].ResETime = olc.Operations[i].ResETime
|
||||
olcf[i].ResText = olc.Operations[i].ResText
|
||||
case "passmod":
|
||||
olcf[i].PassModDN = olc.Operations[i].PassModDN
|
||||
olcf[i].ResTag = olc.Operations[i].ResTag
|
||||
@ -321,35 +349,39 @@ func writeOut(msg string, filename string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Every 24H, remove sent, milter-rejected and deferred that entered queue more than 5 days ago
|
||||
/*
|
||||
func periodicallyCleanMQueue(mqueue map[int]*PostfixLogParser, mqMtx *sync.Mutex) {
|
||||
var ok int
|
||||
func cleanMQueue(mqueue map[string]*OpenLdapConnection, mqMtx *sync.Mutex, age time.Duration) {
|
||||
var ok bool
|
||||
|
||||
for range time.Tick(time.Hour * 24) {
|
||||
// Do we need read lock?
|
||||
for _, inmail := range mqueue {
|
||||
ok = 0
|
||||
// Check all mails were sent (multiple destinations mails)
|
||||
// or rejected
|
||||
for _, outmail := range inmail.Messages {
|
||||
if outmail.Status == "sent" || outmail.Status == "milter-reject" {
|
||||
ok += 1
|
||||
} else if outmail.Status == "deferred" {
|
||||
if inmail.Time.Add(time.Hour * 5 * 24).Before(time.Now()) {
|
||||
ok += 1
|
||||
}
|
||||
log.Printf("Start cleaning queue task: %d items in queue", len(mqueue))
|
||||
|
||||
// Do we need read lock?
|
||||
for uid, ldcon := range mqueue {
|
||||
ok = false
|
||||
// Check if a close operation exist
|
||||
for _, op := range ldcon.Operations {
|
||||
if op.OpType == "close" {
|
||||
if op.Time.Add(age).Before(time.Now()) {
|
||||
ok = true
|
||||
}
|
||||
}
|
||||
if ok == len(inmail.Messages) {
|
||||
mqMtx.Lock()
|
||||
delete(mqueue, inmail.MessageId)
|
||||
mqMtx.Unlock()
|
||||
}
|
||||
}
|
||||
if ok == true {
|
||||
mqMtx.Lock()
|
||||
delete(mqueue, uid)
|
||||
mqMtx.Unlock()
|
||||
}
|
||||
}
|
||||
log.Printf("Finished cleaning queue task: %d items in queue", len(mqueue))
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Every 24H, remove connections closed more than 24 hours ago
|
||||
func periodicallyCleanMQueue(mqueue map[string]*OpenLdapConnection, mqMtx *sync.Mutex) {
|
||||
for range time.Tick(time.Hour * 24) {
|
||||
cleanMQueue(mqueue, mqMtx, 24 * time.Hour)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
func initConfig() {}
|
||||
|
||||
@ -731,6 +763,82 @@ func parseStoreAndWrite(input []byte, mq map[string]*OpenLdapConnection, mqMtx *
|
||||
mqMtx.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
* 2022-07-18T14:35:17.381223+02:00 ldap.domain.org slapd slapd[82581] conn=16113 op=3 ADD dn="cn=coincoin,dc=domain,dc=org"
|
||||
*/
|
||||
if logFormat.AddDN != "" {
|
||||
op := &Operation{
|
||||
Time: logFormat.Time,
|
||||
OpType: logFormat.OpType,
|
||||
OpId: &logFormat.OpId,
|
||||
AddDN: logFormat.AddDN,
|
||||
}
|
||||
mqMtx.Lock()
|
||||
olc, ok := mq[fmt.Sprintf("%s:%d", logFormat.Hostname, logFormat.ConnId)]
|
||||
if false == ok {
|
||||
if false == gDispUnkConn {
|
||||
mqMtx.Unlock()
|
||||
return nil
|
||||
} else {
|
||||
// Create connection
|
||||
olc = &OpenLdapConnection{
|
||||
Time: logFormat.Time,
|
||||
Hostname: logFormat.Hostname,
|
||||
Process: logFormat.Process,
|
||||
ConnId: logFormat.ConnId,
|
||||
ConnFd: logFormat.ConnFd,
|
||||
ClientIp: logFormat.ClientIp,
|
||||
ClientPort: logFormat.ClientPort,
|
||||
ServerIp: logFormat.ServerIp,
|
||||
ServerPort: logFormat.ServerPort,
|
||||
}
|
||||
mq[fmt.Sprintf("%s:%d", logFormat.Hostname, logFormat.ConnId)] = olc
|
||||
}
|
||||
}
|
||||
olc.Operations = append(olc.Operations, op)
|
||||
mqMtx.Unlock()
|
||||
AddCnt.WithLabelValues(olc.Hostname).Inc()
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
* 2022-07-18T14:35:17.381223+02:00 ldap.domain.org slapd slapd[82581] conn=16113 op=3 DEL dn="cn=coincoin,dc=domain,dc=org"
|
||||
*/
|
||||
if logFormat.DelDN != "" {
|
||||
op := &Operation{
|
||||
Time: logFormat.Time,
|
||||
OpType: logFormat.OpType,
|
||||
OpId: &logFormat.OpId,
|
||||
DelDN: logFormat.DelDN,
|
||||
}
|
||||
mqMtx.Lock()
|
||||
olc, ok := mq[fmt.Sprintf("%s:%d", logFormat.Hostname, logFormat.ConnId)]
|
||||
if false == ok {
|
||||
if false == gDispUnkConn {
|
||||
mqMtx.Unlock()
|
||||
return nil
|
||||
} else {
|
||||
// Create connection
|
||||
olc = &OpenLdapConnection{
|
||||
Time: logFormat.Time,
|
||||
Hostname: logFormat.Hostname,
|
||||
Process: logFormat.Process,
|
||||
ConnId: logFormat.ConnId,
|
||||
ConnFd: logFormat.ConnFd,
|
||||
ClientIp: logFormat.ClientIp,
|
||||
ClientPort: logFormat.ClientPort,
|
||||
ServerIp: logFormat.ServerIp,
|
||||
ServerPort: logFormat.ServerPort,
|
||||
}
|
||||
mq[fmt.Sprintf("%s:%d", logFormat.Hostname, logFormat.ConnId)] = olc
|
||||
}
|
||||
}
|
||||
olc.Operations = append(olc.Operations, op)
|
||||
mqMtx.Unlock()
|
||||
DelCnt.WithLabelValues(olc.Hostname).Inc()
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
2022-07-18T11:13:17.521717+02:00 ldap.domain.org slapd[82581] conn=16113 op=4 PASSMOD id="cn=pika,ou=users,dc=domain,dc=org" new
|
||||
@ -975,7 +1083,18 @@ func processLogs(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
// Cleaner thread
|
||||
//go periodicallyCleanMQueue(mQueue, &mqMtx)
|
||||
go periodicallyCleanMQueue(mQueue, &mqMtx)
|
||||
|
||||
// On demand Mqueue cleaning... For debug, dont try this at home, kids!
|
||||
/* sig2 := make(chan os.Signal)
|
||||
signal.Notify(sig2, syscall.SIGUSR2)
|
||||
go func() {
|
||||
for {
|
||||
<-sig2
|
||||
cleanMQueue(mQueue, &mqMtx, 5 * time.Minute)
|
||||
}
|
||||
}()
|
||||
*/
|
||||
|
||||
// Initialize Stdin input...
|
||||
if true == strings.EqualFold(gSyslogListenAddress, "do-not-listen") {
|
||||
|
863
openldap-log-parser_test.go
Normal file
863
openldap-log-parser_test.go
Normal file
@ -0,0 +1,863 @@
|
||||
package openldaplog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
gOlog = NewOpenldapLog(false)
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
)
|
||||
|
||||
|
||||
func TestParseAccept(t *testing.T) {
|
||||
line := `2022-07-18T09:23:20.160516+02:00 ldap.domain.org slapd[82581] conn=1512 fd=10 ACCEPT from IP=10.11.12.16:64482 (IP=0.0.0.0:389)`
|
||||
|
||||
loc,_ := time.LoadLocation("CET")
|
||||
wt := time.Date(2022, 7, 18, 9, 23, 20, 160516*1000, loc)
|
||||
|
||||
lf, err := gOlog.Parse([]byte(line))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if false == lf.Time.Equal(wt) {
|
||||
fmt.Printf("Got : %v\n", lf.Time)
|
||||
fmt.Printf("Wanted: %v\n", wt)
|
||||
t.Error("Parsing time")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") {
|
||||
fmt.Printf("Got : %v\n", lf.Hostname)
|
||||
fmt.Printf("Wanted: ldap.domain.org\n")
|
||||
t.Error("Parsing hostname")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Process, "slapd[82581]") {
|
||||
fmt.Printf("Got : %v\n", lf.Process)
|
||||
fmt.Printf("Wanted: slapd[82581]\n")
|
||||
t.Error("Parsing process")
|
||||
}
|
||||
|
||||
if lf.ConnId != 1512 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnId)
|
||||
fmt.Printf("Wanted: 1512\n")
|
||||
t.Error("Parsing ConnId")
|
||||
}
|
||||
|
||||
if lf.ConnFd != 10 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnFd)
|
||||
fmt.Printf("Wanted: 10\n")
|
||||
t.Error("Parsing ConnFd")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.OpType, "accept") {
|
||||
fmt.Printf("Got : %v\n", lf.OpType)
|
||||
fmt.Printf("Wanted: accept\n")
|
||||
t.Error("Parsing OpType")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.ClientIp, "10.11.12.16") {
|
||||
fmt.Printf("Got : %v\n", lf.ClientIp)
|
||||
fmt.Printf("Wanted: 10.11.12.16\n")
|
||||
t.Error("Parsing ClientIp")
|
||||
}
|
||||
|
||||
if lf.ClientPort != 64482 {
|
||||
fmt.Printf("Got : %v\n", lf.ClientPort)
|
||||
fmt.Printf("Wanted: 64482\n")
|
||||
t.Error("Parsing ClientPort")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.ServerIp, "0.0.0.0") {
|
||||
fmt.Printf("Got : %v\n", lf.ServerIp)
|
||||
fmt.Printf("Wanted: 0.0.0.0\n")
|
||||
t.Error("Parsing ServerIp")
|
||||
}
|
||||
|
||||
if lf.ServerPort != 389 {
|
||||
fmt.Printf("Got : %v\n", lf.ServerPort)
|
||||
fmt.Printf("Wanted: 389\n")
|
||||
t.Error("Parsing ServerPort")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseStartTLS(t *testing.T) {
|
||||
line := `2022-07-18T22:57:50.184389+02:00 ldap.domain.org slapd[82581] conn=1623 op=0 STARTTLS`
|
||||
|
||||
loc,_ := time.LoadLocation("CET")
|
||||
wt := time.Date(2022, 7, 18, 22, 57, 50, 184389*1000, loc)
|
||||
|
||||
lf, err := gOlog.Parse([]byte(line))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if false == lf.Time.Equal(wt) {
|
||||
fmt.Printf("Got : %v\n", lf.Time)
|
||||
fmt.Printf("Wanted: %v\n", wt)
|
||||
t.Error("Parsing time")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") {
|
||||
fmt.Printf("Got : %v\n", lf.Hostname)
|
||||
fmt.Printf("Wanted: ldap.domain.org\n")
|
||||
t.Error("Parsing hostname")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Process, "slapd[82581]") {
|
||||
fmt.Printf("Got : %v\n", lf.Process)
|
||||
fmt.Printf("Wanted: slapd[82581]\n")
|
||||
t.Error("Parsing process")
|
||||
}
|
||||
|
||||
if lf.ConnId != 1623 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnId)
|
||||
fmt.Printf("Wanted: 1512\n")
|
||||
t.Error("Parsing ConnId")
|
||||
}
|
||||
|
||||
if lf.ConnFd != 0 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnFd)
|
||||
fmt.Printf("Wanted: 0\n")
|
||||
t.Error("Parsing ConnFd")
|
||||
}
|
||||
|
||||
if lf.OpId != 0 {
|
||||
fmt.Printf("Got : %v\n", lf.OpId)
|
||||
fmt.Printf("Wanted: 0\n")
|
||||
t.Error("Parsing OpId")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.OpType, "starttls") {
|
||||
fmt.Printf("Got : %v\n", lf.OpType)
|
||||
fmt.Printf("Wanted: \n")
|
||||
t.Error("Parsing OpType")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseBindMethod(t *testing.T) {
|
||||
line := `2022-07-18T09:25:35.224296+02:00 ldap.domain.org slapd[82581] conn=1512 op=1 BIND dn="cn=coincoin,dc=domain,dc=org" method=128`
|
||||
|
||||
loc,_ := time.LoadLocation("CET")
|
||||
wt := time.Date(2022, 7, 18, 9, 25, 35, 224296*1000, loc)
|
||||
|
||||
lf, err := gOlog.Parse([]byte(line))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if false == lf.Time.Equal(wt) {
|
||||
fmt.Printf("Got : %v\n", lf.Time)
|
||||
fmt.Printf("Wanted: %v\n", wt)
|
||||
t.Error("Parsing time")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") {
|
||||
fmt.Printf("Got : %v\n", lf.Hostname)
|
||||
fmt.Printf("Wanted: ldap.domain.org\n")
|
||||
t.Error("Parsing hostname")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Process, "slapd[82581]") {
|
||||
fmt.Printf("Got : %v\n", lf.Process)
|
||||
fmt.Printf("Wanted: slapd[82581]\n")
|
||||
t.Error("Parsing process")
|
||||
}
|
||||
|
||||
if lf.ConnId != 1512 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnId)
|
||||
fmt.Printf("Wanted: 1512\n")
|
||||
t.Error("Parsing ConnId")
|
||||
}
|
||||
|
||||
if lf.ConnFd != 0 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnFd)
|
||||
fmt.Printf("Wanted: 0\n")
|
||||
t.Error("Parsing ConnFd")
|
||||
}
|
||||
|
||||
if lf.OpId != 1 {
|
||||
fmt.Printf("Got : %v\n", lf.OpId)
|
||||
fmt.Printf("Wanted: 1\n")
|
||||
t.Error("Parsing OpId")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.OpType, "bind") {
|
||||
fmt.Printf("Got : %v\n", lf.OpType)
|
||||
fmt.Printf("Wanted: accept\n")
|
||||
t.Error("Parsing OpType")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.BindDN, "cn=coincoin,dc=domain,dc=org") {
|
||||
fmt.Printf("Got : %v\n", lf.BindDN)
|
||||
fmt.Printf("Wanted: cn=coincoin,dc=domain,dc=org\n")
|
||||
t.Error("Parsing BindDN")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.BindMethod, "128") {
|
||||
fmt.Printf("Got : %v\n", lf.BindMethod)
|
||||
fmt.Printf("Wanted: 128\n")
|
||||
t.Error("Parsing BindMethod")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseBindMech(t *testing.T) {
|
||||
line := `2022-07-18T09:25:35.224329+02:00 ldap.domain.org slapd[82581] conn=1512 op=1 BIND dn="cn=coincoin,dc=domain,dc=org" mech=SIMPLE ssf=0`
|
||||
|
||||
loc,_ := time.LoadLocation("CET")
|
||||
wt := time.Date(2022, 7, 18, 9, 25, 35, 224329*1000, loc)
|
||||
|
||||
lf, err := gOlog.Parse([]byte(line))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if false == lf.Time.Equal(wt) {
|
||||
fmt.Printf("Got : %v\n", lf.Time)
|
||||
fmt.Printf("Wanted: %v\n", wt)
|
||||
t.Error("Parsing time")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") {
|
||||
fmt.Printf("Got : %v\n", lf.Hostname)
|
||||
fmt.Printf("Wanted: ldap.domain.org\n")
|
||||
t.Error("Parsing hostname")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Process, "slapd[82581]") {
|
||||
fmt.Printf("Got : %v\n", lf.Process)
|
||||
fmt.Printf("Wanted: slapd[82581]\n")
|
||||
t.Error("Parsing process")
|
||||
}
|
||||
|
||||
if lf.ConnId != 1512 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnId)
|
||||
fmt.Printf("Wanted: 1512\n")
|
||||
t.Error("Parsing ConnId")
|
||||
}
|
||||
|
||||
if lf.ConnFd != 0 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnFd)
|
||||
fmt.Printf("Wanted: 0\n")
|
||||
t.Error("Parsing ConnFd")
|
||||
}
|
||||
|
||||
if lf.OpId != 1 {
|
||||
fmt.Printf("Got : %v\n", lf.OpId)
|
||||
fmt.Printf("Wanted: 1\n")
|
||||
t.Error("Parsing OpId")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.OpType, "bind") {
|
||||
fmt.Printf("Got : %v\n", lf.OpType)
|
||||
fmt.Printf("Wanted: accept\n")
|
||||
t.Error("Parsing OpType")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.BindDN, "") {
|
||||
fmt.Printf("Got : %v\n", lf.BindDN)
|
||||
fmt.Printf("Wanted: \n")
|
||||
t.Error("Parsing BindDN")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.BindMech, "simple") {
|
||||
fmt.Printf("Got : %v\n", lf.BindMech)
|
||||
fmt.Printf("Wanted: simple\n")
|
||||
t.Error("Parsing BindMech")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseResult(t *testing.T) {
|
||||
line := `2022-07-18T09:25:35.224353+02:00 ldap.domain.org slapd[82581] conn=1512 op=1 RESULT tag=97 err=0 text=`
|
||||
|
||||
loc,_ := time.LoadLocation("CET")
|
||||
wt := time.Date(2022, 7, 18, 9, 25, 35, 224353*1000, loc)
|
||||
|
||||
lf, err := gOlog.Parse([]byte(line))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if false == lf.Time.Equal(wt) {
|
||||
fmt.Printf("Got : %v\n", lf.Time)
|
||||
fmt.Printf("Wanted: %v\n", wt)
|
||||
t.Error("Parsing time")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") {
|
||||
fmt.Printf("Got : %v\n", lf.Hostname)
|
||||
fmt.Printf("Wanted: ldap.domain.org\n")
|
||||
t.Error("Parsing hostname")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Process, "slapd[82581]") {
|
||||
fmt.Printf("Got : %v\n", lf.Process)
|
||||
fmt.Printf("Wanted: slapd[82581]\n")
|
||||
t.Error("Parsing process")
|
||||
}
|
||||
|
||||
if lf.ConnId != 1512 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnId)
|
||||
fmt.Printf("Wanted: 1512\n")
|
||||
t.Error("Parsing ConnId")
|
||||
}
|
||||
|
||||
if lf.ConnFd != 0 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnFd)
|
||||
fmt.Printf("Wanted: 0\n")
|
||||
t.Error("Parsing ConnFd")
|
||||
}
|
||||
|
||||
if lf.OpId != 1 {
|
||||
fmt.Printf("Got : %v\n", lf.OpId)
|
||||
fmt.Printf("Wanted: 1\n")
|
||||
t.Error("Parsing OpId")
|
||||
}
|
||||
|
||||
if lf.Result != true {
|
||||
fmt.Printf("Got : %v\n", lf.Result)
|
||||
fmt.Printf("Wanted: true\n")
|
||||
t.Error("Parsing Result")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.OpType, "") {
|
||||
fmt.Printf("Got : %v\n", lf.OpType)
|
||||
fmt.Printf("Wanted: \n")
|
||||
t.Error("Parsing OpType")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.ResTag, "97") {
|
||||
fmt.Printf("Got : %v\n", lf.ResTag)
|
||||
fmt.Printf("Wanted: 97\n")
|
||||
t.Error("Parsing ResTag")
|
||||
}
|
||||
|
||||
if lf.ResErr != 0 {
|
||||
fmt.Printf("Got : %v\n", lf.ResErr)
|
||||
fmt.Printf("Wanted: 0\n")
|
||||
t.Error("Parsing ResErr")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.ResText, "") {
|
||||
fmt.Printf("Got : %v\n", lf.ResText)
|
||||
fmt.Printf("Wanted: \n")
|
||||
t.Error("Parsing ResText")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseUnbind(t *testing.T) {
|
||||
line := `2022-07-18T09:25:35.225177+02:00 ldap.domain.org slapd[82581] conn=1512 op=2 UNBIND`
|
||||
|
||||
loc,_ := time.LoadLocation("CET")
|
||||
wt := time.Date(2022, 7, 18, 9, 25, 35, 225177*1000, loc)
|
||||
|
||||
lf, err := gOlog.Parse([]byte(line))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if false == lf.Time.Equal(wt) {
|
||||
fmt.Printf("Got : %v\n", lf.Time)
|
||||
fmt.Printf("Wanted: %v\n", wt)
|
||||
t.Error("Parsing time")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") {
|
||||
fmt.Printf("Got : %v\n", lf.Hostname)
|
||||
fmt.Printf("Wanted: ldap.domain.org\n")
|
||||
t.Error("Parsing hostname")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Process, "slapd[82581]") {
|
||||
fmt.Printf("Got : %v\n", lf.Process)
|
||||
fmt.Printf("Wanted: slapd[82581]\n")
|
||||
t.Error("Parsing process")
|
||||
}
|
||||
|
||||
if lf.ConnId != 1512 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnId)
|
||||
fmt.Printf("Wanted: 1512\n")
|
||||
t.Error("Parsing ConnId")
|
||||
}
|
||||
|
||||
if lf.ConnFd != 0 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnFd)
|
||||
fmt.Printf("Wanted: 0\n")
|
||||
t.Error("Parsing ConnFd")
|
||||
}
|
||||
|
||||
if lf.OpId != 2 {
|
||||
fmt.Printf("Got : %v\n", lf.OpId)
|
||||
fmt.Printf("Wanted: 2\n")
|
||||
t.Error("Parsing OpId")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.OpType, "unbind") {
|
||||
fmt.Printf("Got : %v\n", lf.OpType)
|
||||
fmt.Printf("Wanted: unbind\n")
|
||||
t.Error("Parsing OpType")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseModDN(t *testing.T) {
|
||||
line := `2022-07-18T09:25:35.224767+02:00 ldap.domain.org slapd[82581] conn=1512 op=3 MOD dn="cn=coincoin,dc=domain,dc=org"`
|
||||
|
||||
loc,_ := time.LoadLocation("CET")
|
||||
wt := time.Date(2022, 7, 18, 9, 25, 35, 224767*1000, loc)
|
||||
|
||||
lf, err := gOlog.Parse([]byte(line))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if false == lf.Time.Equal(wt) {
|
||||
fmt.Printf("Got : %v\n", lf.Time)
|
||||
fmt.Printf("Wanted: %v\n", wt)
|
||||
t.Error("Parsing time")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") {
|
||||
fmt.Printf("Got : %v\n", lf.Hostname)
|
||||
fmt.Printf("Wanted: ldap.domain.org\n")
|
||||
t.Error("Parsing hostname")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Process, "slapd[82581]") {
|
||||
fmt.Printf("Got : %v\n", lf.Process)
|
||||
fmt.Printf("Wanted: slapd[82581]\n")
|
||||
t.Error("Parsing process")
|
||||
}
|
||||
|
||||
if lf.ConnId != 1512 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnId)
|
||||
fmt.Printf("Wanted: 1512\n")
|
||||
t.Error("Parsing ConnId")
|
||||
}
|
||||
|
||||
if lf.ConnFd != 0 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnFd)
|
||||
fmt.Printf("Wanted: 0\n")
|
||||
t.Error("Parsing ConnFd")
|
||||
}
|
||||
|
||||
if lf.OpId != 3 {
|
||||
fmt.Printf("Got : %v\n", lf.OpId)
|
||||
fmt.Printf("Wanted: 3\n")
|
||||
t.Error("Parsing OpId")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.ModDN, "cn=coincoin,dc=domain,dc=org") {
|
||||
fmt.Printf("Got : %v\n", lf.ModDN)
|
||||
fmt.Printf("Wanted: cn=coincoin,dc=domain,dc=org\n")
|
||||
t.Error("Parsing ModDN")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseModAttr(t *testing.T) {
|
||||
line := `2022-07-18T09:25:35.224779+02:00 ldap.domain.org slapd[82581] conn=1512 op=3 MOD attr=description`
|
||||
|
||||
loc,_ := time.LoadLocation("CET")
|
||||
wt := time.Date(2022, 7, 18, 9, 25, 35, 224779*1000, loc)
|
||||
|
||||
lf, err := gOlog.Parse([]byte(line))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if false == lf.Time.Equal(wt) {
|
||||
fmt.Printf("Got : %v\n", lf.Time)
|
||||
fmt.Printf("Wanted: %v\n", wt)
|
||||
t.Error("Parsing time")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") {
|
||||
fmt.Printf("Got : %v\n", lf.Hostname)
|
||||
fmt.Printf("Wanted: ldap.domain.org\n")
|
||||
t.Error("Parsing hostname")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Process, "slapd[82581]") {
|
||||
fmt.Printf("Got : %v\n", lf.Process)
|
||||
fmt.Printf("Wanted: slapd[82581]\n")
|
||||
t.Error("Parsing process")
|
||||
}
|
||||
|
||||
if lf.ConnId != 1512 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnId)
|
||||
fmt.Printf("Wanted: 1512\n")
|
||||
t.Error("Parsing ConnId")
|
||||
}
|
||||
|
||||
if lf.ConnFd != 0 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnFd)
|
||||
fmt.Printf("Wanted: 0\n")
|
||||
t.Error("Parsing ConnFd")
|
||||
}
|
||||
|
||||
if lf.OpId != 3 {
|
||||
fmt.Printf("Got : %v\n", lf.OpId)
|
||||
fmt.Printf("Wanted: 3\n")
|
||||
t.Error("Parsing OpId")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.OpType, "mod") {
|
||||
fmt.Printf("Got : %v\n", lf.OpType)
|
||||
fmt.Printf("Wanted: \n")
|
||||
t.Error("Parsing OpType")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.ModAttr, "description") {
|
||||
fmt.Printf("Got : %v\n", lf.ModAttr)
|
||||
fmt.Printf("Wanted: description\n")
|
||||
t.Error("Parsing ModAttr")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePassMod(t *testing.T) {
|
||||
line := `2022-07-18T09:25:35.224767+02:00 ldap.domain.org slapd[82581] conn=1512 op=4 PASSMOD id="cn=pika,ou=users,dc=domain,dc=org" new`
|
||||
|
||||
loc,_ := time.LoadLocation("CET")
|
||||
wt := time.Date(2022, 7, 18, 9, 25, 35, 224767*1000, loc)
|
||||
|
||||
lf, err := gOlog.Parse([]byte(line))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if false == lf.Time.Equal(wt) {
|
||||
fmt.Printf("Got : %v\n", lf.Time)
|
||||
fmt.Printf("Wanted: %v\n", wt)
|
||||
t.Error("Parsing time")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") {
|
||||
fmt.Printf("Got : %v\n", lf.Hostname)
|
||||
fmt.Printf("Wanted: ldap.domain.org\n")
|
||||
t.Error("Parsing hostname")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Process, "slapd[82581]") {
|
||||
fmt.Printf("Got : %v\n", lf.Process)
|
||||
fmt.Printf("Wanted: slapd[82581]\n")
|
||||
t.Error("Parsing process")
|
||||
}
|
||||
|
||||
if lf.ConnId != 1512 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnId)
|
||||
fmt.Printf("Wanted: 1512\n")
|
||||
t.Error("Parsing ConnId")
|
||||
}
|
||||
|
||||
if lf.ConnFd != 0 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnFd)
|
||||
fmt.Printf("Wanted: 0\n")
|
||||
t.Error("Parsing ConnFd")
|
||||
}
|
||||
|
||||
if lf.OpId != 4 {
|
||||
fmt.Printf("Got : %v\n", lf.OpId)
|
||||
fmt.Printf("Wanted: 4\n")
|
||||
t.Error("Parsing OpId")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.PassModDN, "cn=pika,ou=users,dc=domain,dc=org") {
|
||||
fmt.Printf("Got : %v\n", lf.PassModDN)
|
||||
fmt.Printf("Wanted: cn=pika,ou=users,dc=domain,dc=org\n")
|
||||
t.Error("Parsing PassModDN")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSearchBase(t *testing.T) {
|
||||
line := `2022-07-18T09:25:35.224787+02:00 ldap.domain.org slapd[82581] conn=1512 op=2 SRCH base="ou=users,dc=domain,dc=org" scope=2 deref=0 filter="(&(objectClass=person)(cn=pika))"`
|
||||
|
||||
loc,_ := time.LoadLocation("CET")
|
||||
wt := time.Date(2022, 7, 18, 9, 25, 35, 224787*1000, loc)
|
||||
|
||||
lf, err := gOlog.Parse([]byte(line))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if false == lf.Time.Equal(wt) {
|
||||
fmt.Printf("Got : %v\n", lf.Time)
|
||||
fmt.Printf("Wanted: %v\n", wt)
|
||||
t.Error("Parsing time")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") {
|
||||
fmt.Printf("Got : %v\n", lf.Hostname)
|
||||
fmt.Printf("Wanted: ldap.domain.org\n")
|
||||
t.Error("Parsing hostname")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Process, "slapd[82581]") {
|
||||
fmt.Printf("Got : %v\n", lf.Process)
|
||||
fmt.Printf("Wanted: slapd[82581]\n")
|
||||
t.Error("Parsing process")
|
||||
}
|
||||
|
||||
if lf.ConnId != 1512 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnId)
|
||||
fmt.Printf("Wanted: 1512\n")
|
||||
t.Error("Parsing ConnId")
|
||||
}
|
||||
|
||||
if lf.ConnFd != 0 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnFd)
|
||||
fmt.Printf("Wanted: 0\n")
|
||||
t.Error("Parsing ConnFd")
|
||||
}
|
||||
|
||||
if lf.OpId != 2 {
|
||||
fmt.Printf("Got : %v\n", lf.OpId)
|
||||
fmt.Printf("Wanted: 2\n")
|
||||
t.Error("Parsing OpId")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.OpType, "search") {
|
||||
fmt.Printf("Got : %v\n", lf.OpType)
|
||||
fmt.Printf("Wanted: search\n")
|
||||
t.Error("Parsing OpType")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.SearchBase, "ou=users,dc=domain,dc=org") {
|
||||
fmt.Printf("Got : %v\n", lf.SearchBase)
|
||||
fmt.Printf("Wanted: ou=users,dc=domain,dc=org\n")
|
||||
t.Error("Parsing SearchBase")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.SearchScope, "2") {
|
||||
fmt.Printf("Got : %v\n", lf.SearchScope)
|
||||
fmt.Printf("Wanted: 2\n")
|
||||
t.Error("Parsing SearchScope")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.SearchDeref, "0") {
|
||||
fmt.Printf("Got : %v\n", lf.SearchDeref)
|
||||
fmt.Printf("Wanted: 0\n")
|
||||
t.Error("Parsing SearchDeref")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.SearchFilter, "(&(objectClass=person)(cn=pika))") {
|
||||
fmt.Printf("Got : %v\n", lf.SearchFilter)
|
||||
fmt.Printf("Wanted: (&(objectClass=person)(cn=pika))\n")
|
||||
t.Error("Parsing SearchFilter")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSearchAttr(t *testing.T) {
|
||||
line := `2022-07-18T09:25:35.224779+02:00 ldap.domain.org slapd[82581] conn=1512 op=2 SRCH attr=objectClass userPrincipalName userAccountControl mail rfc822Mailbox entryUUID uid cn`
|
||||
|
||||
loc,_ := time.LoadLocation("CET")
|
||||
wt := time.Date(2022, 7, 18, 9, 25, 35, 224779*1000, loc)
|
||||
|
||||
lf, err := gOlog.Parse([]byte(line))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if false == lf.Time.Equal(wt) {
|
||||
fmt.Printf("Got : %v\n", lf.Time)
|
||||
fmt.Printf("Wanted: %v\n", wt)
|
||||
t.Error("Parsing time")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") {
|
||||
fmt.Printf("Got : %v\n", lf.Hostname)
|
||||
fmt.Printf("Wanted: ldap.domain.org\n")
|
||||
t.Error("Parsing hostname")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Process, "slapd[82581]") {
|
||||
fmt.Printf("Got : %v\n", lf.Process)
|
||||
fmt.Printf("Wanted: slapd[82581]\n")
|
||||
t.Error("Parsing process")
|
||||
}
|
||||
|
||||
if lf.ConnId != 1512 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnId)
|
||||
fmt.Printf("Wanted: 1512\n")
|
||||
t.Error("Parsing ConnId")
|
||||
}
|
||||
|
||||
if lf.ConnFd != 0 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnFd)
|
||||
fmt.Printf("Wanted: 0\n")
|
||||
t.Error("Parsing ConnFd")
|
||||
}
|
||||
|
||||
if lf.OpId != 2 {
|
||||
fmt.Printf("Got : %v\n", lf.OpId)
|
||||
fmt.Printf("Wanted: 2\n")
|
||||
t.Error("Parsing OpId")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.OpType, "") {
|
||||
fmt.Printf("Got : %v\n", lf.OpType)
|
||||
fmt.Printf("Wanted: \n")
|
||||
t.Error("Parsing OpType")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.SearchAttr, "objectClass userPrincipalName userAccountControl mail rfc822Mailbox entryUUID uid cn") {
|
||||
fmt.Printf("Got : %v\n", lf.SearchAttr)
|
||||
fmt.Printf("Wanted: objectClass userPrincipalName userAccountControl mail rfc822Mailbox entryUUID uid cn\n")
|
||||
t.Error("Parsing SearchAttr")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.SearchScope, "") {
|
||||
fmt.Printf("Got : %v\n", lf.SearchScope)
|
||||
fmt.Printf("Wanted: \n")
|
||||
t.Error("Parsing SearchScope")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.SearchDeref, "") {
|
||||
fmt.Printf("Got : %v\n", lf.SearchDeref)
|
||||
fmt.Printf("Wanted: \n")
|
||||
t.Error("Parsing SearchDeref")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.SearchFilter, "") {
|
||||
fmt.Printf("Got : %v\n", lf.SearchFilter)
|
||||
fmt.Printf("Wanted: \n")
|
||||
t.Error("Parsing SearchFilter")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSearchResult(t *testing.T) {
|
||||
line := `2022-07-18T09:25:35.224843+02:00 ldap.domain.org slapd[82581] conn=1512 op=2 SEARCH RESULT tag=101 err=0 nentries=0 text=`
|
||||
|
||||
loc,_ := time.LoadLocation("CET")
|
||||
wt := time.Date(2022, 7, 18, 9, 25, 35, 224843*1000, loc)
|
||||
|
||||
lf, err := gOlog.Parse([]byte(line))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if false == lf.Time.Equal(wt) {
|
||||
fmt.Printf("Got : %v\n", lf.Time)
|
||||
fmt.Printf("Wanted: %v\n", wt)
|
||||
t.Error("Parsing time")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") {
|
||||
fmt.Printf("Got : %v\n", lf.Hostname)
|
||||
fmt.Printf("Wanted: ldap.domain.org\n")
|
||||
t.Error("Parsing hostname")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Process, "slapd[82581]") {
|
||||
fmt.Printf("Got : %v\n", lf.Process)
|
||||
fmt.Printf("Wanted: slapd[82581]\n")
|
||||
t.Error("Parsing process")
|
||||
}
|
||||
|
||||
if lf.ConnId != 1512 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnId)
|
||||
fmt.Printf("Wanted: 1512\n")
|
||||
t.Error("Parsing ConnId")
|
||||
}
|
||||
|
||||
if lf.ConnFd != 0 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnFd)
|
||||
fmt.Printf("Wanted: 0\n")
|
||||
t.Error("Parsing ConnFd")
|
||||
}
|
||||
|
||||
if lf.OpId != 2 {
|
||||
fmt.Printf("Got : %v\n", lf.OpId)
|
||||
fmt.Printf("Wanted: 2\n")
|
||||
t.Error("Parsing OpId")
|
||||
}
|
||||
|
||||
if lf.SearchResult != true {
|
||||
fmt.Printf("Got : %v\n", lf.SearchResult)
|
||||
fmt.Printf("Wanted: true\n")
|
||||
t.Error("Parsing SearchResult")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.OpType, "") {
|
||||
fmt.Printf("Got : %v\n", lf.OpType)
|
||||
fmt.Printf("Wanted: \n")
|
||||
t.Error("Parsing OpType")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.SearchResTag, "101") {
|
||||
fmt.Printf("Got : %v\n", lf.SearchResTag)
|
||||
fmt.Printf("Wanted: 101\n")
|
||||
t.Error("Parsing SearchResTag")
|
||||
}
|
||||
|
||||
if lf.SearchResErr != 0 {
|
||||
fmt.Printf("Got : %v\n", lf.SearchResErr)
|
||||
fmt.Printf("Wanted: 0\n")
|
||||
t.Error("Parsing SearchResErr")
|
||||
}
|
||||
|
||||
if lf.SearchResNEntries != 0 {
|
||||
fmt.Printf("Got : %v\n", lf.SearchResNEntries)
|
||||
fmt.Printf("Wanted: 0\n")
|
||||
t.Error("Parsing SearchResNEntries")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.SearchResText, "") {
|
||||
fmt.Printf("Got : %v\n", lf.SearchResText)
|
||||
fmt.Printf("Wanted: \n")
|
||||
t.Error("Parsing SearchResText")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseClosed(t *testing.T) {
|
||||
line := `2022-07-18T09:23:20.226352+02:00 ldap.domain.org slapd[82581] conn=1512 fd=10 closed`
|
||||
|
||||
loc,_ := time.LoadLocation("CET")
|
||||
wt := time.Date(2022, 7, 18, 9, 23, 20, 226352*1000, loc)
|
||||
|
||||
lf, err := gOlog.Parse([]byte(line))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if false == lf.Time.Equal(wt) {
|
||||
fmt.Printf("Got : %v\n", lf.Time)
|
||||
fmt.Printf("Wanted: %v\n", wt)
|
||||
t.Error("Parsing time")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") {
|
||||
fmt.Printf("Got : %v\n", lf.Hostname)
|
||||
fmt.Printf("Wanted: ldap.domain.org\n")
|
||||
t.Error("Parsing hostname")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.Process, "slapd[82581]") {
|
||||
fmt.Printf("Got : %v\n", lf.Process)
|
||||
fmt.Printf("Wanted: slapd[82581]\n")
|
||||
t.Error("Parsing process")
|
||||
}
|
||||
|
||||
if lf.ConnId != 1512 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnId)
|
||||
fmt.Printf("Wanted: 1512\n")
|
||||
t.Error("Parsing ConnId")
|
||||
}
|
||||
|
||||
if lf.ConnFd != 10 {
|
||||
fmt.Printf("Got : %v\n", lf.ConnFd)
|
||||
fmt.Printf("Wanted: 10\n")
|
||||
t.Error("Parsing ConnFd")
|
||||
}
|
||||
|
||||
if false == strings.EqualFold(lf.OpType, "close") {
|
||||
fmt.Printf("Got : %v\n", lf.OpType)
|
||||
fmt.Printf("Wanted: close\n")
|
||||
t.Error("Parsing OpType")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user