-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathraid.go
179 lines (155 loc) · 4.06 KB
/
raid.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Copyright (c) 2018 the check_snmp_authors. All rights reserved.
// Use of this source code is governed by ISC-style license
// that can be found in the LICENSE file.
package check_snmp_synology
import (
"fmt"
"time"
"bytes"
"strings"
"github.com/sonjah/gosnmp"
)
type raid struct {
Name string
Status int
PercentUsed int
SizeFree int
SizeTotal int
StatusName string
Exitcode int
}
func CheckRaid(s *gosnmp.GoSNMP, u *Utilities) {
//Required fields
service := "Disks"
exitcode := CRITICAL
message := ""
perfdata := ""
// Only proceed if check is configured
if u.Args.Ebox == 0 {
return
}
// Fetch SNMP Data
timeFetch := time.Now()
var err error
var resultsRaidName []gosnmp.SnmpPDU
var resultsRaidStatus []gosnmp.SnmpPDU
var resultsRaidSizeFree []gosnmp.SnmpPDU
var resultsRaidSizeTotal []gosnmp.SnmpPDU
resultsRaidName, err = s.BulkWalkAll(OID_raidName)
if err == nil {
resultsRaidStatus, err = s.BulkWalkAll(OID_raidStatus)
}
if err == nil {
resultsRaidSizeFree, err = s.BulkWalkAll(OID_raidFreeSize)
}
if err == nil {
resultsRaidSizeTotal, err = s.BulkWalkAll(OID_raidTotalSize)
}
// Errorhandling
if err != nil {
exitcode = UNKNOWN
message = err.Error()
Write(u.Args.Hostname, service, exitcode, message, perfdata, u)
return
}
u.Metrics.TimeToFetch += time.Now().Sub(timeFetch)
// Create a ebox slice
raids := []raid{}
for i := 0; i < len(resultsRaidName); i++ {
r := raid{}
r.Name = strings.Trim(bytes.NewBuffer(resultsRaidName[i].Value.([]uint8)).String(), " ")
r.Status = resultsRaidStatus[i].Value.(int)
r.SizeFree = int(resultsRaidSizeFree[i].Value.(uint64)/1024/1024/1024) // Gigabytes
r.SizeTotal = int(resultsRaidSizeTotal[i].Value.(uint64)/1024/1024/1024) // Gigabytes
r.PercentUsed = int(100 * (r.SizeTotal - r.SizeFree) / r.SizeTotal)
raids = append(raids, r)
}
// Set additional fields
setupRaids(raids, u.Args.RaidWarn, u.Args.RaidCrit)
// If diskCheck set, create check for each disk
for i := 0; i < len(raids); i++ {
r := &raids[i]
// Set servicename
service = fmt.Sprintf("RAID %d", i)
// Set exitcode
exitcode = r.Exitcode
// Set message
message = fmt.Sprintf("Name:%s Status:%s Used:%d%% Free:%dGB Total:%dGB", r.Name, r.StatusName, r.PercentUsed, r.SizeFree, r.SizeTotal)
// Set perfdata
perfdata = fmt.Sprintf("Status=%d Used=%d%% Size_free=%dG Size_total=%dG", r.Status, r.PercentUsed, r.SizeFree, r.SizeTotal)
// Done. Write the check result
Write(u.Args.Hostname, service, exitcode, message, perfdata, u)
}
return
}
func setupRaids (raids []raid, warn int, crit int){
for i := 0; i < len(raids); i++ {
// Power1
r := &raids[i]
switch r.Status {
case 1:
r.StatusName = "Normal"
r.Exitcode = OK
case 2:
r.StatusName = "Repairing"
r.Exitcode = CRITICAL
case 3:
r.StatusName = "Migrating"
r.Exitcode = CRITICAL
case 4:
r.StatusName = "Expanding"
r.Exitcode = CRITICAL
case 5:
r.StatusName = "Deleting"
r.Exitcode = CRITICAL
case 6:
r.StatusName = "Creating"
r.Exitcode = CRITICAL
case 7:
r.StatusName = "Syncing"
r.Exitcode = CRITICAL
case 8:
r.StatusName = "ParityChecking"
r.Exitcode = CRITICAL
case 9:
r.StatusName = "Assembling"
r.Exitcode = CRITICAL
case 10:
r.StatusName = "Canceling"
r.Exitcode = CRITICAL
case 11:
r.StatusName = "Degrade"
r.Exitcode = CRITICAL
case 12:
r.StatusName = "Crashed"
r.Exitcode = CRITICAL
case 13:
r.StatusName = "DataScrubbing"
r.Exitcode = CRITICAL
case 14:
r.StatusName = "Deploying"
r.Exitcode = CRITICAL
case 15:
r.StatusName = "UnDeploying"
r.Exitcode = CRITICAL
case 16:
r.StatusName = "MountCache"
r.Exitcode = CRITICAL
case 17:
r.StatusName = "UnmountCache"
r.Exitcode = CRITICAL
case 18:
r.StatusName = "ExpandingUnfinishedSHR"
r.Exitcode = CRITICAL
case 19:
r.StatusName = "ConvertSHRToPool"
r.Exitcode = CRITICAL
case 20:
r.StatusName = "ConvertSHRToSHR2"
r.Exitcode = CRITICAL
default:
r.StatusName = "UnknownStatus"
r.Exitcode = CRITICAL
}
}
}