#!/usr/bin/env ruby require "sinatra" require "zipf" require "./up" configure do hosts = {} ReadFile.new("./hosts.txt").readlines.each { |line| hosts[line.split[0]] = Host.new line } puts "> loaded #{hosts.keys.size} hosts" set :hosts, hosts end get '/host/:host' do hostname = params[:host] if settings.hosts.include? hostname check = settings.hosts[hostname].check if not check["up"] "off #{check.to_s}" elsif check.values.all?{|v|v} "ok #{check.to_s}" elsif check.select{|k,_|k.end_with?"/tcp"}.values.all?{|v|v} \ and not check.select{|k,_|k.end_with?"/udp"}.values.all?{|v|v} "maybe-ok #{check.to_s}" else "not-ok #{check.to_s}" end else "unknown" end end get '/host/raw/:host' do hostname = params[:host] if settings.hosts.include? hostname "#{settings.hosts[hostname].check}" else "" end end get '/all-hosts' do "#{settings.hosts.keys.join ","}" end get '/check-all-hosts' do out = "" out end get '/' do out =<

EOS out end