Open limnh opened 5 years ago
Have set an ENV VAR for $NOMAD_ADDR
to run and create file from the nomad alloc status
. command here: curl \ $NOMAD_ADDR/v1/allocations | jq '.' > alloc-json.json
may have to just do a secondary grep command like open('alloc-json.json') { |f| f.grep(/ID/) }
include?
each_line
& select
alloc-json.txt.each_line.select do |line| (line.include?("run") && str.include?("pending")) || (line.include?("stop") && str.include?("running")) end
curl \ https://localhost:4646/v1/allocations from these Nomad docs
$NOMAD_ADDR
that can be used in this curl command.require 'uri'
require 'json'
uri = URI.parse("http://#{ENV['NOMAD_ADDR']}/v1/allocations")
response = Net::HTTP.get(uri)
allocs = []
body = JSON.parse(response)
body.each do |alloc|
allocs << {
"DesiredStatus" => alloc["DesiredStatus"],
"ID" => alloc["ID"],
"ClientStatus" => alloc["ClientStatus"]
}
end
puts allocs
allocs
is creating a new empty array for the hashesbody
is an object(array) that the command will iterate over
.each
is the module that goes over each object within the array<<
Append—Pushes the given object on to the end of this array.
Attempting to parse the json output from
nomad alloc status
. can getDesiredState
withopen('alloc-json.json') { |f| f.grep(/DesiredStatus/) }
but have not figured out how to addID