问题描述
[
{
"access": "Deny",...
...
"sourceAddressprefixes": [
"x.x.x.x","y.y.y.y"
],"sourceApplicationSecurityGroups": null,...
..
},]
我想从该列表中查询sourceAddressprefixes
和x.x.x.x
的{{1}}以及其他属性。
这些是我尝试过的:
-
y.y.y.y
这给了我列表的数量 -
[?direction=='Inbound'].[name,destinationAddressprefix,sourceAddressprefix,sourceAddressprefixes[*],priority]
这还是给我计数 -
[?direction=='Inbound'].[name,sourceAddressprefixes[0:],priority]
仍在计数 -
[?direction=='Inbound']. [name,sourceAddressprefixes[],priority]
可行,但只能得到一个值。 -
[?direction=='Inbound'].[name,sourceAddressprefixes[0],priority]
可行,但没有其他属性。
我在numpy.min中尝试过此方法,它仅与--query "[?direction=='Inbound'].sourceAddressprefixes[]" --out tsv
一起使用时效果很好,但即使在查询中使用引号,也无法在命令行中使用。
我正在Ubuntu 18.4上运行它
python-jmespath版本0.9.3
解决方法
您对Azure CLI命令有误解。我看到您想过滤NSG的入站规则并查看一些属性。如果要查看入站规则的所有属性:
az network nsg rule list -g groupName--nsg-name nsgName --query "[?direction=='Inbound']"
如果要查看入站规则的某些属性:
az network nsg rule list -g groupName--nsg-name nsgName --query "[?direction=='Inbound'].[name,destinationAddressPrefix,sourceAddressPrefix,sourceAddressPrefixes,priority]"
但是,为此,我建议您使用另一种格式:
az network nsg rule list -g charles --nsg-name azurevmNSG --query "[?direction=='Inbound'].{name:name,destinationAddressPrefix:destinationAddressPrefix,sourceAddressPrefix:sourceAddressPrefix,sourceAddressPrefixes:sourceAddressPrefixes,priority:priority}"
这种方式将向您显示属性的名称和值。如果添加参数-o table
,也许更方便阅读。