Redfish

BMC_IP=10.0.1.123
BMC_USER=ADMIN
BMC_PASS=ADMIN
 
# Install redfishtool (CLI)
git clone  https://github.com/DMTF/Redfishtool.git
cd Redfishtool/
python3 redfishtool.py -r ${BMC_IP} -u ${BMC_USER} -p ${BMC_PASS} Systems -F
 
for BMC_IP in 10.0.1.11 10.0.1.12 10.0.1.13; do
    python3 redfishtool.py -r ${BMC_IP} -u ${BMC_USER} -p ${BMC_PASS} Systems -F | jq .SerialNumber
    python3 redfishtool.py -r ${BMC_IP} -u ${BMC_USER} -p ${BMC_PASS} Systems -F | jq .IndicatorLED
done
 
BMC_HOSTS=$(grep 10.52 /var/lib/misc/dnsmasq.leases | cut -d" " -f3 | sort)
for BMC_HOST in ${BMC_HOSTS}; do
    echo ${BMC_HOST}
    curl --connect-timeout 1 -s https://${BMC_HOST}/redfish/v1/Systems/1/ -k -u ${BMC_USER}:${BMC_PASS} | jq -r .IndicatorLED
  echo
done
 
python3 redfishtool.py -r ${BMC_IP} -u ${BMC_USER} -p ${BMC_PASS} Chassis list
python3 redfishtool.py -r ${BMC_IP} -u ${BMC_USER} -p ${BMC_PASS} Chassis -I 1
python3 redfishtool.py -r ${BMC_IP} -u ${BMC_USER} -p ${BMC_PASS} Chassis -I HA-RAID.0.StorageEnclosure.0
 
python3 redfishtool.py -r ${BMC_IP} -u ${BMC_USER} -p ${BMC_PASS} Systems -F | jq .UUID
python3 redfishtool.py -r ${BMC_IP} -u ${BMC_USER} -p ${BMC_PASS} Systems -F | jq .IndicatorLED
 
python3 redfishtool.py -r ${BMC_IP} -u ${BMC_USER} -p ${BMC_PASS} Chassis -I 1 setIndicatorLed Off
 
BMC_IP=$(dig +short node1.example.com)
unset https_proxy 
 
# gret firmware versions
# BMC
python3 redfishtool.py -r ${BMC_HOST} -u ${BMC_USER} -p ${BMC_PASS} Managers -F | jq .FirmwareVersion
curl -s https://${BMC_IP}/redfish/v1/Managers/1/ -k -u ${BMC_USER}:${BMC_PASS} | jq .FirmwareVersion
# BIOS
python3 redfishtool.py -r ${BMC_HOST} -u ${BMC_USER} -p ${BMC_PASS} Systems -F | jq .BiosVersion
curl -s https://${BMC_IP}/redfish/v1/Systems/1/ -k -u ${BMC_USER}:${BMC_PASS} | jq .BiosVersion
 
# System manufactor
curl -s https://${BMC_IP}/redfish/v1/Systems/1/ -k -u ${BMC_USER}:${BMC_PASS} | jq .Manufacturer
# System model
curl -s https://${BMC_IP}/redfish/v1/Systems/1/ -k -u ${BMC_USER}:${BMC_PASS} | jq .PartNumber
 
# get serial
curl -s https://${BMC_IP}/redfish/v1/Systems/1 -k -u ${BMC_USER}:${BMC_PASS} | jq .UUID
curl -s https://${BMC_IP}/redfish/v1/Systems/1 -k -u ${BMC_USER}:${BMC_PASS} | jq .SerialNumber
curl -s https://${BMC_IP}/redfish/v1/Chassis/1 -k -u ${BMC_USER}:${BMC_PASS} | jq .SerialNumber
 
# get CPU information
curl -s https://${BMC_IP}/redfish/v1/Systems/1/Processors/1/ -k -u ${BMC_USER}:${BMC_PASS} | jq -r .Model | awk '{$1=$1};1'
curl -s https://${BMC_IP}/redfish/v1/Systems/1/Processors/1 -k -u ${BMC_USER}:${BMC_PASS} | jq .TotalCores
curl -s https://${BMC_IP}/redfish/v1/Systems/1/ -k -u ${BMC_USER}:${BMC_PASS} | jq .ProcessorSummary.Count
 
