-
Notifications
You must be signed in to change notification settings - Fork 7
/
redfish.py
308 lines (272 loc) · 15 KB
/
redfish.py
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
#! /usr/bin/env python3
# -*- coding: utf-8; py-indent-offset: 4 -*-
#
# Author: Linuxfabrik GmbH, Zurich, Switzerland
# Contact: info (at) linuxfabrik (dot) ch
# https://www.linuxfabrik.ch/
# License: The Unlicense, see LICENSE file.
# https://github.com/Linuxfabrik/monitoring-plugins/blob/main/CONTRIBUTING.rst
"""This library parses data returned from the Redfish API.
"""
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2023112901'
from . import base
from . import human
from .globals import STATE_OK, STATE_WARN, STATE_CRIT
# The "Status" property is common to many Redfish schema, and contains:
#
# Health: This represents the health state of this resource in the absence
# of its dependent resources
# * Critical A critical condition exists that requires immediate attention.
# * OK Normal.
# * Warning A condition exists that requires attention
#
# HealthRollup: This represents the overall health state from the view of this
# resource
# * Critical A critical condition exists that requires immediate attention.
# * OK Normal.
# * Warning A condition exists that requires attention.
#
# State:
# * Absent This function or resource is not present or not detected.
# * Deferring The element will not process any commands but will queue new
# requests.
# * Disabled This function or resource has been disabled.
# * Enabled This function or resource has been enabled.
# * InTest This function or resource is undergoing testing.
# * Quiesced The element is enabled but only processes a restricted set of
# commands.
# * StandbyOffline This function or resource is enabled, but awaiting an external action to
# activate it.
# * StandbySpare This function or resource is part of a redundancy set and is awaiting a
# failover or other external action to activate it.
# * Starting This function or resource is starting.
# * UnavailableOffline This function or resource is present but cannot be used.
# * Updating The element is updating and may be unavailable or degraded.
def get_chassis(redfish):
data = {}
data['AssetTag'] = redfish.get('AssetTag', '')
data['ChassisType'] = redfish.get('ChassisType', '')
data['Id'] = redfish.get('Id', '')
data['IndicatorLED'] = redfish.get('IndicatorLED', '')
data['Manufacturer'] = redfish.get('Manufacturer', '')
data['Model'] = redfish.get('Model', '')
data['PartNumber'] = redfish.get('PartNumber', '')
data['PowerState'] = redfish.get('PowerState', '') # On
data['SerialNumber'] = redfish.get('SerialNumber', '')
data['SKU'] = redfish.get('SKU', '')
data['[email protected]'] = redfish.get('Sensors', {}).get('@odata.id', '')
data['Status_State'] = redfish.get('Status', {}).get('State', '') # Enabled
data['Status_Health'] = redfish.get('Status', {}).get('Health', '') # OK
data['Status_HealthRollup'] = redfish.get('Status', {}).get('HealthRollup', '') # OK
return data
def get_chassis_power_powersupplies(redfish):
data = {}
data['FirmwareVersion'] = redfish.get('FirmwareVersion', '')
data['LastPowerOutputWatts'] = redfish.get('LastPowerOutputWatts', '')
if data['LastPowerOutputWatts'] is None:
data['LastPowerOutputWatts'] = redfish.get('PowerOutputWatts', '') # DELL uses this instead
data['LineInputVoltage'] = redfish.get('LineInputVoltage', '')
data['LineInputVoltageType'] = redfish.get('LineInputVoltageType', '')
data['Manufacturer'] = redfish.get('Manufacturer', '')
data['Model'] = redfish.get('Model', '')
data['PartNumber'] = redfish.get('PartNumber', '')
data['PowerCapacityWatts'] = redfish.get('PowerCapacityWatts', '')
data['PowerSupplyType'] = redfish.get('PowerSupplyType', '')
data['SerialNumber'] = redfish.get('SerialNumber', '')
data['SparePartNumber'] = redfish.get('SparePartNumber', '')
data['Status_State'] = redfish.get('Status', {}).get('State', '') # Enabled
data['Status_Health'] = redfish.get('Status', {}).get('Health', '') # OK
return data
def get_chassis_power_voltages(redfish):
data = {}
data['LowerThresholdCritical'] = redfish.get('LowerThresholdCritical', '')
data['LowerThresholdFatal'] = redfish.get('LowerThresholdFatal', '')
data['LowerThresholdNonCritical'] = redfish.get('LowerThresholdNonCritical', '')
data['Name'] = redfish.get('Name', '')
data['PhysicalContext'] = redfish.get('PhysicalContext', '')
data['ReadingVolts'] = redfish.get('ReadingVolts', '')
data['UpperThresholdCritical'] = redfish.get('UpperThresholdCritical', '')
data['UpperThresholdFatal'] = redfish.get('UpperThresholdFatal', '')
data['UpperThresholdNonCritical'] = redfish.get('UpperThresholdNonCritical', '')
data['Status_State'] = redfish.get('Status', {}).get('State', '') # Enabled
data['Status_Health'] = redfish.get('Status', {}).get('Health', '') # OK
return data
def get_chassis_sensors(redfish):
data = {}
data['Id'] = redfish.get('Id', '')
data['Name'] = redfish.get('Name', '')
data['PhysicalContext'] = redfish.get('PhysicalContext', '')
data['Reading'] = redfish.get('Reading', '')
data['ReadingRangeMax'] = redfish.get('ReadingRangeMax', '')
data['ReadingRangeMin'] = redfish.get('ReadingRangeMin', '')
data['ReadingUnits'] = redfish.get('ReadingUnits', '')
data['Thresholds_LowerCaution'] = redfish.get('Thresholds', {}).get('LowerCaution', {}).get('Reading', '')
data['Thresholds_LowerCritical'] = redfish.get('Thresholds', {}).get('LowerCritical', {}).get('Reading', '')
data['Thresholds_UpperCaution'] = redfish.get('Thresholds', {}).get('UpperCaution', {}).get('Reading', '')
data['Thresholds_UpperCritical'] = redfish.get('Thresholds', {}).get('UpperCritical', {}).get('Reading', '')
data['Status_State'] = redfish.get('Status', {}).get('State', '') # Enabled
data['Status_Health'] = redfish.get('Status', {}).get('Health', '') # OK
data['Status_HealthRollup'] = redfish.get('Status', {}).get('HealthRollup', '') # OK
return data
def get_chassis_thermal_fans(redfish):
data = {}
data['FanName'] = redfish.get('FanName', '')
data['HotPluggable'] = redfish.get('HotPluggable', '')
data['LowerThresholdCritical'] = redfish.get('LowerThresholdCritical', '')
data['LowerThresholdFatal'] = redfish.get('LowerThresholdFatal', '')
data['LowerThresholdNonCritical'] = redfish.get('LowerThresholdNonCritical', '')
data['Name'] = redfish.get('Name', '')
data['PhysicalContext'] = redfish.get('PhysicalContext', '')
data['Reading'] = redfish.get('Reading', '')
data['ReadingUnits'] = redfish.get('ReadingUnits', '')
data['SensorNumber'] = redfish.get('SensorNumber', '')
data['UpperThresholdCritical'] = redfish.get('UpperThresholdCritical', '')
data['UpperThresholdFatal'] = redfish.get('UpperThresholdFatal', '')
data['UpperThresholdNonCritical'] = redfish.get('UpperThresholdNonCritical', '')
data['Status_State'] = redfish.get('Status', {}).get('State', '') # Enabled
data['Status_Health'] = redfish.get('Status', {}).get('Health', '') # OK
return data
def get_chassis_thermal_redundancy(redfish):
data = {}
data['Mode'] = redfish.get('Mode', '')
data['Name'] = redfish.get('Name', '')
data['Status_State'] = redfish.get('Status', {}).get('State', '') # Enabled
data['Status_Health'] = redfish.get('Status', {}).get('Health', '') # OK
return data
def get_chassis_thermal_temperatures(redfish):
data = {}
data['LowerThresholdCritical'] = redfish.get('LowerThresholdCritical', '')
data['LowerThresholdFatal'] = redfish.get('LowerThresholdFatal', '')
data['LowerThresholdNonCritical'] = redfish.get('LowerThresholdNonCritical', '')
data['Name'] = redfish.get('Name', '')
data['PhysicalContext'] = redfish.get('PhysicalContext', '')
data['ReadingCelsius'] = redfish.get('ReadingCelsius', '')
data['UpperThresholdCritical'] = redfish.get('UpperThresholdCritical', '')
data['UpperThresholdFatal'] = redfish.get('UpperThresholdFatal', '')
data['UpperThresholdNonCritical'] = redfish.get('UpperThresholdNonCritical', '')
data['Status_State'] = redfish.get('Status', {}).get('State', '') # Enabled
data['Status_Health'] = redfish.get('Status', {}).get('Health', '') # OK
return data
def get_manager_logservices_sel_entries(redfish):
msg = ''
state = STATE_OK
msg_state = STATE_OK
for entry in redfish.get('Members', []):
if entry.get('Severity', '').lower() == 'ok':
continue
if entry.get('Severity', '').lower() == 'critical':
msg_state = STATE_CRIT
if entry.get('Severity', '').lower() == 'warning':
msg_state = STATE_WARN
msg += '* {}: {}{}\n'.format(
entry.get('Created', ''),
entry.get('Message', ''),
base.state2str(msg_state, prefix=' '),
)
state = base.get_worst(state, msg_state)
return msg, state
def get_perfdata(data, key='Reading'):
value = data.get(key, '')
if not value or not isinstance(value, (int, float)):
return ''
name = data.get('Name')
physical_context = data.get('PhysicalContext')
uom = '%' if data.get('ReadingUnits', '') == '%' else None
warn = data['Thresholds_UpperCaution'] if data.get('Thresholds_UpperCaution', '') else None
crit = data['Thresholds_UpperCritical'] if data.get('Thresholds_UpperCritical', '') else None
_min = data['ReadingRangeMin'] if data.get('ReadingRangeMin', '') else None
_max = data['ReadingRangeMax'] if data.get('ReadingRangeMax', '') else None
return base.get_perfdata('{}_{}'.format(physical_context, name).replace(' ', '_'), value, uom, warn, crit, _min, _max)
def get_sensor_state(data, key='Reading'):
value = data.get(key, '')
if not value or not isinstance(value, (int, float)):
return STATE_OK
if data.get('Thresholds_UpperCritical', '') and value >= data['Thresholds_UpperCritical']:
return STATE_CRIT
if data.get('Thresholds_LowerCritical', '') and value <= data['Thresholds_LowerCritical']:
return STATE_CRIT
if data.get('Thresholds_UpperCaution', '') and value >= data['Thresholds_UpperCaution']:
return STATE_WARN
if data.get('Thresholds_LowerCaution', '') and value <= data['Thresholds_LowerCaution']:
return STATE_WARN
return STATE_OK
def get_state(data):
if data.get('Status_State', '') in ['Enabled', 'Quiesced']:
if data.get('Status_HealthRollup') is not None and data.get('Status_HealthRollup').lower() == 'critical':
return STATE_CRIT
if data.get('Status_HealthRollup') is not None and data.get('Status_HealthRollup').lower() == 'warning':
return STATE_WARN
if data.get('Status_Health') is not None and data.get('Status_Health').lower() == 'critical':
return STATE_CRIT
if data.get('Status_Health') is not None and data.get('Status_Health').lower() == 'warning':
return STATE_WARN
return STATE_OK
def get_systems(redfish):
data = {}
data['BiosVersion'] = redfish.get('BiosVersion', '')
data['HostName'] = redfish.get('HostName', '')
data['Id'] = redfish.get('Id', '')
data['IndicatorLED'] = redfish.get('IndicatorLED', '')
data['Manufacturer'] = redfish.get('Manufacturer', '')
data['Model'] = redfish.get('Model', '')
data['PowerState'] = redfish.get('PowerState', '') # On
data['ProcessorSummary_Count'] = redfish.get('ProcessorSummary', {}).get('Count', '')
data['ProcessorSummary_LogicalProcessorCount'] = redfish.get('ProcessorSummary', {}).get('LogicalProcessorCount', '')
data['ProcessorSummary_Model'] = redfish.get('ProcessorSummary', {}).get('Model', '')
data['SerialNumber'] = redfish.get('SerialNumber', '')
data['SKU'] = redfish.get('SKU', '')
data['[email protected]'] = redfish.get('Storage', {}).get('@odata.id', '')
data['Status_State'] = redfish.get('Status', {}).get('State', '') # Enabled
data['Status_Health'] = redfish.get('Status', {}).get('Health', '') # OK
data['Status_HealthRollup'] = redfish.get('Status', {}).get('HealthRollup', '') # OK
return data
def get_systems_storage(redfish):
data = {}
data['Description'] = redfish.get('Description', '')
data['[email protected]'] = redfish.get('[email protected]', '')
data['Id'] = redfish.get('Id', '')
data['Name'] = redfish.get('Name', '')
data['Status_State'] = redfish.get('Status', {}).get('State', '') # Enabled
data['Status_Health'] = redfish.get('Status', {}).get('Health', '') # OK
data['Status_HealthRollup'] = redfish.get('Status', {}).get('HealthRollup', '') # OK
return data
def get_systems_storage_drives(redfish):
data = {}
data['BlockSizeBytes'] = redfish.get('BlockSizeBytes', '')
data['CapableSpeedGbs'] = redfish.get('CapableSpeedGbs', '')
data['CapacityBytes'] = human.bytes2human(redfish.get('CapacityBytes', ''))
data['Description'] = redfish.get('Description', '')
data['EncryptionAbility'] = redfish.get('EncryptionAbility', '')
data['EncryptionStatus'] = redfish.get('EncryptionStatus', '')
data['FailurePredicted'] = redfish.get('FailurePredicted', '')
data['HotspareType'] = redfish.get('HotspareType', '')
data['Id'] = redfish.get('Id', '')
data['Manufacturer'] = redfish.get('Manufacturer', '')
data['MediaType'] = redfish.get('MediaType', '')
data['Model'] = redfish.get('Model', '')
data['Name'] = redfish.get('Name', '')
data['NegotiatedSpeedGbs'] = redfish.get('NegotiatedSpeedGbs', '')
data['PartNumber'] = redfish.get('PartNumber', '')
data['PredictedMediaLifeLeftPercent'] = redfish.get('PredictedMediaLifeLeftPercent', '')
data['Protocol'] = redfish.get('Protocol', '')
data['Revision'] = redfish.get('Revision', '')
data['RotationSpeedRPM'] = redfish.get('RotationSpeedRPM', '')
data['SerialNumber'] = redfish.get('SerialNumber', '')
data['WriteCacheEnabled'] = redfish.get('WriteCacheEnabled', '')
data['Status_State'] = redfish.get('Status', {}).get('State', '') # Enabled
data['Status_Health'] = redfish.get('Status', {}).get('Health', '') # OK
data['Status_HealthRollup'] = redfish.get('Status', {}).get('HealthRollup', '') # OK
return data
def get_vendor(redfish):
vendor = redfish.get('Vendor', '')
if not vendor:
oem = redfish.get('Oem', {})
if oem:
# get the first existing key from Oem dict
vendor = list(oem)[0]
if vendor:
vendor = vendor.lower()
else:
vendor = 'generic'
return vendor