More err check, https://github.com/openbsm/openbsm/pull/75 workaround
This commit is contained in:
parent
9218ae6daa
commit
744f087e6c
31
libbsm.go
31
libbsm.go
@ -412,14 +412,17 @@ func getGroupNameByGid(gid uint32) (group, error) {
|
|||||||
|
|
||||||
func getEventName(event uint16) (string,error) {
|
func getEventName(event uint16) (string,error) {
|
||||||
if len(gEventDB) == 0 {
|
if len(gEventDB) == 0 {
|
||||||
loadEventDB()
|
err := loadEventDB()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("%v\n", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for _, ev := range gEventDB {
|
for _, ev := range gEventDB {
|
||||||
if ev.Type == int(event) {
|
if ev.Type == int(event) {
|
||||||
return ev.Desc, nil
|
return ev.Desc, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("Event ID not found: %x\n", event)
|
return "", fmt.Errorf("Event ID not found: %d\n", event)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We load the entire file in memory
|
// We load the entire file in memory
|
||||||
@ -438,15 +441,28 @@ func loadEventDB() error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
eventStr := strings.Split(line, ":")
|
eventStr := strings.Split(line, ":")
|
||||||
if len(eventStr) != 4 {
|
// Wait for https://github.com/openbsm/openbsm/pull/75
|
||||||
|
//if len(eventStr) != 4 {
|
||||||
|
if (len(eventStr) != 4 && eventStr[0] != "43082") || (len(eventStr) == 5 && eventStr[0] != "43082") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
t, _ := strconv.Atoi(eventStr[0])
|
t, err := strconv.Atoi(eventStr[0])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Unable to convert to int: %v\n", eventStr[0])
|
||||||
|
}
|
||||||
|
// Wait for https://github.com/openbsm/openbsm/pull/75
|
||||||
|
if t == 43082 && (len(eventStr) == 5) {
|
||||||
|
gEventDB = append(gEventDB, event{Type: t,
|
||||||
|
Name: eventStr[1],
|
||||||
|
Desc: eventStr[3],
|
||||||
|
Class: eventStr[4],})
|
||||||
|
} else {
|
||||||
gEventDB = append(gEventDB, event{Type: t,
|
gEventDB = append(gEventDB, event{Type: t,
|
||||||
Name: eventStr[1],
|
Name: eventStr[1],
|
||||||
Desc: eventStr[2],
|
Desc: eventStr[2],
|
||||||
Class: eventStr[3],})
|
Class: eventStr[3],})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,8 +537,11 @@ func (h *Header32) Print(file *os.File, delimiter string, flags int) {
|
|||||||
t := time.Unix((int64)(h.S), 0)
|
t := time.Unix((int64)(h.S), 0)
|
||||||
timeval = t.Format(time.UnixDate)
|
timeval = t.Format(time.UnixDate)
|
||||||
}
|
}
|
||||||
// We dont care for error
|
evdesc, err := getEventName(h.E_type)
|
||||||
evdesc, _ := getEventName(h.E_type)
|
if err != nil {
|
||||||
|
fmt.Printf("%v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
fmt.Fprintf(file, "header%s%d%s%d%s%s%s%v%s%s%s%d", delimiter, h.Size, delimiter, h.Version, delimiter,
|
fmt.Fprintf(file, "header%s%d%s%d%s%s%s%v%s%s%s%d", delimiter, h.Size, delimiter, h.Version, delimiter,
|
||||||
//h.E_type, delimiter, h.E_mod, delimiter, t.Format(time.UnixDate), delimiter, h.Msec)
|
//h.E_type, delimiter, h.E_mod, delimiter, t.Format(time.UnixDate), delimiter, h.Msec)
|
||||||
evdesc, delimiter, h.E_mod, delimiter, timeval, delimiter, h.Msec)
|
evdesc, delimiter, h.E_mod, delimiter, timeval, delimiter, h.Msec)
|
||||||
|
Loading…
Reference in New Issue
Block a user