# ram
curl -s https://${BMC_IP}/redfish/v1/Systems/1/ -k -u ${BMC_USER}:${BMC_PASS} | jq .MemorySummary.TotalSystemMemoryGiB
curl -k -u ${BMC_USER}:${BMC_PASS} -s https://${BMC_IP}/redfish/v1/Systems/1/Memory | jq ".Members | length"
 
# get BMC settings
curl -s https://${BMC_IP}/redfish/v1/Managers/1/EthernetInterfaces/2  -k -u ${BMC_USER}:${BMC_PASS} | jq .IPv4Addresses[0].Address
 
# get Health
curl -s https://${BMC_IP}/redfish/v1/Chassis/1 -k -u ${BMC_USER}:${BMC_PASS} | jq .Status.Health
# get IndicatorLED
curl -s https://${BMC_IP}/redfish/v1/Systems/1/ -k -u ${BMC_USER}:${BMC_PASS} | jq -r .IndicatorLED
# fan mode
curl -s https://${BMC_IP}//redfish/v1/Managers/1/FanMode -k -u ${BMC_USER}:${BMC_PASS} | jq .Mode
 
# temperature
curl -s https://${BMC_IP}/redfish/v1/Chassis/1/Thermal -k -u ${BMC_USER}:${BMC_PASS} | jq '.Temperatures[] | select(.Name == "System Temp") .ReadingCelsius'
 
# GPU
curl -s https://${BMC_NODE}/redfish/v1/Chassis/1/PCIeDevices/GPU1/ -k -u ${BMC_USER}:${BMC_PASS} | jq -r .Model
 
# storage
curl -s https://${BMC_IP}/redfish/v1/Systems/1/SimpleStorage/1 -k -u ${BMC_USER}:${BMC_PASS} | jq .Devices[].Model
 
# raid
curl -s https://${BMC_IP}/redfish/v1/Chassis/HA-RAID.0.StorageEnclosure.0 -k -u ${BMC_USER}:${BMC_PASS} | python -m json.tool
curl -s https://${BMC_IP}/redfish/v1/Chassis/HA-RAID.0.StorageEnclosure.0/Drives/Disk.Bay.0 -k -u ${BMC_USER}:${BMC_PASS} | python -m json.tool
 
curl -k https://BMC_IP/registries/BiosAttributeRegistry.v1_0_0.json | python -m json.tool
 
curl -s https://BMC_IP/redfish/v1/Chassis/1/Thermal -k -u ADMIN:ADMIN |   python -m json.tool
 
# power control
curl -s https://${BMC_IP}/redfish/v1/Chassis/1/Power/ -k -u ${BMC_USER}:${BMC_PASS} | jq -r ".PowerControl[].Status.State"
 
# power consumption
curl -s https://${BMC_IP}/redfish/v1/Chassis/1/Power/ -k -u ${BMC_USER}:${BMC_PASS} | jq .PowerControl[].PowerConsumedWatts
curl -s https://${BMC_IP}/redfish/v1/Chassis/1/Power/ -k -u ${BMC_USER}:${BMC_PASS} | jq .PowerControl[].PowerMetrics.AverageConsumedWatts

Get NIC information

# get BMC mac
curl -s https://${BMC_IP}/redfish/v1/Managers/1/EthernetInterfaces/1 -k -u ${BMC_USER}:${BMC_PASS} | jq -r '.MACAddress | ascii_downcase'
 
# get NIC1 mac
for NIC_ID in {1..4}; do
  curl -s https://${BMC_IP}/redfish/v1/Systems/1/EthernetInterfaces/${NIC_ID} -k -u ${BMC_USER}:${BMC_PASS} | jq -r '.MACAddress | ascii_downcase'
done
# SuperMicro
https://www.supermicro.com/manuals/other/RedfishRefGuide.pdf
https://www.supermicro.com/manuals/other/redfish-ref-guide-html/Content/general-content/available-apis.htm
 
# HP
https://hewlettpackard.github.io/ilo-rest-api-docs/ilo5/#uefi-bios-standard-redfish-support
https://support.hpe.com/hpsc/doc/public/display?docId=c04423967
 
# Redfishtool (redfish CLI)
https://github.com/DMTF/Redfishtool
 
# boot to bios
python3 redfishtool.py -r ${BMC_IP} -u ${BMC_USER} -p ${BMC_PASS} Systems setBootOverride Once BiosSetup
python3 redfishtool.py -r ${BMC_IP} -u ${BMC_USER} -p ${BMC_PASS} Systems reset ForceRestart

