azure - 带有json的天蓝色jmespath查询列表
问题描述
我从 Azure nsg 查询中得到了类似的东西
[
{
"access": "Deny",
...
...
"sourceAddressPrefixes": [
"x.x.x.x",
"y.y.y.y"
],
"sourceApplicationSecurityGroups": null,
...
..
},
]
我想sourceAddressPrefixes
从该列表中查询x.x.x.x
和y.y.y.y
以及其他属性。
这些是我尝试过的:
[?direction=='Inbound'].[name,destinationAddressPrefix,sourceAddressPrefix,sourceAddressPrefixes[*],priority]
这给了我列表的计数[?direction=='Inbound'].[name,destinationAddressPrefix,sourceAddressPrefix,sourceAddressPrefixes[0:],priority]
这仍然给了我计数[?direction=='Inbound']. [name,destinationAddressPrefix,sourceAddressPrefix,sourceAddressPrefixes[],priority]
数数[?direction=='Inbound'].[name,destinationAddressPrefix,sourceAddressPrefix,sourceAddressPrefixes[0],priority]
这有效,但只能得到一个值。--query "[?direction=='Inbound'].sourceAddressPrefixes[]" --out tsv
这有效,但没有其他属性。
我在https://jmespath.org/tutorial.html中尝试了这个,它可以在 just中正常工作[?direction=='Inbound'].[access,sourceAddressPrefixes]
,但不能在命令行中正常工作,即使在查询周围有引号也是如此。
我在 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
。
推荐阅读
- java - Java spring boot - 检索动态输入
- python - TicTacToe 再次播放时如何重置棋盘?
- c - 向用户询问数据并将它们存储在 C 中的结构中
- flutter - Flutter Youtube 视频上传
- javascript - 科尔多瓦插件 ble-central 的问题
- java - Java Eclipse LocalDate 无法解析为类型?
- typo3 - v:page 不想显示自定义页面 TYPO3 9.5.19 VHS: 6.0.3
- c++ - 字符串比较
- python - 按周和产品分组,并对 Pandas 中的 ID 求和
- scala - 高效使用 Apache Spark 将数据推送到 elasticsearch