Exploring the HPE G2 PDU REST API

· by Rudi Martinsen · Read in about 6 min · (1075 words)

Lately I’ve been playing around with the Redfish based REST API in the HPE G2 Metered and Switched Power Distribution Units.

Through the API you are able to pull some details about the PDU as well as different utilization data. Based on your PDUs capabilities you should also be able to control different outlets. My focus has been to pull some details about the PDUs, and to pull the load on the different segments.

As I usually do when I set out exploring an API I was looking for the documentation. Surprisingly there was nothing to be found. The only thing I found was a few lines in the PDU User guide regarding authentication.

Luckily as the API is based on the Redfish standard I was able to start exploring it through Postman.

From the user guide I learned that the API used Basic auth for GET requests. So I did a GET to the https://mgmtIP/redfish/v1/ , specified Basic auth in the Postman client and boom, I got the schema out

    {
        "@odata.context": "/redfish/v1/$metadata#ServiceRoot",
        "AccountService": {
            "@odata.id": "href/redfish/v1/AccountService"
        },
        "@odata.type": "#ServiceRoot.1.0.0.ServiceRoot",
        "@odata.id": "/redfish/v1",
        "Name": "Redfish Root Service",
        "PowerDistribution": {
            "@odata.id": "/redfish/v1/RackPower/PowerDistribution"
        },
        "links": {
            "Session": {
                "@odata.id": "/redfish/v1/SessionService/Sessions"
            }
        },
        "EventService": {
            "@odata.id": "href/redfish/v1/EventService"
        },
        "Manager": {
            "@odata.id": "/redfish/v1/Managers"
        },
        "SessionService": {
            "@odata.id": "/redfish/v1/SessionService"
        },
        "JsonSchemas": {
            "@odata.id": "/redfish/v1/Schemas"
        },
        "Id": "v1",
        "RedfishVersion": "1.0.0"
    }

The interesting endpoints and the ones I’m exploring will be the PowerDistribution ones.

