From dbab8d86e9dffe4f634621fc98f4a0e1bdd7a634 Mon Sep 17 00:00:00 2001 From: Aidan Date: Fri, 7 Jun 2024 18:20:29 +1200 Subject: [PATCH] Additional error case found --- host/host_aix.go | 12 +++++++++++- host/host_aix_test.go | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/host/host_aix.go b/host/host_aix.go index 5faa1edf8..4358b61fd 100644 --- a/host/host_aix.go +++ b/host/host_aix.go @@ -52,6 +52,7 @@ func BootTimeWithContext(ctx context.Context) (btime uint64, err error) { // 07:43PM up 5 hrs, 1 user, load average: 3.27, 2.91, 2.72 // 11:18:23 up 83 days, 18:29, 4 users, load average: 0.16, 0.03, 0.01 // 08:47PM up 2 days, 20 hrs, 1 user, load average: 2.47, 2.17, 2.17 +// 01:16AM up 4 days, 29 mins, 1 user, load average: 2.29, 2.31, 2.21 func UptimeWithContext(ctx context.Context) (uint64, error) { out, err := invoke.CommandWithContext(ctx, "uptime") if err != nil { @@ -74,7 +75,7 @@ func parseUptime(uptime string) uint64 { } // day provided along with a single hour or hours - // ie: up 2 days, 20 hrs + // ie: up 2 days, 20 hrs, if ut[5] == "hr," || ut[5] == "hrs," { hours, err = strconv.ParseUint(ut[4], 10, 64) if err != nil { @@ -82,6 +83,15 @@ func parseUptime(uptime string) uint64 { } } + // mins provided along with a single min or mins + // ie: up 4 days, 29 mins, + if ut[5] == "min," || ut[5] == "mins," { + mins, err = strconv.ParseUint(ut[4], 10, 64) + if err != nil { + return 0 + } + } + // alternatively day provided with hh:mm // ie: up 83 days, 18:29 if strings.Contains(ut[4], ":") { diff --git a/host/host_aix_test.go b/host/host_aix_test.go index 16da87973..3d497ff8a 100644 --- a/host/host_aix_test.go +++ b/host/host_aix_test.go @@ -17,6 +17,7 @@ func TestParseUptimeValidInput(t *testing.T) { {"07:43PM up 5 hrs, 1 user, load average: 3.27, 2.91, 2.72", 300}, {"11:18:23 up 83 days, 18:29, 4 users, load average: 0.16, 0.03, 0.01", 120629}, {"08:47PM up 2 days, 20 hrs, 1 user, load average: 2.47, 2.17, 2.17", 4080}, + {"01:16AM up 4 days, 29 mins, 1 user, load average: 2.29, 2.31, 2.21", 5789}, } for _, tc := range testCases { got := parseUptime(tc.input)