Skip to content
This repository was archived by the owner on Aug 31, 2022. It is now read-only.
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions sonic_data_client/non_db_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ var (
path: []string{"OTHERS", "osversion", "build"},
getFunc: dataGetFunc(getBuildVersion),
},
{ // Get device syslog
path: []string{"OTHERS", "device", "syslog"},
getFunc: dataGetFunc(getDeviceSyslog),
},
}
)

Expand Down Expand Up @@ -229,6 +233,33 @@ func getCpuUtil() ([]byte, error) {
return b, nil
}

func getDeviceSyslog() ([]byte, error) {
hostName := "localhost"
portNum := "5150"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make it configurable parameter and pass in when the service start.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can have 5150 as default value.

service := hostName + ":" + portNum
bufferSize := 1024
RemoteAddr, err := net.ResolveUDPAddr("udp4", service)
portConn, err := net.ListenUDP("udp4", RemoteAddr)
if err != nil {
log.V(2).Infof("%v", err)
return nil, err
}
defer portConn.Close()
buffer := make([]byte, bufferSize)
payloadSize, _, err := portConn.ReadFromUDP(buffer)
if err != nil {
log.V(2).Infof("%v", err)
return buffer, err
}
if bufferSize < payloadSize {
log.V(2).Infof("Payload was larger than buffer", err)
return nil, nil
}

log.V(4).Infof("getDeviceSyslog, output %v", string(buffer[:payloadSize]))
return buffer[:payloadSize], nil
}

func getProcMeminfo() ([]byte, error) {
memInfo, _ := linuxproc.ReadMemInfo("/proc/meminfo")
b, err := json.Marshal(memInfo)
Expand Down