查了一下怎麼拿json格式的裡面的特定資料
詳細請參考Ref
e.g.:資料長這樣子:
[
{
...略
"Attributes": {
"ACPI002": true,
...略
},
...略
}
]
curl -k -u admin:admin https://169.254.0.17/redfish/v1/Systems/Self/Bios | jq -s '.Attributes' 這樣查詢會錯誤:
因為{}外層有[],所以一開始要填.[],而不是.Attributes
curl -k -u admin:admin https://169.254.0.17/redfish/v1/Systems/Self/Bios | jq -s '.[]'
只需要"Attributes"的資料
curl -k -u admin:admin https://169.254.0.17/redfish/v1/Systems/Self/Bios | jq -s '.[].Attributes'
只需要"Attributes": {...略}底下的特定資料 example: MEMS00F, PMS001, PMS007, PRSS011, MDFX001, IPMINM1, PRSS01C, TER06B, IPMI000
curl -k -u admin:admin https://169.254.0.17/redfish/v1/Systems/Self/Bios | jq -s '.[].Attributes | {MEMS00F, PMS001, PMS007, PRSS011, MDFX001, IPMINM1, PRSS01C, TER06B, IPMI000}'
實際範例:透過usb over (BMC)LAN,使用Redfish功能,修改BIOS設定值,改完後重開機,回到OS底下檢查BIOS數值是否生效:
GET URI: /redfish/v1/Systems/Self/Bios 底下的資料
[root@localhost ~]# curl -X GET -k -u admin:admin https://169.254.0.17/redfish/v1/Systems/Self/Bios | jq -s
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 8019 100 8019 0 0 6889 0 0:00:01 0:00:01 --:--:-- 6883
[
{
"@Redfish.Settings": {
"@odata.type": "#Settings.v1_2_1.Settings",
"SettingsObject": {
"@odata.id": "/redfish/v1/Systems/Self/Bios/SD"
}
},
"@odata.context": "/redfish/v1/$metadata#Bios.Bios",
"@odata.etag": "\"1682586632\"",
"@odata.id": "/redfish/v1/Systems/Self/Bios",
"@odata.type": "#Bios.v1_0_6.Bios",
"Actions": {
"#Bios.ChangePassword": {
"@Redfish.ActionInfo": "/redfish/v1/Systems/Self/Bios/ChangePasswordActionInfo",
"target": "/redfish/v1/Systems/Self/Bios/Actions/Bios.ChangePassword"
},
"#Bios.ResetBios": {
"@Redfish.ActionInfo": "/redfish/v1/Systems/Self/Bios/ResetBiosActionInfo",
"target": "/redfish/v1/Systems/Self/Bios/Actions/Bios.ResetBios"
}
},
"AttributeRegistry": "BiosAttributeRegistry_a1006o.1.26.0",
"Attributes": {
"ACPI002": true,
"ACPI004": false,
"DumpSetupData": "Diff Only",
"ECS_TH": 0,
"EMCA_LS": "Enable",
"ElcCsv": true,
"ElcDebugMode": "Enabled",
"JSFP2": "Disabled",
"JUSBFP2": "Enabled",
"JUSBRP": "Enabled",
"LBHI": 41,
"LBHR": 0,
"LBLO": 40,
"LBMIN": 7,
"LBTW": "Enabled",
"LOMEN": "Enabled",
...略
"MDFX001": "BIOS Setup",
"NVLCK002": "Enable",
...略
"TER0A8": "COM0 (Serial Over Lan)",
"USBDebug": false,
"VMDJ001": "Disabled",
...略
"VMDJ004": "Disabled"
},
"Description": "Current BIOS Settings",
"Id": "Bios",
"Name": "Current BIOS Settings"
}
]
譬如,用PATCH改了一些值
[root@localhost ~]# curl -X PATCH -k -u admin:admin https://169.254.0.17/redfish/v1/Systems/Self/Bios/SD -H "If-Match: *" -H "Content-Type: application/json" -d '{"Attributes": {"MEMS00F": "Disabled","PMS001": "Disable","PMS007": "Auto","PRSS011": "Disable","MDFX001": "BIOS Setup","IPMINM1": "Disabled","PRSS01C": "Enable","TER06B": "COM0 (Serial Over Lan)","IPMI000": "Disabled"}}'
[root@localhost ~]#
[root@localhost ~]# curl -k -u admin:admin https://169.254.0.17/redfish/v1/Systems/Self/Bios/SD
{"@odata.context":"/redfish/v1/$metadata#Bios.Bios","@odata.etag":"\"1682585929\"","@odata.id":"/redfish/v1/Systems/Self/Bios/SD","@odata.type":"#Bios.v1_0_6.Bios","Attributes":{"IPMI000":"Disabled","IPMINM1":"Disabled","MDFX001":"BIOS Setup","MEMS00F":"Disabled","PMS001":"Disable","PMS007":"Auto","PRSS011":"Disable","PRSS01C":"Enable","TER06B":"COM0 (Serial Over Lan)"},"Description":"Future BIOS Settings","Id":"SD","Name":"Future BIOS Settings"}[root@localhost ~]#
[root@localhost ~]#
確認設定進去的值
[root@localhost ~]# curl -k -u admin:admin https://169.254.0.17/redfish/v1/Systems/Self/Bios/SD | jq -s
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 450 100 450 0 0 223 0 0:00:02 0:00:02 --:--:-- 223
[
{
"@odata.context": "/redfish/v1/$metadata#Bios.Bios",
"@odata.etag": "\"1682585929\"",
"@odata.id": "/redfish/v1/Systems/Self/Bios/SD",
"@odata.type": "#Bios.v1_0_6.Bios",
"Attributes": {
"IPMI000": "Disabled",
"IPMINM1": "Disabled",
"MDFX001": "BIOS Setup",
"MEMS00F": "Disabled",
"PMS001": "Disable",
"PMS007": "Auto",
"PRSS011": "Disable",
"PRSS01C": "Enable",
"TER06B": "COM0 (Serial Over Lan)"
},
"Description": "Future BIOS Settings",
"Id": "SD",
"Name": "Future BIOS Settings"
}
]
[root@localhost ~]#
AMI有bmc usb over lan的BUG,所以檢查兩次確認是不是有問題
[root@localhost ~]# curl -k -u admin:admin https://169.254.0.17/redfish/v1/Systems/Self/Bios/SD | jq -s
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 450 100 450 0 0 223 0 0:00:02 0:00:02 --:--:-- 223
[
{
"@odata.context": "/redfish/v1/$metadata#Bios.Bios",
"@odata.etag": "\"1682585929\"",
"@odata.id": "/redfish/v1/Systems/Self/Bios/SD",
"@odata.type": "#Bios.v1_0_6.Bios",
"Attributes": {
"IPMI000": "Disabled",
"IPMINM1": "Disabled",
"MDFX001": "BIOS Setup",
"MEMS00F": "Disabled",
"PMS001": "Disable",
"PMS007": "Auto",
"PRSS011": "Disable",
"PRSS01C": "Enable",
"TER06B": "COM0 (Serial Over Lan)"
},
"Description": "Future BIOS Settings",
"Id": "SD",
"Name": "Future BIOS Settings"
}
]
[root@localhost ~]#
系統重開後,檢查值
[root@localhost ~]# curl -k -u admin:admin https://169.254.0.17/redfish/v1/Systems/Self/Bios | jq -s '.[].Attributes | {MEMS00F, PMS001, PMS007, PRSS011, MDFX001, IPMINM1, PRSS01C, TER06B, IPMI000}'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 8019 100 8019 0 0 9238 0 --:--:-- --:--:-- --:--:-- 9238
{
"MEMS00F": "Disabled",
"PMS001": "Disable",
"PMS007": "Auto",
"PRSS011": "Disable",
"MDFX001": "BIOS Setup",
"IPMINM1": "Disabled",
"PRSS01C": "Enable",
"TER06B": "COM0 (Serial Over Lan)",
"IPMI000": "Disabled"
}
方便辨識把原先PATCH的內容貼出來看比對
[root@localhost ~]# echo '{"Attributes": {"MEMS00F": "Disabled","PMS001": "Disable","PMS007": "Auto","PRSS011": "Disable","MDFX001": "BIOS Setup","IPMINM1": "Disabled","PRSS01C": "Enable","TER06B": "COM0 (Serial Over Lan)","IPMI000": "Disabled"}}' | jq -s
[
{
"Attributes": {
"MEMS00F": "Disabled",
"PMS001": "Disable",
"PMS007": "Auto",
"PRSS011": "Disable",
"MDFX001": "BIOS Setup",
"IPMINM1": "Disabled",
"PRSS01C": "Enable",
"TER06B": "COM0 (Serial Over Lan)",
"IPMI000": "Disabled"
}
}
]
[root@localhost ~]#
Ref:
https://medium.com/evan-fang/jq-%E5%91%BD%E4%BB%A4%E5%88%97json%E8%99%95%E7%90%86%E5%B7%A5%E5%85%B7-a553c8940ef5
https://myapollo.com.tw/blog/jq-by-example/
https://myapollo.com.tw/blog/jq-useful-tips/
https://mozillazg.com/2018/01/jq-use-examples-cookbook.html#hidvalue
https://blog.techbridge.cc/2019/02/01/linux-curl-command-tutorial/
https://ithelp.ithome.com.tw/articles/10130071