-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify_system.go
55 lines (45 loc) · 1.43 KB
/
verify_system.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
"strconv"
"strings"
)
func verifyFreeSpace(output string, diskUsagePercentWarning int) []verificationError {
var errors []verificationError
lines := strings.Split(output, "\n")
for _, line := range lines[1:] { // skip header row
columns := strings.Fields(line)
if len(columns) > 1 {
percentValue, err := strconv.Atoi(strings.Trim(columns[1], "%"))
if err != nil {
e := verificationError{title: "Disk usage verification error", message: fmt.Sprint(err)}
errors = append(errors, e)
} else {
if percentValue >= diskUsagePercentWarning {
e := verificationError{
title: "Disk usage verification error",
message: fmt.Sprintf("Disk usage of %s at %d percent\n", columns[2], percentValue)}
errors = append(errors, e)
}
}
}
}
return errors
}
func verifyLoadAvg(output string, uptimeLoad5MinutesWarning float64) []verificationError {
var errors []verificationError
columns := strings.Fields(output)
if len(columns) >= 3 {
floatValue, err := strconv.ParseFloat(columns[1], 64)
if err != nil {
e := verificationError{title: "Load average verification error", message: fmt.Sprint(err)}
errors = append(errors, e)
} else {
if floatValue >= uptimeLoad5MinutesWarning {
e := verificationError{title: "Load average verification error", message: fmt.Sprintf("High load warning: %s\n", output)}
errors = append(errors, e)
}
}
}
return errors
}