Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Add dataset "device syslog" to non-db client (POC) #83

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
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
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