Read Dell iDRAC values through Redfish Topic is solved

Others (MiLight, Hue, Toon etc...)

Moderator: leecollings

User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Read Dell iDRAC values through Redfish

Post by waaren »

Ragdag wrote: Wednesday 06 May 2020 11:47 Unfortunately after a restart of the server the Temperatures array in the json has a different order.

Is there a way for me to loop through the array and pick a value if the name is correct?
If you send the complete JSON and the mapping from the names in the JSON to the deviceNames in domoticz I will have a look if this can be coded in a more generic way.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Ragdag
Posts: 152
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Read Dell iDRAC values through Redfish

Post by Ragdag »

waaren wrote: Wednesday 06 May 2020 12:12
Ragdag wrote: Wednesday 06 May 2020 11:47 Unfortunately after a restart of the server the Temperatures array in the json has a different order.

Is there a way for me to loop through the array and pick a value if the name is correct?
If you send the complete JSON and the mapping from the names in the JSON to the deviceNames in domoticz I will have a look if this can be coded in a more generic way.
This is the entire json payload.

Code: Select all

{
    "@odata.context": "/redfish/v1/$metadata#Thermal.Thermal",
    "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/Thermal",
    "@odata.type": "#Thermal.v1_4_0.Thermal",
    "Description": "Represents the properties for Temperature and Cooling",
    "Fans": [
        {
            "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/Sensors/Fans/0x17%7C%7CFan.Embedded.1",
            "@odata.type": "#Thermal.v1_4_0.Fan",
            "Assembly": {
                "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/Assembly"
            },
            "FanName": "System Board Fan1 RPM",
            "LowerThresholdCritical": 360,
            "LowerThresholdFatal": 360,
            "LowerThresholdNonCritical": 600,
            "MaxReadingRange": null,
            "MemberId": "0x17||Fan.Embedded.1",
            "MinReadingRange": 360,
            "Name": "System Board Fan1 RPM",
            "PhysicalContext": "SystemBoard",
            "Reading": 4440,
            "ReadingUnits": "RPM",
            "Redundancy": [],
            "[email protected]": 0,
            "RelatedItem": [
                {
                    "@odata.id": "/redfish/v1/Chassis/System.Embedded.1"
                }
            ],
            "[email protected]": 1,
            "Status": {
                "Health": "OK",
                "State": "Enabled"
            },
            "UpperThresholdCritical": null,
            "UpperThresholdFatal": null,
            "UpperThresholdNonCritical": null
        },
        {
            "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/Sensors/Fans/0x17%7C%7CFan.Embedded.2",
            "@odata.type": "#Thermal.v1_4_0.Fan",
            "Assembly": {
                "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/Assembly"
            },
            "FanName": "System Board Fan2 RPM",
            "LowerThresholdCritical": 360,
            "LowerThresholdFatal": 360,
            "LowerThresholdNonCritical": 600,
            "MaxReadingRange": null,
            "MemberId": "0x17||Fan.Embedded.2",
            "MinReadingRange": 360,
            "Name": "System Board Fan2 RPM",
            "PhysicalContext": "SystemBoard",
            "Reading": 4440,
            "ReadingUnits": "RPM",
            "Redundancy": [],
            "[email protected]": 0,
            "RelatedItem": [
                {
                    "@odata.id": "/redfish/v1/Chassis/System.Embedded.1"
                }
            ],
            "[email protected]": 1,
            "Status": {
                "Health": "OK",
                "State": "Enabled"
            },
            "UpperThresholdCritical": null,
            "UpperThresholdFatal": null,
            "UpperThresholdNonCritical": null
        },
        {
            "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/Sensors/Fans/0x17%7C%7CFan.Embedded.3",
            "@odata.type": "#Thermal.v1_4_0.Fan",
            "Assembly": {
                "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/Assembly"
            },
            "FanName": "System Board Fan3 RPM",
            "LowerThresholdCritical": 360,
            "LowerThresholdFatal": 360,
            "LowerThresholdNonCritical": 600,
            "MaxReadingRange": null,
            "MemberId": "0x17||Fan.Embedded.3",
            "MinReadingRange": 360,
            "Name": "System Board Fan3 RPM",
            "PhysicalContext": "SystemBoard",
            "Reading": 4440,
            "ReadingUnits": "RPM",
            "Redundancy": [],
            "[email protected]": 0,
            "RelatedItem": [
                {
                    "@odata.id": "/redfish/v1/Chassis/System.Embedded.1"
                }
            ],
            "[email protected]": 1,
            "Status": {
                "Health": "OK",
                "State": "Enabled"
            },
            "UpperThresholdCritical": null,
            "UpperThresholdFatal": null,
            "UpperThresholdNonCritical": null
        },
        {
            "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/Sensors/Fans/0x17%7C%7CFan.Embedded.5",
            "@odata.type": "#Thermal.v1_4_0.Fan",
            "Assembly": {
                "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/Assembly"
            },
            "FanName": "System Board Fan5 RPM",
            "LowerThresholdCritical": 360,
            "LowerThresholdFatal": 360,
            "LowerThresholdNonCritical": 600,
            "MaxReadingRange": null,
            "MemberId": "0x17||Fan.Embedded.5",
            "MinReadingRange": 360,
            "Name": "System Board Fan5 RPM",
            "PhysicalContext": "SystemBoard",
            "Reading": 4440,
            "ReadingUnits": "RPM",
            "Redundancy": [],
            "[email protected]": 0,
            "RelatedItem": [
                {
                    "@odata.id": "/redfish/v1/Chassis/System.Embedded.1"
                }
            ],
            "[email protected]": 1,
            "Status": {
                "Health": "OK",
                "State": "Enabled"
            },
            "UpperThresholdCritical": null,
            "UpperThresholdFatal": null,
            "UpperThresholdNonCritical": null
        },
        {
            "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/Sensors/Fans/0x17%7C%7CFan.Embedded.6",
            "@odata.type": "#Thermal.v1_4_0.Fan",
            "Assembly": {
                "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/Assembly"
            },
            "FanName": "System Board Fan6 RPM",
            "LowerThresholdCritical": 360,
            "LowerThresholdFatal": 360,
            "LowerThresholdNonCritical": 600,
            "MaxReadingRange": null,
            "MemberId": "0x17||Fan.Embedded.6",
            "MinReadingRange": 360,
            "Name": "System Board Fan6 RPM",
            "PhysicalContext": "SystemBoard",
            "Reading": 4440,
            "ReadingUnits": "RPM",
            "Redundancy": [],
            "[email protected]": 0,
            "RelatedItem": [
                {
                    "@odata.id": "/redfish/v1/Chassis/System.Embedded.1"
                }
            ],
            "[email protected]": 1,
            "Status": {
                "Health": "OK",
                "State": "Enabled"
            },
            "UpperThresholdCritical": null,
            "UpperThresholdFatal": null,
            "UpperThresholdNonCritical": null
        },
        {
            "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/Sensors/Fans/0x17%7C%7CFan.Embedded.4",
            "@odata.type": "#Thermal.v1_4_0.Fan",
            "Assembly": {
                "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/Assembly"
            },
            "FanName": "System Board Fan4 RPM",
            "LowerThresholdCritical": 360,
            "LowerThresholdFatal": 360,
            "LowerThresholdNonCritical": 600,
            "MaxReadingRange": null,
            "MemberId": "0x17||Fan.Embedded.4",
            "MinReadingRange": 360,
            "Name": "System Board Fan4 RPM",
            "PhysicalContext": "SystemBoard",
            "Reading": 4320,
            "ReadingUnits": "RPM",
            "Redundancy": [],
            "[email protected]": 0,
            "RelatedItem": [
                {
                    "@odata.id": "/redfish/v1/Chassis/System.Embedded.1"
                }
            ],
            "[email protected]": 1,
            "Status": {
                "Health": "OK",
                "State": "Enabled"
            },
            "UpperThresholdCritical": null,
            "UpperThresholdFatal": null,
            "UpperThresholdNonCritical": null
        }
    ],
    "[email protected]": 6,
    "Id": "Thermal",
    "Name": "Thermal",
    "Redundancy": [
        {
            "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/Thermal/Redundancy/iDRAC.Embedded.1%23SystemBoardFanRedundancy",
            "@odata.type": "#Redundancy.v1_3_0.Redundancy",
            "MaxNumSupported": null,
            "MemberId": "iDRAC.Embedded.1#SystemBoardFanRedundancy",
            "MinNumNeeded": null,
            "Mode": "N+m",
            "Name": "System Board Fan Redundancy",
            "RedundancyEnabled": true,
            "RedundancySet": [],
            "[email protected]": 0,
            "Status": {
                "Health": "OK",
                "State": "Enabled"
            }
        }
    ],
    "[email protected]": 1,
    "Temperatures": [
        {
            "@odata.context": "/redfish/v1/$metadata#Thermal.Thermal",
            "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/Sensors/Temperatures/iDRAC.Embedded.1%23SystemBoardInletTemp",
            "@odata.type": "#Thermal.v1_4_0.Temperature",
            "LowerThresholdCritical": -7,
            "LowerThresholdFatal": -7,
            "LowerThresholdNonCritical": 3,
            "MaxReadingRangeTemp": 47,
            "MemberId": "iDRAC.Embedded.1#SystemBoardInletTemp",
            "MinReadingRangeTemp": -7,
            "Name": "System Board Inlet Temp",
            "PhysicalContext": "SystemBoard",
            "ReadingCelsius": 19,
            "RelatedItem": [
                {
                    "@odata.id": "/redfish/v1/Chassis/System.Embedded.1"
                }
            ],
            "[email protected]": 1,
            "SensorNumber": 4,
            "Status": {
                "Health": "OK",
                "State": "Enabled"
            },
            "UpperThresholdCritical": 47,
            "UpperThresholdFatal": 47,
            "UpperThresholdNonCritical": 42
        },
        {
            "@odata.context": "/redfish/v1/$metadata#Thermal.Thermal",
            "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/Sensors/Temperatures/iDRAC.Embedded.1%23SystemBoardExhaustTemp",
            "@odata.type": "#Thermal.v1_4_0.Temperature",
            "LowerThresholdCritical": 0,
            "LowerThresholdFatal": 0,
            "LowerThresholdNonCritical": 0,
            "MaxReadingRangeTemp": 75,
            "MemberId": "iDRAC.Embedded.1#SystemBoardExhaustTemp",
            "MinReadingRangeTemp": 0,
            "Name": "System Board Exhaust Temp",
            "PhysicalContext": "SystemBoard",
            "ReadingCelsius": 34,
            "RelatedItem": [
                {
                    "@odata.id": "/redfish/v1/Chassis/System.Embedded.1"
                }
            ],
            "[email protected]": 1,
            "SensorNumber": 1,
            "Status": {
                "Health": "OK",
                "State": "Enabled"
            },
            "UpperThresholdCritical": 75,
            "UpperThresholdFatal": 75,
            "UpperThresholdNonCritical": 70
        },
        {
            "@odata.context": "/redfish/v1/$metadata#Thermal.Thermal",
            "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/Sensors/Temperatures/iDRAC.Embedded.1%23CPU1Temp",
            "@odata.type": "#Thermal.v1_4_0.Temperature",
            "LowerThresholdCritical": 3,
            "LowerThresholdFatal": 3,
            "LowerThresholdNonCritical": 8,
            "MaxReadingRangeTemp": 87,
            "MemberId": "iDRAC.Embedded.1#CPU1Temp",
            "MinReadingRangeTemp": 3,
            "Name": "CPU1 Temp",
            "PhysicalContext": "CPU",
            "ReadingCelsius": 58,
            "RelatedItem": [
                {
                    "@odata.id": "/redfish/v1/Systems/System.Embedded.1/Processors/CPU.Socket.1"
                }
            ],
            "[email protected]": 1,
            "SensorNumber": 14,
            "Status": {
                "Health": "OK",
                "State": "Enabled"
            },
            "UpperThresholdCritical": 87,
            "UpperThresholdFatal": 87,
            "UpperThresholdNonCritical": 82
        }
    ],
    "[email protected]": 3
}
This is the current DzVents script

