Skip to content

Commit

Permalink
Merge pull request #29 from mcktr/feature/format-seconds
Browse files Browse the repository at this point in the history
Calculate human readable uptime
  • Loading branch information
mcktr authored Feb 22, 2019
2 parents 9575d26 + 1af2acb commit 614f796
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
11 changes: 8 additions & 3 deletions cmd/check_fritz/check_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,20 @@ func CheckConnectionUptime(aI ArgumentInformation) {
return
}

uptime, err := strconv.ParseFloat(resp.NewUptime, 64)
uptime, err := strconv.Atoi(resp.NewUptime)

if HandleError(err) {
return
}

perfData := perfdata.CreatePerformanceData("uptime", uptime, "s")
days := uptime / 86400
hours := (uptime / 3600) - (days * 24)
minutes := (uptime / 60) - (days * 1440) - (hours * 60)
seconds := uptime % 60
output := fmt.Sprintf("%dd %dh %dm %ds", days, hours, minutes, seconds)
perfData := perfdata.CreatePerformanceData("uptime", float64(uptime), "s")

fmt.Print("OK - Connection Uptime: " + fmt.Sprintf("%.f", uptime) + " " + perfData.GetPerformanceDataAsString() + "\n")
fmt.Print("OK - Connection Uptime: " + fmt.Sprintf("%d", uptime) + " seconds (" + output + ") " + perfData.GetPerformanceDataAsString() + "\n")

GlobalReturnCode = exitOk
}
12 changes: 9 additions & 3 deletions cmd/check_fritz/check_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,21 @@ func CheckDeviceUptime(aI ArgumentInformation) {
return
}

uptime, err := strconv.ParseFloat(resp.NewUpTime, 64)
uptime, err := strconv.Atoi(resp.NewUpTime)

if HandleError(err) {
return
}

perfData := perfdata.CreatePerformanceData("uptime", uptime, "s")
days := uptime / 86400
hours := (uptime / 3600) - (days * 24)
minutes := (uptime / 60) - (days * 1440) - (hours * 60)
seconds := uptime % 60
output := fmt.Sprintf("%dd %dh %dm %ds", days, hours, minutes, seconds)

fmt.Print("OK - Device Uptime: " + fmt.Sprintf("%.0f", uptime) + " " + perfData.GetPerformanceDataAsString() + "\n")
perfData := perfdata.CreatePerformanceData("uptime", float64(uptime), "s")

fmt.Print("OK - Device Uptime: " + fmt.Sprintf("%d", uptime) + " seconds (" + output + ") " + perfData.GetPerformanceDataAsString() + "\n")

GlobalReturnCode = exitOk
}

0 comments on commit 614f796

Please sign in to comment.