-
Notifications
You must be signed in to change notification settings - Fork 1
/
mco_dash.rb
59 lines (49 loc) · 1.33 KB
/
mco_dash.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'rubygems' if RUBY_VERSION < "1.9"
require 'sinatra'
require 'sinatra/base'
require 'sinatra/respond_to'
require 'logger'
require 'json'
require 'mcollective'
include MCollective::RPC
require (File.join(File.dirname(__FILE__), 'config', 'environment.rb'))
require 'mcoll'
class Mcodash < Sinatra::Base
register Sinatra::RespondTo
#Sinatra::Application.register Sinatra::RespondTo
set :static, true
set :public, File.dirname(__FILE__) + '/static'
configure do
LOGGER = Logger.new("log/mcodash.log", 7, 'daily')
end
helpers do
def logger
LOGGER
end
end
get '/' do
respond_to do |wants|
wants.html { erb :index,
:layout => :main_template }
end
end
get '/hostfilter' do
respond_to do |wants|
wants.html { erb :hostform,
:layout => :main_template }
end
end
post '/hostfilter' do
client = Mcoll::Client.new
request[:agent] = params[:request].split(":")[0]
request[:action] = params[:request].split(":")[1]
response = client.getresults(params[:fact], params[:value], request[:agent], request[:action])
respond_to do |wants|
wants.html { erb :hostresults,
:layout => :main_template,
:locals => {:response => response, :request => request}
}
wants.json { results.to_json }
end
end
end