forked from rottenbytes/Cuisine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cuisine.rb
96 lines (71 loc) · 1.9 KB
/
cuisine.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env ruby
require "rubygems"
require "sinatra"
require "haml"
require "tire"
require "cuisine/elasticsearch"
require "cuisine/config"
__DIR__ = File.expand_path(File.dirname(__FILE__))
set :public_folder, __DIR__ + '/public'
set :views, __DIR__ + '/templates'
template :layout do
File.read('templates/layout.haml')
end
before do
@config=load_config("config/cuisine.yml")
Tire::Configuration.url(@config["es_url"])
@environments = es_get_environments()
end
get "/" do
@updatedonly=false
if params[:updatedonly] == "true" then
@updatedonly=true
end
@latest = es_search_limited(nb=@config["homepage_hosts"],hostname=@config["homepage_filter"],filter_updated=@updatedonly)
haml :index
end
get "/environment/:environment" do
@updatedonly=false
if params[:updatedonly] == "true" then
@updatedonly=true
end
@latest = es_search_limited(nb=@config["homepage_hosts"],hostname=@config["homepage_filter"],filter_updated=@updatedonly,environment=params[:environment])
haml :index
end
get "/search" do
haml :search
end
post "/search" do
criterias = {}
criterias[:string] = {}
criterias[:updatedonly] = false
if params[:chk_nodename]
criterias[:string][:nodename] = params[:nodename]
end
if params[:chk_updated_resources]
criterias[:string][:updated_resources] = params[:updated_resources]
end
if params[:chk_diffs]
criterias[:string][:diffs] = params[:diffs]
end
if params[:chk_updatedonly]
criterias[:updatedonly] = true
end
if params[:environment]
criterias[:string][:environment] = params[:environment]
end
@search_params=criterias
@results = es_search_criterias(criterias=criterias)
haml :search
end
get "/about" do
haml :about
end
get "/host/:hostname" do
@infos = es_search_limited(nb=@config["results_hosts"], hostname=params[:hostname])
haml :host
end
get "/run/:id" do
@infos = es_get_run(params[:id])[0]
haml :run
end