| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package megacli |
| 4 | |
| 5 | import ( |
| 6 | "strconv" |
| 7 | "strings" |
| 8 | ) |
| 9 | |
| 10 | func (c *Collector) collect() (map[string]int64, error) { |
| 11 | mx := make(map[string]int64) |
| 12 | |
| 13 | if err := c.collectPhysDrives(mx); err != nil { |
| 14 | return nil, err |
| 15 | } |
| 16 | |
| 17 | if c.doBBU { |
| 18 | if err := c.collectBBU(mx); err != nil { |
| 19 | c.doBBU = false |
| 20 | c.Warningf("BBU collection failed, disabling it: %v", err) |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | return mx, nil |
| 25 | } |
| 26 | |
| 27 | func writeInt(mx map[string]int64, key, value string) { |
| 28 | v, err := strconv.ParseInt(value, 10, 64) |
| 29 | if err != nil { |
| 30 | return |
| 31 | } |
| 32 | mx[key] = v |
| 33 | } |
| 34 | |
| 35 | func getColonSepValue(line string) string { |
| 36 | _, after, ok := strings.Cut(line, ":") |
| 37 | if !ok { |
| 38 | return "" |
| 39 | } |
| 40 | return strings.TrimSpace(after) |
| 41 | } |
| 42 | |
| 43 | func getColonSepNumValue(line string) string { |
| 44 | v := getColonSepValue(line) |
| 45 | before, _, ok := strings.Cut(v, " ") |
| 46 | if !ok { |
| 47 | return v |
| 48 | } |
| 49 | return before |
| 50 | } |