Manage Redfish with Curl

curl -d '{
    "Boot": {
        "BootSourceOverrideEnabled": "Once",
        "BootSourceOverrideTarget": "Pxe"
    }
}' \
-H "Content-Type: application/json" \
-X PATCH \
--insecure \
--silent \
https://${BMC_HOST}}/redfish/v1/Systems/1/
 
curl -sk -H "$token" -H "Content-Type: application/json" -X POST https://$1/redfish/v1/Systems/1/Actions/ComputerSystem.Reset/ -d '{"ResetType": "ForceRestart"}'
curl -sk -H "$token" -H "Content-Type: application/json" -X POST https://$1/redfish/v1/Systems/1/Actions/ComputerSystem.Reset/ -d '{"ResetType": "ForceOff"}'
curl -sk -H "$token" -H "Content-Type: application/json" -X POST https://$1/redfish/v1/Systems/1/Actions/ComputerSystem.Reset/ -d '{"ResetType": "On"}'

Get server data

for BMC_IP in $(cat /var/lib/misc/dnsmasq.leases | grep 10.0.98 | cut -d" " -f3); do
    echo ${BMC_IP}
    curl -s https://${BMC_IP}/redfish/v1/Systems/1/ -k -u ${BMC_USER}:${BMC_PASS} | jq -r .Manufacturer
    curl -s https://${BMC_IP}/redfish/v1/Systems/1/ -k -u ${BMC_USER}:${BMC_PASS} | jq -r .PartNumber
    curl -s https://${BMC_IP}/redfish/v1/Systems/1/ -k -u ${BMC_USER}:${BMC_PASS} | jq -r .IndicatorLED
    curl -s https://${BMC_IP}/redfish/v1/Systems/1/ -k -u ${BMC_USER}:${BMC_PASS} | jq .BiosVersion
    curl -s https://${BMC_IP}/redfish/v1/Managers/1/ -k -u ${BMC_USER}:${BMC_PASS} | jq .FirmwareVersion
    echo
done

VirtualMedia / ISO

# mount ISO image
curl https://${BMC_HOST}/redfish/v1/Managers/1/VirtualMedia/CD1/Actions/VirtualMedia.InsertMedia \
  -u ${BMC_USER}:${BMC_PASS} \
  --insecure \
  --silent \
  -X POST \
  -H "Content-Type: application/json" \
  -d "{ 
        \"Image\": \"http://${DL_SRV_IP}/iso/${ISO}\"
    }"
 
# get VirtualMedia state
curl -k -u ${BMC_USER}:${BMC_PASS} -s https://${BMC_IP}/redfish/v1/Managers/1/VirtualMedia/CD1 | jq
 
# boot from ISO (use "UsbCd" on Supermicro else "Cd")
    curl https://${BMC_HOST}/redfish/v1/Systems/1/ \
      -u ${BMC_USER}:${BMC_PASS} \
      --insecure \
      --silent \
      -X PATCH \
      -H "Content-Type: application/json" \
      -d '{
            "Boot":{
                "BootSourceOverrideEnabled":"Once",
                "BootSourceOverrideMode":"UEFI",
                "BootSourceOverrideTarget": "UsbCd"
            }
        }'
 
# boot from HDD
curl https://${BMC_HOST}/redfish/v1/Systems/1/ \
  -u ${BMC_USER}:${BMC_PASS} \
  --insecure \
  --silent \
  -X PATCH \
  -H "Content-Type: application/json" \
  -d '{
        "Boot":{
          "BootSourceOverrideEnabled":"Continuous",
          "BootSourceOverrideMode":"UEFI",
           "BootSourceOverrideTarget": "Hdd"
         }
      }'
 
# get boot state
curl --silent -k --user ${BMC_USER}:${BMC_PASS} https://${BMC_HOST}/redfish/v1/Systems/1/ | jq '.Boot'
 
# reboot server
curl https://${BMC_HOST}/redfish/v1/Systems/1/Actions/ComputerSystem.Reset \
    -u ${BMC_USER}:${BMC_PASS} \
    --insecure \
    --silent \
    -H "Content-Type: application/json" \
    -X POST \
    -d '{ 
            "ResetType": "GracefulRestart"
        }'

Links
https://www.thomas-krenn.com/de/wiki/Redfish