Code: Select all

local scriptVar = 'iDRAC_Temp'

return 
{
	on = 
	{
	    timer = 
	    {
		    'every 5 minutes' -- just an example to trigger the request
	    },
	    httpResponses = 
        {
            scriptVar, -- must match with the callback passed to the openURL command
	    },
	},

    logging = 
    {
        --level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

	execute = function(domoticz, item)

		if (item.isTimer) then
			domoticz.openURL({
				url = 'https://root:[email protected]/redfish/v1/Chassis/System.Embedded.1/Thermal',
				method = 'GET',
				callback = scriptVar, -- see httpResponses above.
			})
		end

		if (item.isHTTPResponse) then

			if (item.ok) then
				if (item.isJSON) then

					local inletTemp = item.json.Temperatures[1].ReadingCelsius
					local ExhaustTemp = item.json.Temperatures[2].ReadingCelsius
					
					domoticz.log('Inlet: ' .. inletTemp, domoticz.LOG_DEBUG)
					domoticz.log('Exhaust: ' .. ExhaustTemp, domoticz.LOG_DEBUG)
					
                    if (domoticz.devices(268).updateTemperature(inletTemp) == 0.0 ) then
                        domoticz.log('There was a problem getting an 0.0 reading for Inlet', domoticz.LOG_ERROR)
                    else
    					-- update some device in Domoticz
	    				domoticz.devices(268).updateTemperature(inletTemp)
		    		end

                    if (domoticz.devices(269).updateTemperature(ExhaustTemp) == 0.0 ) then
                        domoticz.log('There was a problem getting an 0.0 reading for Exhaust', domoticz.LOG_ERROR)
                    else
    					-- update some device in Domoticz
		    			domoticz.devices(269).updateTemperature(ExhaustTemp)
		    		end
			   	end
			else
				domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
				domoticz.log(item, domoticz.LOG_ERROR)
			end

		end

	end
}
The json is converted to a LUA table from what I gather in the wiki so it should be possible, just haven't got a clue how
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Read Dell iDRAC values through Redfish

Post by waaren »

Ragdag wrote: Wednesday 06 May 2020 11:47 Unfortunately after a restart of the server the Temperatures array in the json has a different order.
Is there a way for me to loop through the array and pick a value if the name is correct?
Can you try this one?

Code: Select all

local scriptVar = 'iDRAC_Temp'

return
{
    on =
    {
        timer =
        {
            'every 5 minutes', -- just an example to trigger the request
        },
        httpResponses =
        {
            scriptVar, -- must match with the callback passed to the openURL command
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)

        if item.isTimer then
            dz.openURL({
                url = 'https://root:[email protected]/redfish/v1/Chassis/System.Embedded.1/Thermal',
                method = 'GET',
                callback = scriptVar, -- see httpResponses above.
            })
            return
        end

        if item.isJSON then

            local inletTemp = -999
            local exhaustTemp = -999

            subTable = item.json.Temperatures

            for index, record in ipairs(subTable) do
                if record.Name:find('Inlet Temp') then
                    inletTemp = record.ReadingCelsius
                elseif record.Name:find('Exhaust Temp') then
                    exhaustTemp = record.ReadingCelsius
                end
            end

            if inletTemp == -999 then
                dz.log('There was a problem getting a reading for Inlet', dz.LOG_ERROR)
            else
                dz.devices(268).updateTemperature(inletTemp)
                dz.log('Inlet: ' .. inletTemp, dz.LOG_DEBUG)
            end

            if exhaustTemp == -999 then
                dz.log('There was a problem getting a reading for exhaust', dz.LOG_ERROR)
            else
                dz.devices(269).updateTemperature(exhaustTemp)
                dz.log('Exhaust: ' .. exhaustTemp, dz.LOG_DEBUG)
            end

            --[[
                    This part is not correct the updateTemperature method only returns a table with the values  you just entered
                    What do you want to check ?

                if (dz.devices(268).updateTemperature(inletTemp) == 0.0 ) then
                    dz.log('There was a problem getting an 0.0 reading for Inlet', dz.LOG_ERROR)
            ]]

        else
            dz.log('There was a problem handling the request', dz.LOG_ERROR)
            dz.log(item, dz.LOG_ERROR)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Ragdag
Posts: 152
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Read Dell iDRAC values through Redfish

Post by Ragdag »

waaren wrote: Wednesday 06 May 2020 17:25
Ragdag wrote: Wednesday 06 May 2020 11:47 Unfortunately after a restart of the server the Temperatures array in the json has a different order.
Is there a way for me to loop through the array and pick a value if the name is correct?
Can you try this one?

Code: Select all

local scriptVar = 'iDRAC_Temp'

return
{
    on =
    {
        timer =
        {
            'every 5 minutes', -- just an example to trigger the request
        },
        httpResponses =
        {
            scriptVar, -- must match with the callback passed to the openURL command
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)

        if item.isTimer then
            dz.openURL({
                url = 'https://root:[email protected]/redfish/v1/Chassis/System.Embedded.1/Thermal',
                method = 'GET',
                callback = scriptVar, -- see httpResponses above.
            })
            return
        end

        if item.isJSON then

            local inletTemp = -999
            local exhaustTemp = -999

            subTable = item.json.Temperatures

            for index, record in ipairs(subTable) do
                if record.Name:find('Inlet Temp') then
                    inletTemp = record.ReadingCelsius
                elseif record.Name:find('Exhaust Temp') then
                    exhaustTemp = record.ReadingCelsius
                end
            end

            if inletTemp == -999 then
                dz.log('There was a problem getting a reading for Inlet', dz.LOG_ERROR)
            else
                dz.devices(268).updateTemperature(inletTemp)
                dz.log('Inlet: ' .. inletTemp, dz.LOG_DEBUG)
            end

            if exhaustTemp == -999 then
                dz.log('There was a problem getting a reading for exhaust', dz.LOG_ERROR)
            else
                dz.devices(269).updateTemperature(exhaustTemp)
                dz.log('Exhaust: ' .. exhaustTemp, dz.LOG_DEBUG)
            end

            --[[
                    This part is not correct the updateTemperature method only returns a table with the values  you just entered
                    What do you want to check ?

                if (dz.devices(268).updateTemperature(inletTemp) == 0.0 ) then
                    dz.log('There was a problem getting an 0.0 reading for Inlet', dz.LOG_ERROR)
            ]]

        else
            dz.log('There was a problem handling the request', dz.LOG_ERROR)
            dz.log(item, dz.LOG_ERROR)
        end
    end
}
That part in the if statement was the same thing you are doing with the -999 but mine is completely wrong :D

It looks like success.

Code: Select all

2020-05-06 12:54:10.710 Status: dzVents: Write file: /home/pi/domoticz/scripts/dzVents/generated_scripts/DZ_iDRAC_Temp.lua
2020-05-06 18:18:00.122 Status: dzVents: Info: iDRAC_Temp: ------ Start internal script: DZ_Test:, trigger: "every 1 minutes"
2020-05-06 18:18:00.122 Status: dzVents: Debug: iDRAC_Temp: OpenURL: url = https://root:[email protected]/redfish/v1/Chassis/System.Embedded.1/Thermal
2020-05-06 18:18:00.122 Status: dzVents: Debug: iDRAC_Temp: OpenURL: method = GET
2020-05-06 18:18:00.122 Status: dzVents: Debug: iDRAC_Temp: OpenURL: post data = nil
2020-05-06 18:18:00.122 Status: dzVents: Debug: iDRAC_Temp: OpenURL: headers = nil
2020-05-06 18:18:00.122 Status: dzVents: Debug: iDRAC_Temp: OpenURL: callback = iDRAC_Temp
2020-05-06 18:18:00.122 Status: dzVents: Info: iDRAC_Temp: ------ Finished DZ_Test
2020-05-06 18:18:05.344 Status: dzVents: Info: iDRAC_Temp: ------ Start internal script: DZ_Test: HTTPResponse: "iDRAC_Temp"
2020-05-06 18:18:05.379 Status: dzVents: Debug: iDRAC_Temp: Processing device-adapter for Server Inlet Temp: Temperature device adapter
2020-05-06 18:18:05.380 Status: dzVents: Debug: iDRAC_Temp: Inlet: 22
2020-05-06 18:18:05.381 Status: dzVents: Debug: iDRAC_Temp: Processing device-adapter for Server Exhaust Temp: Temperature device adapter
2020-05-06 18:18:05.381 Status: dzVents: Debug: iDRAC_Temp: Exhaust: 34
2020-05-06 18:18:05.381 Status: dzVents: Info: iDRAC_Temp: ------ Finished DZ_Test 
Thank you for the effort (again :)). I think I understand how you did it, so I might be able to hack that together next time.

You're taking the Temperature section of the JSON and putting that in a table and then go through the records to find the correct one and take the Celsius reading of that record find.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Read Dell iDRAC values through Redfish

Post by waaren »

Ragdag wrote: Wednesday 06 May 2020 18:21 I think I understand how you did it.

You're taking the Temperature section of the JSON and putting that in a table and then go through the records to find the correct one and take the Celsius reading of that record find.
Allmost: item.json is already a table.

Even before your script starts item.data is analyzed in domoticz/dzVents/Utils/HTTPResonse.lua and if it is recognized as a JSON string it is loaded into a Lua table and passed as item.json
Your script perform the actions you describe on the subtable Temperatures
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest