Skip to content

Instantly share code, notes, and snippets.

@arnobroekhof
Last active December 23, 2015 22:59
Show Gist options
  • Select an option

  • Save arnobroekhof/6707350 to your computer and use it in GitHub Desktop.

Select an option

Save arnobroekhof/6707350 to your computer and use it in GitHub Desktop.
simple rest api for printing all facts from facter in json format.
#!/usr/bin/env ruby
require 'facter'
require 'json'
require 'sinatra'
ipaddress="172.16.132.2"
# sinatra specific settings
set :sessions, false
set :logging, false
set :dump_errors, false
set :some_custom_option, false
# Print everything if they didn't ask for specific facts.
facts ||= Facter.to_hash
error 403 do
"Access forbidden"
end
get '/api/facts', :provides => 'json' do
if request.ip == ipaddress
content_type :json
JSON.dump(facts)
else
403
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment