使用Inspec迭代JSON,仅针对特定条目进行测试
要测试我的服务器上是否安装了正确的领事版本,我正在尝试编写Inspec测试。这个想法是用Mutiple IP地址调用此测试,将其针对JSON(我从领事API中获得)对其进行解析,然后仅查看领事版本的服务器,以获取我列出的IPS的服务器。
现在,我正在努力迭代JSON,然后只检查正确的服务器。
它看起来应该像这样:
describe json(content: http('http://172.17.0.1:8500/v1/agent/members').body) do
for i in 0..2 do
ip_addresses.each { |node| its ([i, 'Tags', 'build']) { should match consul_version }.where(['Addr'] == node) }
end
当然不起作用,但是我认为这解释了我要实现的目标。
是否有一种可以让我这样做的方法?
编辑: JSON归结为:
[
{
"Addr": "192.100.100.100”,
"Name": “machine0”,
"Tags": {
"build": "1.11.3",
}
},
{
"Addr": "192.100.100.101”,
"Name": “machine1",
"Tags": {
"build": "1.11.3”,
}
},
{
"Addr": "192.100.100.102”,
"Name": “machine2”,
"Tags": {
"build": "1.11.3",
}
}
]
To test if the correct consul version is installed on my servers, I am trying to write an inspec test. The idea is to call this test with mutiple ip addresses, parse it against json (which I get from the consul api) and then check the consul version for only the servers that I have the IPs listed for.
Now I am struggling with iterating over the json and then only checking the correct servers.
It should look something like this:
describe json(content: http('http://172.17.0.1:8500/v1/agent/members').body) do
for i in 0..2 do
ip_addresses.each { |node| its ([i, 'Tags', 'build']) { should match consul_version }.where(['Addr'] == node) }
end
It doesn't work of course, but I think it explains what I am trying to achieve.
Is there an approach that would allow me to do this?
Edit:
The json boils down to this:
[
{
"Addr": "192.100.100.100”,
"Name": “machine0”,
"Tags": {
"build": "1.11.3",
}
},
{
"Addr": "192.100.100.101”,
"Name": “machine1",
"Tags": {
"build": "1.11.3”,
}
},
{
"Addr": "192.100.100.102”,
"Name": “machine2”,
"Tags": {
"build": "1.11.3",
}
}
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论