There are a few endpoints to check (I’ve abbreviated the urls and removed https://mgmtIp/redfish/v1):

  • /RackPower/PowerDistribution

This will list the available PDUs:

{
    "Members@odata.count": 4,
    "@odata.context": "/redfish/v1/$metadata#PowerDistribution",
    "@odata.type": "#PowerDistributionCollection.1.0.0.PowerDistributionCollection",
    "@odata.id": "/redfish/v1/RackPower/PowerDistribution/",
    "Description": "Power Distribution Details",
    "Name": "PowerDistribution",
    "Members": [
        {
            "@odata.id": "/redfish/v1/PowerDistribution/1"
        },
        {
            "@odata.id": "/redfish/v1/PowerDistribution/2"
        },
        {
            "@odata.id": "/redfish/v1/PowerDistribution/3"
        },
        {
            "@odata.id": "/redfish/v1/PowerDistribution/4"
        }
    ]
}
  • /PowerDistribution/"pduId"

This is listing details about the specified PDU

{
    "Core_location": "",
    "@odata.context": "/redfish/v1/$metadata#PowerDistribution",
    "BreakerRating": 0,
    "InputRating": 16,
    "Model": "230V, 16A, 11.0kVA, 50/60Hz",
    "LoadsegmentMeasurement": [
        {
            "@odata.id": "/redfish/v1/PowerDistribution/1/PowerMeasurement/LoadsegmentMeasurement"
        }
    ],
    "Core_u_position": "",
    "@odata.type": "#PowerDistribution.1.0.0.PowerDistribution",
    "Panel_name": "",
    "@odata.id": "/redfish/v1/PowerDistribution/1",
    "OutletMeasurement": [
        {
            "@odata.id": "/redfish/v1/PowerDistribution/1/PowerMeasurement/Loadsegment/1/OutletMeasurement"
        },
        {
            "@odata.id": "/redfish/v1/PowerDistribution/1/PowerMeasurement/Loadsegment/2/OutletMeasurement"
        },
        {
            "@odata.id": "/redfish/v1/PowerDistribution/1/PowerMeasurement/Loadsegment/3/OutletMeasurement"
        },
        {
            "@odata.id": "/redfish/v1/PowerDistribution/1/PowerMeasurement/Loadsegment/4/OutletMeasurement"
        },
        {
            "@odata.id": "/redfish/v1/PowerDistribution/1/PowerMeasurement/Loadsegment/5/OutletMeasurement"
        },
        {
            "@odata.id": "/redfish/v1/PowerDistribution/1/PowerMeasurement/Loadsegment/6/OutletMeasurement"
        }
    ],
    "Firmware_version": "2.0.0.C",
    "Serial": "xxxxxx",
    "Id": 1,
    "PartNumber": "P9S20A",
    "DeviceType": "PowerDistributionUnit",
    "PowerDistributionNumber": 1,
    "Boot_version": "2.25",
    "Hardware_version": "HPE",
    "Voltage": 240,
    "KVARating": 11,
    "Power_rating": 11,
    "OutletControl": [
        {
            "@odata.id": "/redfish/v1/PowerDistribution/1/PowerControl/Loadsegment/1/OutletControl"
        },
        {
            "@odata.id": "/redfish/v1/PowerDistribution/1/PowerControl/Loadsegment/2/OutletControl"
        },
        {
            "@odata.id": "/redfish/v1/PowerDistribution/1/PowerControl/Loadsegment/3/OutletControl"
        },
        {
            "@odata.id": "/redfish/v1/PowerDistribution/1/PowerControl/Loadsegment/4/OutletControl"
        },
        {
            "@odata.id": "/redfish/v1/PowerDistribution/1/PowerControl/Loadsegment/5/OutletControl"
        },
        {
            "@odata.id": "/redfish/v1/PowerDistribution/1/PowerControl/Loadsegment/6/OutletControl"
        }
    ]
}

As you can see there’s links to both the LoadsegmentMeasurement, OutletMeasurement and OutletControl for each segment of the specified PDU.

  • /PowerDistribution/"pduId"/PowerMeasurement/LoadsegmentMeasurement

Here we pull the current load of each of the segments on the specified PDU

{
    "@odata.context": "/redfish/v1/$metadata#PowerDistributionUnit",
    "@odata.type": "#PowerMeasurement.1.0.0.PowerMeasurement",
    "@odata.id": "/redfish/v1/PowerDistribution/PowerMeasurement/LoadsegmentMeasurement",
    "Description": "Power Measurement details for the loadsegment",
    "Name": "LoadsegmentMeasurement",
    "PduId": 1,
    "LoadSegment@odata.count": 6,
    "Loadsegments": [
        {
            "Current": 0,
            "LoadSegmentId": 1,
            "BreakerStatus": "Normal",
            "AppearantPower": 0,
            "RatedCurrent": 0,
            "voltage": 0,
            "ActivePower": 0,
            "RealPower": 0,
            "PowerFactor": 1,
            "Energy": 0
        },
        {
            "Current": 1,
            "LoadSegmentId": 2,
            "BreakerStatus": "Normal",
            "AppearantPower": 399,
            "RatedCurrent": 0,
            "voltage": 226,
            "ActivePower": 386,
            "RealPower": 46557,
            "PowerFactor": 0,
            "Energy": 0
        },
        {
            "Current": 0,
            "LoadSegmentId": 3,
            "BreakerStatus": "Normal",
            "AppearantPower": 79,
            "RatedCurrent": 0,
            "voltage": 226,
            "ActivePower": 22,
            "RealPower": 38039,
            "PowerFactor": 0,
            "Energy": 0
        },
        {
            "Current": 0,
            "LoadSegmentId": 4,
            "BreakerStatus": "Normal",
            "AppearantPower": 0,
            "RatedCurrent": 0,
            "voltage": 227,
            "ActivePower": 0,
            "RealPower": 0,
            "PowerFactor": 1,
            "Energy": 0
        },
        {
            "Current": 0,
            "LoadSegmentId": 5,
            "BreakerStatus": "Normal",
            "AppearantPower": 0,
            "RatedCurrent": 0,
            "voltage": 227,
            "ActivePower": 0,
            "RealPower": 0,
            "PowerFactor": 1,
            "Energy": 0
        },
        {
            "Current": 0,
            "LoadSegmentId": 6,
            "BreakerStatus": "Normal",
            "AppearantPower": 0,
            "RatedCurrent": 0,
            "voltage": 230,
            "ActivePower": 0,
            "RealPower": 0,
            "PowerFactor": 1,
            "Energy": 0
        }
    ]
}
  • /PowerDistribution/"pduId"/PowerMeasurement/Loadsegment/"segmentId"/OutletMeasurement

Here we’re pulling measurements for each of the different outlets on the specified segment

{
    "@odata.context": "/redfish/v1/$metadata#PowerDistribution",
    "@odata.type": "#OutletMeasurement.1.0.0.OutletMeasurement",
    "@odata.id": "/redfish/v1/PowerDistribution/PowerMeasurement/loadsegment/OutletMeasurement/",
    "Description": "Mesurement details for the Outlet per loadsegment",
    "Name": "OutletMeasurement",
    "PduId": 1,
    "Outlet@odata.count": 4,
    "LoadsegmentNumber": 1,
    "Outlets": [
        {
            "AlarmStatus": "Normal",
            "OutletNumber": 1,
            "EnergyConsumedWattHour": 860869,
            "ConsumedCurrent": 0,
            "PowerFactor": 0,
            "OutputVoltage": 226,
            "LoadPercentage": 0,
            "PowerConsumedVoltageAmphere": 154920792,
            "OutletStatus": "ON",
            "PowerConsumedWatts": 147
        },
        {
            "AlarmStatus": "Normal",
            "OutletNumber": 2,
            "EnergyConsumedWattHour": 140982,
            "ConsumedCurrent": 0,
            "PowerFactor": 0,
            "OutputVoltage": 226,
            "LoadPercentage": 0,
            "PowerConsumedVoltageAmphere": 39179829,
            "OutletStatus": "ON",
            "PowerConsumedWatts": 18
        },
        {
            "AlarmStatus": "Normal",
            "OutletNumber": 3,
            "EnergyConsumedWattHour": 94229,
            "ConsumedCurrent": 0,
            "PowerFactor": 0,
            "OutputVoltage": 226,
            "LoadPercentage": 0,
            "PowerConsumedVoltageAmphere": 222622959,
            "OutletStatus": "ON",
            "PowerConsumedWatts": 218
        },
        {
            "AlarmStatus": "Normal",
            "OutletNumber": 4,
            "EnergyConsumedWattHour": 666750,
            "ConsumedCurrent": 0,
            "PowerFactor": 0,
            "OutputVoltage": 226,
            "LoadPercentage": 0,
            "PowerConsumedVoltageAmphere": 41444559,
            "OutletStatus": "ON",
            "PowerConsumedWatts": 3
        }
    ]
}
  • /PowerDistribution/"pduId"/PowerControl/Loadsegment/"segmentId"/OutletControl

List the config on the different Outlets on the specified segment

{
    "@odata.context": "/redfish/v1/$metadata#PowerDistribution",
    "@odata.type": "#OutletControl.1.0.0.OutletControl",
    "@odata.id": "/redfish/v1/PowerDistribution/PowerControl/Loadsegment/OutletControl",
    "Description": "Control the Outlet",
    "Name": "OutletControl",
    "PduId": 1,
    "Outlet@odata.count": 4,
    "LoadsegmentNumber": 1,
    "Outlets": [
        {
            "OutletNumber": 2,
            "StartupState": "on",
            "OutletName": "OUTLET 2",
            "OnDelay": 0,
            "OffDelay": 0,
            "RebootDelay": 5,
            "OutletStatus": "on"
        },
        {
            "OutletNumber": 3,
            "StartupState": "on",
            "OutletName": "OUTLET 3",
            "OnDelay": 0,
            "OffDelay": 0,
            "RebootDelay": 5,
            "OutletStatus": "on"
        },
        {
            "OutletNumber": 4,
            "StartupState": "on",
            "OutletName": "OUTLET 4",
            "OnDelay": 0,
            "OffDelay": 0,
            "RebootDelay": 5,
            "OutletStatus": "on"
        },
        {
            "OutletNumber": 5,
            "StartupState": "on",
            "OutletName": "OUTLET 5",
            "OnDelay": 0,
            "OffDelay": 0,
            "RebootDelay": 5,
            "OutletStatus": "on"
        }
    ]
}

As you can see there’s lots of stuff to pull from this API. The most interesting part will of course be the utilization.

As mentioned, based on the capabilities on your PDU you might not be able to pull all of this data, or you might have more info. If you have the switched version you should also be able to actually control the different outlets through the API, but this is something I haven’t been looking at.

Postman

To make it easier to explore the API I’ve created a Postman collection that can be imported. The collection includes the examples I’ve shown in this post.

There’s a few variables that needs to be set to correspond with your environment:

  • mgmtIp - Management IP address
  • pduId - The Id of the PDU you want to pull data from. Use the PowerDistributionList example to check the available IDs
  • segmentId - The Id of the LoadSegment you want to pull data from. Use the PowerDistributionUnit example to list the available segments.

You will also need to update the authentication credentials to match your environment.

To learn how you can work with Postman collections check out the Intro to collection in the Postman documentation

The Postman collection and more information about it can be found on Github.

Summary

Hopefully this post can help others out there struggling with getting started with the HPE PDU REST Api. Please reach out if you have any comments.