-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhardwareAnalyzer.go
485 lines (420 loc) · 16.2 KB
/
hardwareAnalyzer.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
package main
// Linux Raid/disks configuration detection tool with auto contained disk tools:
// MegaRaid/PERC/SAS2IRCU/ADAPTEC/SoftRAID/ZFS/Btrfs/LVM/Disks Linux support.
// When net and user functions are involved Go compiles dynamically linked binaries
// go-memexec module uses osusergo functionalities, so force to compile statically.
// GOOS="linux" GOARCH="amd64" go build -tags netgo,osusergo -ldflags "-X main.Author=kr0m -X main.AuthorURL=https://alfaexploit.com"
// N=$(wc -l serverList|awk '{print$1}') && i=1 && for SERVER in $(<serverList); do echo "$i/$N SERVER: $SERVER" && scp -J fw ~/hardwareAnalyzer/hardwareAnalyzer $SERVER: && let i=$i+1; done
// pssh -O StrictHostKeyChecking=no -i -h serverList "sudo ./hardwareAnalyzer"
// arcconf dynamic binary: repacked using packelf.sh
// git clone https://github.com/oufm/packelf.git && cd packelf && ./packelf.sh ~/arcconf ./arcconf && cp arcconf ~/hardwareAnalyzer/
// zpool
// git clone https://github.com/oufm/packelf.git && cd packelf && ./packelf.sh /usr/sbin/zpool ./zpool && cp zpool ~/hardwareAnalyzer/
// btrfs
// git clone https://github.com/oufm/packelf.git && cd packelf && ./packelf.sh /usr/bin/btrfs ./btrfs && cp btrfs ~/hardwareAnalyzer/
import (
"flag"
"fmt"
"hardwareAnalyzer/adaptec"
"hardwareAnalyzer/btrfs"
"hardwareAnalyzer/hardwarecontrollerscommon"
"hardwareAnalyzer/lvm"
"hardwareAnalyzer/megaraidpercsas2ircu"
"hardwareAnalyzer/regulardisks"
"hardwareAnalyzer/softraid"
"hardwareAnalyzer/utils"
"hardwareAnalyzer/zfs"
//"github.com/davecgh/go-spew/spew"
"github.com/enescakir/emoji"
"github.com/fatih/color"
"github.com/inancgumus/screen"
)
// We use init to initializar flags in order to not get the error: flag redefined when unit testing code
var showInfo *bool
func init() {
showInfo = flag.Bool("showInfo", false, "Show binary information.")
}
func checkHardware() (bool, bool, bool, bool, bool, bool, bool, bool) {
// MegaRaid check:
megaRaidCheck, err := megaraidpercsas2ircu.CheckMegaraidPerc("mega")
if err != nil {
megaRaidCheck = false
color.Red("++ ERROR: %s", err)
color.Cyan("Dont worry, it only implies that MegaRaid controllers cant be checked, continuing.")
}
// PERC check:
color.Set(color.FgCyan)
fmt.Println("")
percRaidCheck, err := megaraidpercsas2ircu.CheckMegaraidPerc("perc")
if err != nil {
percRaidCheck = false
color.Red("++ ERROR: %s", err)
color.Cyan("Dont worry, it only implies that Dell-PERC controllers cant be checked, continuing.")
}
// SAS2IRCU check:
fmt.Println("")
color.Set(color.FgCyan)
sas2ircuRaidCheck, err := megaraidpercsas2ircu.CheckSas2ircuRaid()
if err != nil {
sas2ircuRaidCheck = false
color.Red("++ ERROR: %s", err)
color.Cyan("Dont worry, it only implies that MegaRaid SAS2IRCU controllers cant be checked, continuing.")
}
// ARCCONF check:
fmt.Println("")
color.Set(color.FgCyan)
// Dont get error return value as executing arcconf in a system without Adaptec controllers always returns: exit status 127
adaptecRaidCheck, err := adaptec.CheckAadaptecRaid()
if err != nil {
adaptecRaidCheck = false
color.Red("++ ERROR: %s", err)
color.Cyan("Dont worry, it only implies that Adaptec controllers cant be checked, continuing.")
}
// SoftRaid check:
fmt.Println("")
color.Set(color.FgCyan)
softRaidCheck, err := softraid.CheckSoftRaid()
if err != nil {
softRaidCheck = false
color.Red("++ ERROR: %s", err)
color.Cyan("Dont worry, it only implies that Softraid configutations cant be checked, continuing.")
}
// ZFS check:
fmt.Println("")
color.Set(color.FgCyan)
zfsRaidCheck, err := zfs.CheckZFSRaid()
if err != nil {
zfsRaidCheck = false
color.Red("++ ERROR: %s", err)
color.Cyan("Dont worry, it only implies that ZFS configutations cant be checked, continuing.")
}
// Btrfs check:
fmt.Println("")
color.Set(color.FgCyan)
btrfsRaidCheck, err := btrfs.CheckBtrfsRaid()
if err != nil {
btrfsRaidCheck = false
color.Red("++ ERROR: %s", err)
color.Cyan("Dont worry, it only implies that Btrfs configutations cant be checked, continuing.")
}
// LVM check:
fmt.Println("")
color.Set(color.FgCyan)
lvmRaidCheck, err := lvm.CheckLVMRaid()
if err != nil {
lvmRaidCheck = false
color.Red("++ ERROR: %s", err)
color.Cyan("Dont worry, it only implies that LVM configutations cant be checked, continuing.")
}
return megaRaidCheck, percRaidCheck, sas2ircuRaidCheck, adaptecRaidCheck, softRaidCheck, zfsRaidCheck, btrfsRaidCheck, lvmRaidCheck
}
func inquireHardwareConfiguration(megaRaidCheck, percRaidCheck, sas2ircuRaidCheck, adaptecRaidCheck, softRaidCheck, zfsRaidCheck, btrfsRaidCheck, lvmRaidCheck bool) ([]utils.ControllerStruct, []utils.PoolStruct, []utils.VolumeGroupStruct, []utils.RaidStruct, []utils.NoRaidDiskStruct) {
// Get detected raid info:
fmt.Println("")
color.Set(color.FgCyan)
// Variables where final data will be stored
var controllers []utils.ControllerStruct
var pools []utils.PoolStruct
var volumeGroups []utils.VolumeGroupStruct
var raids []utils.RaidStruct
var noRaidDisks []utils.NoRaidDiskStruct
// Temp variables for each check
var newControllers []utils.ControllerStruct
var newRaids []utils.RaidStruct
var newNoRaidDisks []utils.NoRaidDiskStruct
if megaRaidCheck {
newControllers, newRaids, newNoRaidDisks, err := megaraidpercsas2ircu.ProcessHWMegaraidPercRaid("mega")
if err != nil {
color.Red("++ ERROR: %s", err)
}
// Append controllers, raids and noraiddisks to already existent
if len(newControllers) > 0 {
for _, newController := range newControllers {
controllers = append(controllers, newController)
}
}
if len(newRaids) > 0 {
for _, newRaid := range newRaids {
raids = append(raids, newRaid)
}
}
if len(newNoRaidDisks) > 0 {
for _, newNoRaidDisk := range newNoRaidDisks {
noRaidDisks = append(noRaidDisks, newNoRaidDisk)
}
}
}
color.Set(color.FgCyan)
if percRaidCheck {
newControllers, newRaids, newNoRaidDisks, err := megaraidpercsas2ircu.ProcessHWMegaraidPercRaid("perc")
if err != nil {
color.Red("++ ERROR: %s", err)
}
// Append controllers, raids and noraiddisks to already existent
if len(newControllers) > 0 {
for _, newController := range newControllers {
controllers = append(controllers, newController)
}
}
if len(newRaids) > 0 {
for _, newRaid := range newRaids {
raids = append(raids, newRaid)
}
}
if len(newNoRaidDisks) > 0 {
for _, newNoRaidDisk := range newNoRaidDisks {
noRaidDisks = append(noRaidDisks, newNoRaidDisk)
}
}
}
color.Set(color.FgCyan)
if sas2ircuRaidCheck {
newControllers, newRaids, newNoRaidDisks, err := megaraidpercsas2ircu.ProcessHWSas2ircuRaid("sas2ircu")
if err != nil {
color.Red("++ ERROR: %s", err)
}
// Append controllers, raids and noraiddisks to already existent
if len(newControllers) > 0 {
for _, newController := range newControllers {
controllers = append(controllers, newController)
}
}
if len(newRaids) > 0 {
for _, newRaid := range newRaids {
raids = append(raids, newRaid)
}
}
if len(newNoRaidDisks) > 0 {
for _, newNoRaidDisk := range newNoRaidDisks {
noRaidDisks = append(noRaidDisks, newNoRaidDisk)
}
}
}
color.Set(color.FgCyan)
if adaptecRaidCheck {
newControllers, newRaids, newNoRaidDisks, err := adaptec.ProcessHWAdaptecRaid("adaptec")
if err != nil {
color.Red("++ ERROR: %s", err)
}
// Append controllers, raids and noraiddisks to already existent
if len(newControllers) > 0 {
for _, newController := range newControllers {
controllers = append(controllers, newController)
}
}
if len(newRaids) > 0 {
for _, newRaid := range newRaids {
raids = append(raids, newRaid)
}
}
if len(newNoRaidDisks) > 0 {
for _, newNoRaidDisk := range newNoRaidDisks {
noRaidDisks = append(noRaidDisks, newNoRaidDisk)
}
}
}
// Softraid requires extra steps like hardwarecontrollerscommon.CheckJbodDisks and hardwarecontrollerscommon.CheckHardRaidDisks in order to rename disks if required and fill model, medium disk info
color.Set(color.FgCyan)
if softRaidCheck {
newControllers, newRaids, err := softraid.ProcessSoftRaid("softraid")
if err != nil {
color.Red("++ ERROR: %s", err)
}
// Check JBOD disks(noRaidDisks) against SoftRaid disks
if err = hardwarecontrollerscommon.CheckJbodDisks(newRaids, noRaidDisks); err != nil {
color.Red("++ ERROR: %s", err)
}
// Append controllers, raids and noraiddisks to already existent
if len(newControllers) > 0 {
for _, newController := range newControllers {
controllers = append(controllers, newController)
}
}
if len(newRaids) > 0 {
for _, newRaid := range newRaids {
raids = append(raids, newRaid)
}
}
}
// ZFS requires extra steps like hardwarecontrollerscommon.CheckJbodDisks, softraid.CheckSoftRaidDisks and hardwarecontrollerscommon.CheckHardRaidDisks in order to rename disks if required and fill model, medium disk info
color.Set(color.FgCyan)
if zfsRaidCheck {
newControllers, newPools, newRaids, err := zfs.ProcessZFSRaid("zfs")
if err != nil {
color.Red("++ ERROR: %s", err)
}
// Check JBOD disks(noRaidDisks) against ZFS disks
if err = hardwarecontrollerscommon.CheckJbodDisks(newRaids, noRaidDisks); err != nil {
color.Red("++ ERROR: %s", err)
}
// Check MD disks against ZFS disks
if err = softraid.CheckSoftRaidDisks(newRaids, raids); err != nil {
color.Red("++ ERROR: %s", err)
}
// Check HardRaid disks against ZFS disks
if err = hardwarecontrollerscommon.CheckHardRaidDisks(newRaids, raids); err != nil {
color.Red("++ ERROR: %s", err)
}
// Append controllers, raids and noraiddisks to already existent
if len(newControllers) > 0 {
for _, newController := range newControllers {
controllers = append(controllers, newController)
}
}
if len(newPools) > 0 {
for _, newPool := range newPools {
pools = append(pools, newPool)
}
}
if len(newRaids) > 0 {
for _, newVdev := range newRaids {
raids = append(raids, newVdev)
}
}
}
// Btrfs requires extra steps like hardwarecontrollerscommon.CheckJbodDisks, softraid.checkSoftRaidDisks and hardwarecontrollerscommon.CheckHardRaidDisks in order to rename disks if required and fill model, medium disk info
color.Set(color.FgCyan)
if btrfsRaidCheck {
newControllers, newRaids, err := btrfs.ProcessBtrfsRaid("btrfs")
if err != nil {
color.Red("++ ERROR: %s", err)
}
// Check JBOD disks(noRaidDisks) against Btrfs disks
if err = hardwarecontrollerscommon.CheckJbodDisks(newRaids, noRaidDisks); err != nil {
color.Red("++ ERROR: %s", err)
}
// Check MD disks against Btrfs disks
if err = softraid.CheckSoftRaidDisks(newRaids, raids); err != nil {
color.Red("++ ERROR: %s", err)
}
// Check HardRaid disks against Btrfs disks
if err = hardwarecontrollerscommon.CheckHardRaidDisks(newRaids, raids); err != nil {
color.Red("++ ERROR: %s", err)
}
// Append controllers, raids and noraiddisks to already existent
if len(newControllers) > 0 {
for _, newController := range newControllers {
controllers = append(controllers, newController)
}
}
if len(newRaids) > 0 {
for _, newRaid := range newRaids {
raids = append(raids, newRaid)
}
}
if len(newNoRaidDisks) > 0 {
for _, newNoRaidDisks := range newNoRaidDisks {
noRaidDisks = append(noRaidDisks, newNoRaidDisks)
}
}
}
// LVM requires extra steps like hardwarecontrollerscommon.CheckJbodDisks, softraid.CheckSoftRaidDisks and hardwarecontrollerscommon.CheckHardRaidDisks in order to rename disks if required and fill model, medium disk info
color.Set(color.FgCyan)
if lvmRaidCheck {
newControllers, newVolumeGroups, newRaids, err := lvm.ProcessLVMRaid("lvm")
if err != nil {
color.Red("++ ERROR: %s", err)
}
// Check JBOD disks(noRaidDisks) against LVM disks
if err = hardwarecontrollerscommon.CheckJbodDisks(newRaids, noRaidDisks); err != nil {
color.Red("++ ERROR: %s", err)
}
// Check MD disks against LVM disks
if err = softraid.CheckSoftRaidDisks(newRaids, raids); err != nil {
color.Red("++ ERROR: %s", err)
}
// Check HardRaid disks against LVM disks
if err = hardwarecontrollerscommon.CheckHardRaidDisks(newRaids, raids); err != nil {
color.Red("++ ERROR: %s", err)
}
// Append controllers, raids and noraiddisks to already existent
if len(newControllers) > 0 {
for _, newController := range newControllers {
controllers = append(controllers, newController)
}
}
if len(newVolumeGroups) > 0 {
for _, newVolumeGroup := range newVolumeGroups {
volumeGroups = append(volumeGroups, newVolumeGroup)
}
}
if len(newRaids) > 0 {
for _, newRaid := range newRaids {
raids = append(raids, newRaid)
}
}
}
// Regular disks
color.Set(color.FgCyan)
newControllers, newRaids, err := regulardisks.ProcessRegularDisks(raids, noRaidDisks)
if err != nil {
color.Red("++ ERROR: %s", err)
}
// Try to fill the most information about disks
err = utils.CheckPreviousDiskData(newRaids, raids)
if err != nil {
color.Red("++ ERROR: %s", err)
}
// Append controllers, raids and noraiddisks to already existent
if len(newControllers) > 0 {
for _, newController := range newControllers {
controllers = append(controllers, newController)
}
}
if len(newRaids) > 0 {
for _, newRaid := range newRaids {
raids = append(raids, newRaid)
}
}
return controllers, pools, volumeGroups, raids, noRaidDisks
}
func main() {
version := "2.8"
codename := "Sistine Chapel"
// Set default font color:
color.Set(color.FgCyan)
screen.MoveTopLeft()
screen.Clear()
fmt.Println("########################################################################################")
fmt.Printf("| HardwareAnalyzer v%v - CodeName: %v %v |\n", version, codename, emoji.LatinCross)
fmt.Println("| Coded by kr0m - MegaRaid/PERC/SAS2IRCU/ADAPTEC/SoftRAID/ZFS/Btrfs/LVM/Disks support. |")
fmt.Println("########################################################################################")
fmt.Println("")
if !utils.IsRoot() {
color.Red("++ ERROR: Binary must be run under root privileges.")
fmt.Println("")
return
}
var err error
var isSupported bool
if isSupported, err = utils.SupportedOS(); !isSupported {
color.Red("++ ERROR: %s", err)
fmt.Println("")
return
}
// -info command:
flag.Parse()
if *showInfo {
color.Set(color.FgCyan)
screen.MoveTopLeft()
screen.Clear()
fmt.Println("#################################################################################################################")
fmt.Printf("| HardwareAnalyzer v%v - CodeName: %v %v |\n", version, codename, emoji.LatinCross)
fmt.Println("| Coded by kr0m(https://alfaexploit.com) - MegaRaid/PERC/SAS2IRCU/ADAPTEC/SoftRAID/ZFS/Btrfs/LVM/Disks support. |")
fmt.Println("| - storcli: Linux/x86-64-static v007.1408.0000.0000 Apr 16, 2020 |")
fmt.Println("| - percCLI: Linux/x86-64-static Ver 007.0127.0000.0000 July 13, 2017 |")
fmt.Println("| - sas2ircu: Linux/x86-64-static Version 20.00.00.00 (2014.09.18) |")
fmt.Println("| - arcconf: Linux/x86-64 Version 2.05 (B22932) - Statically repacked: packelf.sh |")
fmt.Println("| - zpool: Linux/x86-64 Version zfs-2.1.5-1 - Statically repacked: packelf.sh |")
fmt.Println("| - btrfs: Linux/x86-64 Version 5.16.2-1 - Statically repacked: packelf.sh |")
fmt.Println("| - lvm: Linux/x86-64 Version 2.03.11(2) - Statically repacked: packelf.sh |")
fmt.Println("#################################################################################################################")
fmt.Println("")
return
}
megaRaidCheck, percRaidCheck, sas2ircuRaidCheck, adaptecRaidCheck, softRaidCheck, zfsRaidCheck, btrfsRaidCheck, lvmRaidCheck := checkHardware()
controllers, pools, volumeGroups, raids, noRaidDisks := inquireHardwareConfiguration(megaRaidCheck, percRaidCheck, sas2ircuRaidCheck, adaptecRaidCheck, softRaidCheck, zfsRaidCheck, btrfsRaidCheck, lvmRaidCheck)
// Show gathered raid info:
utils.ShowGatheredData(controllers, pools, volumeGroups, raids, noRaidDisks)
fmt.Println("")
}