limnh / journey

Notes and learnings along the way of becoming an engineer
0 stars 1 forks source link

2019-04-08 #29

Open limnh opened 5 years ago

limnh commented 5 years ago

Attempting to parse the json output from nomad alloc status. can get DesiredState with open('alloc-json.json') { |f| f.grep(/DesiredStatus/) } but have not figured out how to add ID

limnh commented 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

limnh commented 5 years ago

may have to just do a secondary grep command like open('alloc-json.json') { |f| f.grep(/ID/) }

limnh commented 5 years ago

Daily To-Do List:

Questions/Issues:

Solutions:

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