Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEriks Sneiders <eriks.sneiders@zabbix.com>2022-03-22 22:41:52 +0300
committerEriks Sneiders <eriks.sneiders@zabbix.com>2022-03-31 17:45:17 +0300
commitac58eb3cda53ca9456f3c5a10e8e27fb252b7ae7 (patch)
treeae438a250cfc285098728595486b1d46b8b7e2c6 /src/go/plugins
parent48b37b5ebebed9cb2e8ad1ed25976161e0df41f7 (diff)
...G...... [ZBXNEXT-7559] code clean up
Diffstat (limited to 'src/go/plugins')
-rw-r--r--src/go/plugins/smart/smart.go9
-rw-r--r--src/go/plugins/smart/smart_test.go1
-rw-r--r--src/go/plugins/smart/smartfs.go31
3 files changed, 23 insertions, 18 deletions
diff --git a/src/go/plugins/smart/smart.go b/src/go/plugins/smart/smart.go
index 8e56aec60b9..b7b406b3fcf 100644
--- a/src/go/plugins/smart/smart.go
+++ b/src/go/plugins/smart/smart.go
@@ -371,12 +371,13 @@ func getAttributeType(devType string, rate int, tables []table) string {
return getTypeByRateAndAttr(rate, tables)
}
-func getAttributes(in deviceParser) (out []string) {
- for _, table := range in.SmartAttributes.Table {
- out = append(out, table.Attrname)
+func getAttributes(in deviceParser) []string {
+ out := make([]string, len(in.SmartAttributes.Table))
+ for i, table := range in.SmartAttributes.Table {
+ out[i] = table.Attrname
}
- return
+ return out
}
func getType(devType string, rate int, tables []table) string {
diff --git a/src/go/plugins/smart/smart_test.go b/src/go/plugins/smart/smart_test.go
index 548168300b4..6677119ec65 100644
--- a/src/go/plugins/smart/smart_test.go
+++ b/src/go/plugins/smart/smart_test.go
@@ -301,6 +301,7 @@ func Test_setSingleDiskFields(t *testing.T) {
gotOut, err := setSingleDiskFields(tt.args.dev)
if (err != nil) != tt.wantErr {
t.Errorf("setSingleDiskFields() error = %v, wantErr %v", err, tt.wantErr)
+
return
}
diff --git a/src/go/plugins/smart/smartfs.go b/src/go/plugins/smart/smartfs.go
index 9a73eeda736..0e139b2deb4 100644
--- a/src/go/plugins/smart/smartfs.go
+++ b/src/go/plugins/smart/smartfs.go
@@ -107,10 +107,6 @@ type power struct {
Hours int `json:"hours"`
}
-type singelRequestAttribute struct {
- SmartAttributes singelRequestTables `json:"ata_smart_attributes"`
-}
-
type singelRequestTables struct {
Table []singelRequestRaw `json:"table"`
}
@@ -264,32 +260,39 @@ func (p *Plugin) executeSingle(path string) (device []byte, err error) {
func (p *Plugin) getDevices() (basic, raid, megaraid []deviceInfo, err error) {
basicTmp, err := p.scanDevices("--scan -j")
if err != nil {
- return nil, nil, nil, fmt.Errorf("Failed to scan for devices: %s.", err)
+ return nil, nil, nil, fmt.Errorf("Failed to scan for devices: %s.", err.Error())
}
raidTmp, err := p.scanDevices("--scan -d sat -j")
if err != nil {
- return nil, nil, nil, fmt.Errorf("Failed to scan for sat devices: %s.", err)
+ return nil, nil, nil, fmt.Errorf("Failed to scan for sat devices: %s.", err.Error())
}
-raid:
- for _, tmp := range basicTmp {
- for _, r := range raidTmp {
+ basic, raid, megaraid = formatDeviceOutput(basicTmp, raidTmp)
+
+ return
+}
+
+func formatDeviceOutput(basic, raid []deviceInfo) (basicDev, raidDev, megaraidDev []deviceInfo) {
+loop:
+ for _, tmp := range basic {
+ for _, r := range raid {
if tmp.Name == r.Name {
- continue raid
+ continue loop
}
}
- basic = append(basic, tmp)
+ basicDev = append(basicDev, tmp)
}
- for _, r := range raidTmp {
+ for _, r := range raid {
if strings.Contains(r.DevType, "megaraid") {
- megaraid = append(megaraid, r)
+ megaraidDev = append(megaraidDev, r)
+
continue
}
- raid = append(raid, r)
+ raidDev = append(raidDev, r)
}
return