Debian Codegraph @

ansible_collections/dellemc/openmanage/plugins/module_utils/idrac_utils/info/system_metrics.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # Dell OpenManage Ansible Modules
4 # Version 10.0.0
5 # Copyright (C) 2025 Dell Inc. or its subsidiaries. All Rights Reserved.
6
7 # Redistribution and use in source and binary forms, with or without modification,
8 # are permitted provided that the following conditions are met:
9
10 # * Redistributions of source code must retain the above copyright notice,
11 # this list of conditions and the following disclaimer.
12
13 # * Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #
27
28 from .chassis_sensor_util import IDRACChassisSensors
29
30 GET_SYSTEMBOARD_POWERCONSUMPTION_DETAILS_URI_10 = "/redfish/v1/Chassis/System.Embedded.1/Sensors/SystemBoardPwrConsumption"
31 GET_SYSTEMBOARDINLETTEMP_DETAILS_URI_10 = "/redfish/v1/Chassis/System.Embedded.1/Sensors/SystemBoardInletTemp"
32 GET_INLETTEMP_DETAILS_URI_10 = "/redfish/v1/Chassis/System.Embedded.1/Sensors/InletTemp"
33 GET_POWERHEADROOM_DETAILS_URI_10 = "/redfish/v1/Chassis/System.Embedded.1/Sensors/PowerHeadroom"
34 NA = "Not Available"
35
36
37 class IDRACSystemMetricsInfo(object):
38 def __init__(self, idrac, chassis_sensors: IDRACChassisSensors):
39 self.chassis_sensors = chassis_sensors
40
41 def _get_sensor_data(self, uri: str):
42 response = self.chassis_sensors.get_sensor(uri)
43 return response if response.status_code == 200 else None
44
45 def get_energy_consumption_details(self):
46 response = self.chassis_sensors.get_sensor(GET_SYSTEMBOARD_POWERCONSUMPTION_DETAILS_URI_10)
47 if response.status_code == 200:
48 return response.json_data.get("LifetimeReading", NA)
49 return {}
50
51 def get_temperature_details(self):
52
53 response = (
54 self._get_sensor_data(GET_SYSTEMBOARDINLETTEMP_DETAILS_URI_10)
55 or self._get_sensor_data(GET_INLETTEMP_DETAILS_URI_10)
56 )
57 if response:
58 oem_data = response.json_data.get("Oem", {}).get("Dell", {})
59 inlettemp_critical = oem_data.get("DurationInCriticalThresholdPercent", NA)
60 inlettemp_warn = oem_data.get("DurationInWarningThresholdPercent", NA)
61 return inlettemp_critical, inlettemp_warn
62 return {}, {}
63
64 def get_power_consumption_details(self):
65 response = self.chassis_sensors.get_sensor(GET_POWERHEADROOM_DETAILS_URI_10)
66 if response.status_code == 200:
67 return response.json_data.get("LowestReading", NA)
68 return {}
69
70 def get_system_metrics_info(self):
71 output = []
72 energy_consump = self.get_energy_consumption_details()
73 inlettemp_critical, inlettemp_warn = self.get_temperature_details()
74 power_consumption = self.get_power_consumption_details()
75
76 output = [{
77 "EnergyConsumption": energy_consump,
78 "InletTempCriticalPerc": inlettemp_critical,
79 "InletTempWarnPerc": inlettemp_warn,
80 "Key": "SystemMetrics",
81 "PowerConsumption": power_consumption,
82 "SystemMetrics": "Not Available"
83 }]
84
85 return output