fix hardward addr bug

This commit is contained in:
liangzy 2020-05-04 11:11:11 +08:00
parent d6024cf64c
commit eebd6500f3
2 changed files with 8 additions and 1 deletions

View File

@ -80,7 +80,7 @@ func (el *esLogger) WriteMsg(when time.Time, msg string, level int, lable string
vals["hostname"] = GetHostname() vals["hostname"] = GetHostname()
vals["working_idr"] = Getwd() vals["working_idr"] = Getwd()
vals["home_dir"] = GetUserHomename() vals["home_dir"] = GetUserHomename()
vals["hardware_addr"] = GetCurrentInterface().HardwareAddr vals["hardware_addr"] = GetCurrentInterfaceHardwareAddr()
vals["client_addrs"] = GetCurrentInterfaceAddrs() vals["client_addrs"] = GetCurrentInterfaceAddrs()
if el.IndexName == "" { if el.IndexName == "" {

View File

@ -15,6 +15,13 @@ func GetCurrentInterface() *net.Interface {
return nil return nil
} }
func GetCurrentInterfaceHardwareAddr() string {
if inter := GetCurrentInterface(); inter != nil {
return fmt.Sprintf("%s", inter.HardwareAddr)
}
return ""
}
func GetCurrentInterfaceAddrs() string { func GetCurrentInterfaceAddrs() string {
if inter := GetCurrentInterface(); inter != nil { if inter := GetCurrentInterface(); inter != nil {
if addrs, err := inter.Addrs(); err == nil { if addrs, err := inter.Addrs(); err == nil {