Skip to content

Commit

Permalink
Add kernel info to the api
Browse files Browse the repository at this point in the history
  • Loading branch information
vaslabs committed Mar 26, 2021
1 parent 8d2d8c7 commit c2f6883
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions service/web/cmd/pi-web-agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import (
type system_info_response struct {
OS_Info api.Os_Info_Response
Temperature api.Temperature_Response
Kernel string
}

func system_info_handler(w http.ResponseWriter, req *http.Request) {
os_info := api.OS_Info()
temperature := api.Measure_Temperature()
kernel_info := api.Kernel_Info()
json.NewEncoder(w).Encode(system_info_response{
os_info,
temperature,
kernel_info,
})
}

Expand Down
14 changes: 14 additions & 0 deletions service/web/pkg/live_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,17 @@ func Measure_Temperature_From(command string, args ...string) Temperature_Respon
}
}
}

func Kernel_Info() string {
return Kernel_Info_From("uname", "-r")
}

func Kernel_Info_From(command string, args...string) string {
output, error := shell.RunSingle(command, args...)
if (error != nil) {
log.Fatalf("Error getting kernel info: %s", error)
return ""
} else {
return output
}
}
8 changes: 8 additions & 0 deletions service/web/test/os_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ func TestTempMeasure(t *testing.T) {
}
}

func TestKernelInfo(t *testing.T) {
expectedKernelInfo := "5.11.9-200"
kernel_info := api.Kernel_Info_From("echo", "-n", "5.11.9-200")
if (expectedKernelInfo != kernel_info) {
expectationFailure(expectedKernelInfo, kernel_info, t)
}
}

func expectationFailure(expected string, got string, t *testing.T) {
t.Errorf("Expected %s but got %s", expected, got)
}

0 comments on commit c2f6883

Please sign in to comment.