-
Notifications
You must be signed in to change notification settings - Fork 0
/
fans.go
181 lines (163 loc) · 4.74 KB
/
fans.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
package hpmib
import "strconv"
// FanStatus describes the state of a fan.
type FanStatus int
// FanLocale specifies the location of the fan in the system.
type FanLocale int
// FanRedundancy describes the fault tolerance of the fan.
type FanRedundancy int
// Fan models a fan in the HP MIB.
type Fan struct {
ID int
Locale FanLocale
Redundancy FanRedundancy
Status Status
}
// Table defined by the HP MIB that contains the status of each fan.
const (
cpqHeFltTolFanIndex OID = "1.3.6.1.4.1.232.6.2.6.7.1.2"
cpqHeFltTolFanLocale OID = "1.3.6.1.4.1.232.6.2.6.7.1.3"
cpqHeFltTolFanRedundant OID = "1.3.6.1.4.1.232.6.2.6.7.1.7"
cpqHeFltTolFanCondition OID = "1.3.6.1.4.1.232.6.2.6.7.1.9"
)
// Redundancy states for a fan defined by the HP MIB.
const (
FanRedundancyUnknown FanRedundancy = -11
FanRedundancyOther FanRedundancy = 1
FanRedundancyNotRedundant FanRedundancy = 2
FanRedundancyRedundant FanRedundancy = 3
)
// Locales for a fan defined by the HP MIB.
const (
FanLocaleOther FanLocale = 1
FanLocaleUnknown FanLocale = 2
FanLocaleSystem FanLocale = 3
FanLocaleSystemBoard FanLocale = 4
FanLocaleIOBoard FanLocale = 5
FanLocaleCPU FanLocale = 6
FanLocaleMemory FanLocale = 7
FanLocaleStorage FanLocale = 8
FanLocaleRemovableMedia FanLocale = 9
FanLocalePowerSupply FanLocale = 10
FanLocaleAmbient FanLocale = 11
FanLocaleChassis FanLocale = 12
FanLocaleBridgeCard FanLocale = 13
FanLocaleManagementBoard FanLocale = 14
FanLocaleBackplane FanLocale = 15
FanLocaleNetworkSlot FanLocale = 16
FanLocaleBladeSlot FanLocale = 17
FanLocaleVirtual FanLocale = 18
)
var (
fanLocaleIDMappings = map[string]FanLocale{
"1": FanLocaleOther,
"2": FanLocaleUnknown,
"3": FanLocaleSystem,
"4": FanLocaleSystemBoard,
"5": FanLocaleIOBoard,
"6": FanLocaleCPU,
"7": FanLocaleMemory,
"8": FanLocaleStorage,
"9": FanLocaleRemovableMedia,
"10": FanLocalePowerSupply,
"11": FanLocaleAmbient,
"12": FanLocaleChassis,
"13": FanLocaleBridgeCard,
"14": FanLocaleManagementBoard,
"15": FanLocaleBackplane,
"16": FanLocaleNetworkSlot,
"17": FanLocaleBladeSlot,
"18": FanLocaleVirtual,
}
fanLocaleHumanMappings = map[FanLocale]string{
FanLocaleOther: "Other",
FanLocaleUnknown: "Unknown",
FanLocaleSystem: "System",
FanLocaleSystemBoard: "System Board",
FanLocaleIOBoard: "IO Board",
FanLocaleCPU: "CPU",
FanLocaleMemory: "Memory",
FanLocaleStorage: "Storage",
FanLocaleRemovableMedia: "Removable Media",
FanLocalePowerSupply: "Power Supply",
FanLocaleAmbient: "Ambient",
FanLocaleChassis: "Chassis",
FanLocaleBridgeCard: "Bridge Card",
FanLocaleManagementBoard: "Management Board",
FanLocaleBackplane: "Backplane",
FanLocaleNetworkSlot: "Network Slot",
FanLocaleBladeSlot: "Blade Slot",
FanLocaleVirtual: "Virtual",
}
fanRedundancyIDMappings = map[string]FanRedundancy{
"1": FanRedundancyOther,
"2": FanRedundancyNotRedundant,
"3": FanRedundancyRedundant,
}
fanRedundancyHumanMappings = map[FanRedundancy]string{
FanRedundancyOther: "Other",
FanRedundancyNotRedundant: "Not Redundant",
FanRedundancyRedundant: "Redundant",
}
)
// Fans returns a list of Fans. Returns a non-nil error of the list of Fans
// could not be determined.
func (m *MIB) Fans() ([]Fan, error) {
fans := []Fan{}
columns := OIDList{
cpqHeFltTolFanIndex,
cpqHeFltTolFanLocale,
cpqHeFltTolFanRedundant,
cpqHeFltTolFanCondition,
}
table, err := traverseTable(m.snmpClient, columns)
if err != nil {
return []Fan{}, err
}
for _, row := range table {
index, err := strconv.Atoi(row[0])
if err != nil {
return []Fan{}, err
}
locale := parseFanLocale(row[1])
redundancy := parseFanRedundancy(row[2])
status := parseStatus(row[3])
fans = append(fans, Fan{
ID: index,
Status: status,
Locale: locale,
Redundancy: redundancy,
})
}
return fans, nil
}
func parseFanLocale(s string) FanLocale {
locale, ok := fanLocaleIDMappings[s]
if !ok {
return FanLocaleUnknown
}
return locale
}
// String converts the FanLocale to a human readable string.
func (f *FanLocale) String() string {
s, ok := fanLocaleHumanMappings[*f]
if !ok {
return "Unknown"
}
return s
}
func parseFanRedundancy(s string) FanRedundancy {
redundancy, ok := fanRedundancyIDMappings[s]
if !ok {
return FanRedundancyUnknown
}
return redundancy
}
// String converts the FanRedundancy to a human readable string.
func (f *FanRedundancy) String() string {
s, ok := fanRedundancyHumanMappings[*f]
if !ok {
return "Unknown"
}
return s
}