User Tools

Site Tools


aix:hmc_rest_api

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
aix:hmc_rest_api [2023/07/05 10:46]
manu
aix:hmc_rest_api [2025/10/22 17:23] (current)
manu
Line 6: Line 6:
  
 https://<​hmcIP>:​12443/​rest/​api/​uom/​ManagedSystem https://<​hmcIP>:​12443/​rest/​api/​uom/​ManagedSystem
 +
 +https://​aix4admins.blogspot.com/​2018/​08/​api-hmc.html
 +
 +https://​ftpmirror.your.org/​pub/​misc/​ftp.software.ibm.com/​systems/​power/​docs/​hw/​p9/​p9ehl.pdf
 +
 +==== Initiate a new RestAPI session ====
 +
 +Create a file **login.xml**
 +<​code>​
 +<?xml version="​1.0"​ encoding="​UTF-8"​ standalone="​yes"?>​
 +<​LogonRequest xmlns="​http://​www.ibm.com/​xmlns/​systems/​power/​firmware/​web/​mc/​2012_10/"​ schemaVersion="​V1_0">​
 +  <​UserID>​hscroot</​UserID>​
 +  <​Password>​abc123</​Password>​
 +</​LogonRequest>​
 +</​code>​
 +
 +First login to create a cokies.txt file
 +<cli prompt='#'>​
 +HMC=hmcp9
 +
 +curl -k -c cookies.txt -i -X PUT -H "​Content-Type:​ application/​vnd.ibm.powervm.web+xml;​ type=LogonRequest"​ -H "​Accept:​ application/​vnd.ibm.powervm.web+xml;​ type=LogonResponse"​ -H "​X-Audit-Memento:​ hmc_test"​ -d @login.xml https://​$HMC:​12443/​rest/​api/​web/​Logon
 +</​cli>​
 +
 +==== Kill the RestAPI session ====
 +
 +First login to create a cokies.txt file
 +<cli prompt='#'>​
 +HMC=hmcp9
 +
 +curl -k -c cookies.txt -b cookies.txt -X "​DELETE"​ https://​$HMC:​12443/​rest/​api/​web/​Logon
 +</​cli>​
 +
 +==== List partitions ====
 +
 +<cli prompt='#'>​
 +# curl -k -c cookies.txt -b cookies.txt -H "​Accept:​ application/​atom+xml;​ charset=UTF-8"​ https://​$HMC:​12443/​rest/​api/​uom/​LogicalPartition
 +</​cli>​
 +
 +==== List Managed system / Power Servers ====
 +
 +<cli prompt='#'>​
 +# curl -k -c cookies.txt -b cookies.txt -H "​Accept:​ application/​atom+xml;​ charset=UTF-8"​ https://​$HMC:​12443/​rest/​api/​uom/​ManagedSystem
 +</​cli>​
 +
 +<​code>​
 +</​code>​
 +
 +==== Get temperature on the Power servers ====
 +
 +Get Power9 system ID:
 +<cli prompt='#'>​
 +[root@lnx01 ~]# curl -k -c cookies.txt -b cookies.txt -H "​Accept:​ application/​atom+xml;​ charset=UTF-8"​ https://​$HMC:​12443/​rest/​api/​uom/​ManagedSystem > toto
 +
 +[root@lnx01 ~]# cat toto | egrep '<​id>​|SystemName'​
 +    <​id>​38xxxxxx-140b-30f2-8544-7xxxxxxxx4b3</​id>​
 +        <​id>​f0xxxxxx-c7c9-38f3-8f99-6xxxxxxxx58a</​id>​
 +    <​SystemName kb="​CUR"​ kxe="​false">​p9-SiteA</​SystemName>​
 +        <​id>​3exxxxxx-7ac6-325d-9f15-3xxxxxxxxdd3</​id>​
 +    <​SystemName kb="​CUR"​ kxe="​false">​p9-SiteB</​SystemName>​
 +</​cli>​
 +
 +Use now the ID of both P9 to get the list of json files
 +<cli prompt='#'>​
 +# curl -k -c cookies.txt -b cookies.txt -H "​Accept:​ application/​atom+xml;​ charset=UTF-8"​ https://​hmcp9:​12443/​rest/​api/​pcm/​ManagedSystem/​f0xxxxxx-c7c9-38f3-8f99-6xxxxxxxx58a/​RawMetrics/​EnergyMonitor/ ​          
 +</​cli>​
 +<​code>​
 +<feed xmlns="​http://​www.w3.org/​2005/​Atom"​ xmlns:​ns2="​http://​a9.com/​-/​spec/​opensearch/​1.1/"​ xmlns:​ns3="​http://​www.w3.org/​1999/​xhtml">​
 +    <​id>​f0xxxxxx-c7c9-38f3-8f99-6de73b35758a</​id>​
 +    <​updated>​2025-10-22T16:​38:​30.000+02:​00</​updated>​
 +    <title type="​text">​EnergyMonitorMetrics</​title>​
 +    <​subtitle type="​text">​ManagedSystem f0xxxxxx-c7c9-38f3-8f99-6de73b35758a</​subtitle>​
 +    <link rel="​self"​ href="​https://​hmcp9:​12443/​rest/​api/​pcm/​ManagedSystem/​f0xxxxxx-c7c9-38f3-8f99-6xxxxxxxx58a/​RawMetrics/​EnergyMonitor/"/>​
 +    <​generator uri="​IBM Power Systems Management Console"​ version="​1"/>​
 +    <​entry>​
 +        <​id>​8bdaf564-ad40-4c3a-be9b-3d5f506ebd7b</​id>​
 +        <​updated>​2025-10-22T15:​46:​00.000+02:​00</​updated>​
 +        <title type="​text">​LTM_9009-22A*78xxxx0_fsp_20251022T154600+0200.json</​title>​
 +        <​published>​2025-10-22T15:​46:​00.000+02:​00</​published>​
 +        <link type="​application/​vnd.ibm.powervm.pcm.json"​ href="​https://​hmcp9:​12443/​rest/​api/​pcm/​ManagedSystem/​f0xxxxxx-c7c9-38f3-8f99-6xxxxxxxx58a/​RawMetrics/​EnergyMonitor/​LTM_9009-22A*78xxxx0_fsp_20251022T154600+0200.json"/>​
 +        <​author>​
 +            <​name>​IBM Power Systems Management Console</​name>​
 +        </​author>​
 +        <​category term="​fsp"/>​
 +    </​entry>​
 +    <​entry>​
 +        <​id>​11ba3435-47a5-406e-b315-5979210a9b4b</​id>​
 +        <​updated>​2025-10-22T15:​46:​30.000+02:​00</​updated>​
 +        <title type="​text">​LTM_9009-22A*78xxxx0_fsp_20251022T154630+0200.json</​title>​
 +        <​published>​2025-10-22T15:​46:​30.000+02:​00</​published>​
 +        <link type="​application/​vnd.ibm.powervm.pcm.json"​ href="​https://​hmcp9:​12443/​rest/​api/​pcm/​ManagedSystem/​f0xxxxxx-c7c9-38f3-8f99-6xxxxxxxx58a/​RawMetrics/​EnergyMonitor/​LTM_9009-22A*78xxxx0_fsp_20251022T154630+0200.json"/>​
 +        <​author>​
 +            <​name>​IBM Power Systems Management Console</​name>​
 +        </​author>​
 +        <​category term="​fsp"/>​
 +    </​entry>​
 +....
 +</​code>​
 +
 +Get one json file (you need to accept JSON), and read it using **jq** JSON parser
 +<cli prompt='#'>​
 +# curl -k -c cookies.txt -b cookies.txt -X GET -H "​Accept:​ application/​json" ​ https://​hmcp9:​12443/​rest/​api/​pcm/​ManagedSystem/​f0xxxxxx-c7c9-38f3-8f99-6xxxxxxxx58a/​RawMetrics/​EnergyMonitor/​LTM_9009-22A*78xxxx0_fsp_20251022T154630+0200.json | jq .
 +</​cli>​
 +<​code>​
 +  % Total    % Received % Xferd  Average Speed   ​Time ​   Time     ​Time ​ Current
 +                                 ​Dload ​ Upload ​  ​Total ​  ​Spent ​   Left  Speed
 +100  1306    0  1306    0     ​0 ​ 39575      0 --:--:-- --:--:-- --:--:-- 39575
 +{
 +  "​timeStamp":​ "​2025-10-22T15:​46:​30+0200",​
 +  "​status":​ 0,
 +  "​errorInfo":​ [],
 +  "​utilInfo":​ {
 +    "​version":​ "​1.0.0",​
 +    "​metricType":​ "​Raw",​
 +    "​monitoringType":​ "​LTM",​
 +    "​mtms":​ "​9009-22A*78xxxx0",​
 +    "​name":​ "​p9-SiteB"​
 +  },
 +  "​powerEnergyReading":​ {
 +    "​currentPowerReading":​ 700,
 +    "​minimumPowerReading":​ 700,
 +    "​maximumPowerReading":​ 700,
 +    "​averagePowerReading":​ 700,
 +    "​ipmiTimeStamp":​ "Wed Oct 22 15:52:09 2025",
 +    "​reportingPeriod":​ 30,
 +    "​powerReadingState":​ "​activated"​
 +  },
 +  "​thermalEnergyReading":​ {
 +    "​inletTemperatures":​ [
 +      {
 +        "​entityId":​ "Inlet air temperature(40h)",​
 +        "​entityInstance":​ "​1",​
 +        "​temperatureData":​ 27
 +      }
 +    ],
 +    "​cpuTemperatures":​ [
 +      {
 +        "​entityId":​ "CPU temperature sensors(41h)",​
 +        "​entityInstance":​ "​1",​
 +        "​temperatureData":​ 60
 +      },
 +      {
 +        "​entityId":​ "CPU temperature sensors(41h)",​
 +        "​entityInstance":​ "​2",​
 +        "​temperatureData":​ 68
 +      }
 +    ],
 +    "​baseboardTemperatures":​ [
 +      {
 +        "​entityId":​ "​Baseboard temperature sensors(42h)",​
 +        "​entityInstance":​ "​1",​
 +        "​temperatureData":​ 47
 +      },
 +      {
 +        "​entityId":​ "​Baseboard temperature sensors(42h)",​
 +        "​entityInstance":​ "​2",​
 +        "​temperatureData":​ 46
 +      },
 +      {
 +        "​entityId":​ "​Baseboard temperature sensors(42h)",​
 +        "​entityInstance":​ "​3",​
 +        "​temperatureData":​ 45
 +      },
 +      {
 +        "​entityId":​ "​Baseboard temperature sensors(42h)",​
 +        "​entityInstance":​ "​4",​
 +        "​temperatureData":​ 48
 +      },
 +      {
 +        "​entityId":​ "​Baseboard temperature sensors(42h)",​
 +        "​entityInstance":​ "​5",​
 +        "​temperatureData":​ 49
 +      },
 +      {
 +        "​entityId":​ "​Baseboard temperature sensors(42h)",​
 +        "​entityInstance":​ "​6",​
 +        "​temperatureData":​ 48
 +      }
 +    ]
 +  }
 +}
 +</​code>​
  
 ====== SNMP ====== ====== SNMP ======
aix/hmc_rest_api.txt ยท Last modified: 2025/10/22 17:23 by manu