#! /usr/bin/ruby
#
# Sample External Node script for Puppet Dashboard
#
# == puppet.conf Configuration
#
#  [main]
#  external_nodes = /path/to/external_node
#  node_terminus = exec

require 'yaml'
require 'uri'
require 'net/http'

BASE="http://localhost:3000"
NODE = ARGV.first

url = URI.parse("#{BASE}/nodes/#{NODE}")
req = Net::HTTP::Get.new(url.path, 'Accept' => 'text/yaml')
res = Net::HTTP.start(url.host, url.port) {|http| http.request(req) }

case res
when Net::HTTPSuccess; puts res.body; exit 0
else; STDERR.puts "Error: #{res.code} #{res.message}"; exit 1
end
