微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

带有azure的azure jmespath查询列表

如何解决带有azure的azure jmespath查询列表

我在Azure nsg查询中有类似的内容

    [
      {
        "access": "Deny",...
        ...
        "sourceAddressprefixes": [
          "x.x.x.x","y.y.y.y"
        ],"sourceApplicationSecurityGroups": null,...
        ..
      },]

我想从该列表中查询sourceAddressprefixesx.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,也许更方便阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。