-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (30 loc) · 1.19 KB
/
main.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
package main
import (
"flag"
"fmt"
"os"
"github.com/shirou/gopsutil/disk"
)
func main() {
d := flag.String("disk", "/", "Disk name.")
warning := flag.Int("warning", 80, "Warning thresold for disk.")
critical := flag.Int("critical", 90, "Critical thresold for disk.")
flag.Parse()
u, err := disk.Usage(*d)
if err != nil {
fmt.Printf("Can't get information - error %v.\n", err)
os.Exit(3)
}
total := u.Total / 1024 / 1024
used := u.Used / 1024 / 1024
if int(u.UsedPercent) >= *critical {
fmt.Printf("CRITICAL - Disk %v percent usage %v%% - Total Disk %v Mo - Used Disk %v Mo | disk_percent = %v,%v,%v,0,100\n", *d, int(u.UsedPercent), total, used, int(u.UsedPercent), *warning, *critical)
os.Exit(2)
} else if int(u.UsedPercent) >= *warning {
fmt.Printf("WARNING - Disk %v percent usage %v%% - Total Disk %v Mo - Used Disk %v Mo | disk_percent = %v,%v,%v,0,100\n", *d, int(u.UsedPercent), total, used, int(u.UsedPercent), *warning, *critical)
os.Exit(1)
} else {
fmt.Printf("OK - Disk %v percent usage %v%% - Total Disk %v Mo - Used Disk %v Mo | disk_percent = %v,%v,%v,0,100\n", *d, int(u.UsedPercent), total, used, int(u.UsedPercent), *warning, *critical)
os.Exit(0)
}
}