oxidized-web 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of oxidized-web might be problematic. Click here for more details.

@@ -1,23 +1,102 @@
1
- %html
2
- !=haml :head
3
- %body
4
- %h1 no success in a day
5
- %table{:id=>'statsTable', :class=>'center tablesorter'}
1
+ .row.tbl-header
2
+ .col-xs-12
3
+ %h4
4
+ %a{href: url_for('/nodes')} nodes
5
+ \/ stats
6
+
7
+ .row
8
+ .pull-right
9
+ %button.ColVis_Button{type: 'button', onclick: 'history.go();'}
10
+ %span.glyphicon.glyphicon-repeat Refresh
11
+
12
+ .table-responsive
13
+ %table.table.table-condensed.table-striped.table-hover#statsTable
14
+ %caption
15
+ %span Node Statistics
16
+
6
17
  %thead
7
18
  %tr
8
19
  %th Name
9
- %th Last success
20
+ %th Total Runs
21
+ %th Total Failures
22
+ %th Failure Rate
23
+ %th Average Run Time
24
+ %th Last Status
25
+ %th Last Update
26
+ %th Last Failure
27
+
10
28
  %tbody
11
- -@data.select do |node,stats|
12
- - not stats[:success] or (stats[:success].last[:end] < Time.now.utc-60*60*24)
13
- - end.map do |node,stats|
14
- - last = stats[:success]
15
- - last = last.last[:end] if last
16
- - last ||= 'never'
17
- %tr
29
+ - @data.map do |node, stats|
30
+ - status = 'no_connection'
31
+ - successes = 0
32
+ - failures = 0
33
+ - avg_success_time = 0
34
+ - avg_failure_time = 0
35
+ - avg_time = 0
36
+ - row_class = ''
37
+
38
+ - if stats[:success]
39
+ - last_success = stats[:success].last[:end]
40
+ - successes = stats[:success].length
41
+ - avg_success_time = stats[:success].collect {|x| x[:time]}
42
+ - avg_success_time = avg_success_time.inject {|sum, x| sum + x}
43
+ - avg_success_time /= successes
44
+
45
+ - if stats[:no_connection]
46
+ - last_failure = stats[:no_connection].last[:end]
47
+ - failures = stats[:no_connection].length
48
+ - avg_failure_time = stats[:no_connection].collect {|x| x[:time]}
49
+ - avg_failure_time = avg_failure_time.inject {|sum, x| sum + x}
50
+ - avg_failure_time /= failures
51
+
52
+ - if avg_success_time > 0 && avg_failure_time > 0
53
+ - avg_time = (avg_success_time + avg_failure_time) / 2
54
+ - elsif avg_success_time > 0
55
+ - avg_time = avg_success_time
56
+ - elsif avg_failure_time > 0
57
+ - avg_time = avg_failure_time
58
+ - avg_time = "#{'%.2f' % avg_time}" unless avg_time == 'Unknown'
59
+
60
+ - if last_success && last_failure
61
+ - status = last_success > last_failure ? 'success' : 'no_connection'
62
+ - elsif last_success
63
+ - status = 'success'
64
+ - last_failure = 'never'
65
+ - else
66
+ - last_success = 'never'
67
+
68
+ - total_runs = successes + failures
69
+ - failure_rate = (failures / total_runs.to_f) * 100
70
+ - row_class = 'warning' if failure_rate >= 50
71
+ - row_class = 'danger' if failure_rate >= 75
72
+
73
+ %tr{class: row_class}
18
74
  %td= node
19
- %td= last
20
- :javascript
21
- $(function(){
22
- $("#statsTable").tablesorter();
23
- });
75
+ %td= total_runs
76
+ %td= failures
77
+ %td #{'%.2f' % failure_rate}%
78
+ %td #{'%.2f' % avg_time}s
79
+ %td
80
+ %div{title: status, class: status}
81
+ %td.time= last_success
82
+ %td.time= last_failure
83
+
84
+ :javascript
85
+ $(function() {
86
+ $('#statsTable').dataTable({
87
+ dom: 'C<"clear">lfrtip',
88
+ "lengthMenu": [[50, 250, 500, -1], [50, 250, 500, "All"]],
89
+ columnDefs: [{
90
+ visible: false,
91
+ targets: 1
92
+ }, {
93
+ type: "string",
94
+ targets: 3
95
+ }],
96
+ colVis: {
97
+ exclude: [0, 5]
98
+ }
99
+ });
100
+ });
101
+
102
+
@@ -1,19 +1,22 @@
1
- !=haml :head
2
- %body
3
- %h4
4
- - if @info[:group] != ''
5
- %a{:href=>url_for("/node/version?node_full=#{@info[:group] + '/' + @info[:node]}")} versions
6
- - else
7
- %a{:href=>url_for("/node/version?node_full=#{@info[:node]}")} versions
8
- \/ version #{@info[:num]} for Node
9
- %span{:class=>'node_title'} #{@info[:node]}
10
-
11
- - date_version = Time.parse @info[:date]
12
- Date of version: #{date_version.strftime("%d-%m-%y at %r")}
13
- %br
14
- %br
15
- %div{:class=>'diffs'}
16
- - @data.each_line do |line|
17
- %div #{line}
1
+ .row
2
+ .col-sm-12
3
+ %h4
4
+ - if @info[:group] != ''
5
+ - params = "node_full=#{@info[:group] + '/' + @info[:node]}"
6
+ - else
7
+ - params = "node_full=#{@info[:node]}"
8
+ %a{href: url_for("/node/version?#{params}")} versions
9
+ \/ version #{@info[:num]} for Node
10
+ %span.node_title #{@info[:node]}
11
+ .row
12
+ .col-sm-12
13
+ - date_version = Time.parse @info[:date]
14
+ Date of version:
15
+ %span.time #{date_version.strftime('%Y-%m-%d %H:%M:%S %Z')}
16
+
17
+ .row
18
+ .col-sm-12
19
+ .diffs
20
+ - @data.each_line do |line|
21
+ %div> #{line}
18
22
 
19
-
@@ -1,60 +1,51 @@
1
- %script{:src=>url_for('/scripts/jquery-2.1.1.min.js')}
2
- %script{:src=>url_for('/scripts/jquery.dataTables.min.js')}
3
- %script{:src=>url_for('/scripts/dataTables.bootstrap.js')}
4
- %script{:src=>url_for('/scripts/dataTables.colVis.js')}
5
- %link{:rel=>'stylesheet', :href=>url_for('/css/dataTables.bootstrap.css')}
6
- %link{:rel=>'stylesheet', :href=>url_for('/css/dataTables.colVis.css')}
1
+ .row.tbl-header
2
+ .col-xs-12
3
+ %h4
4
+ %a{href: url_for('/nodes')} nodes
5
+ \/ Versions for Node
6
+ %span.node_title #{@node}
7
+
8
+ .row
9
+ .pull-right
10
+ %form
11
+ %button.ColVis_Button{type: 'button', onclick: 'history.go();'}
12
+ %span.glyphicon.glyphicon-repeat Refresh
13
+ .table-responsive
14
+ %table.table.table-condensed.table-striped.table-hover#versionsTable
15
+ %thead
16
+ %tr
17
+ %th Version
18
+ %th Dates
19
+ %th Author
20
+ %th Message
21
+ %th Actions
22
+
23
+ %tbody
24
+ - nb = @data.count + 1
25
+ - @data.each do |x|
26
+ %tr
27
+ %td #{nb -= 1}
28
+ %td #{time_from_now x[:date]}
29
+ %td #{x[:author][:name]}
30
+ %td #{x[:message]}
31
+ %td
32
+ - params = "node=#{@node}&group=#{@group}&oid=#{x[:oid]}"
33
+ - params = "#{params}&date=#{x[:date]}&num=#{nb}"
34
+ %a{title: 'configuration',
35
+ href: url_for("/node/version/view?#{params}")}
36
+ %span.glyphicon.glyphicon-cloud-download
37
+ &nbsp;&nbsp;
38
+ %a{title: 'diff', href: url_for("/node/version/diffs?#{params}")}
39
+ %img{src: url_for('/images/diff_15x17.png')}
40
+
7
41
  :javascript
8
42
  $(function() {
9
43
  $('#versionsTable').dataTable({
10
44
  dom: 'C<"clear">lfrtip',
11
- "order": [[ 0, "desc" ]],
12
- columnDefs: [
13
- { visible: false, targets: [2, 3] }
14
- }
45
+ "order": [[0, "desc"]],
46
+ columnDefs: [{
47
+ visible: false,
48
+ targets: [2, 3]
49
+ }]
15
50
  });
16
51
  });
17
- %div{:class=>'row tbl-header'}
18
- %div{:class=>'col-xs-12 '}
19
- %h4
20
- %a{:href=>url_for('/nodes')} nodes
21
- \/ Versions for Node
22
- %span{:class=>'node_title'} #{@node}
23
-
24
- %div{:class=>'row'}
25
- %div{:class=>'refresh-div'}
26
- %form
27
- %button{:class => "ColVis_Button", :type => "button", :onclick => "history.go();"}
28
- %span{:class=>"glyphicon glyphicon-repeat"}
29
- Refresh
30
- %table{:id=>'versionsTable', :class=>'table table-responsive tablesorter'}
31
- %thead
32
- %tr
33
- %th Version
34
- %th Dates
35
- %th Author
36
- %th Message
37
- %th Actions
38
-
39
- %tbody
40
- -trclass = %w(even odd)
41
- - nb = @data.count + 1
42
- - @data.each do |x|
43
- %tr
44
- %td
45
- #{nb -= 1}
46
- %td
47
- #{time_from_now x[:date]}
48
- %td
49
- #{x[:author][:name]}
50
- %td
51
- #{x[:message]}
52
- %td
53
- %a{:title => "configuration", :href => url_for("/node/version/view?node=#{@node}&group=#{@group}&oid=#{x[:oid]}&date=#{x[:date]}&num=#{nb}") }
54
- %span{:class=>'glyphicon glyphicon-cloud-download'}
55
- &nbsp;&nbsp;
56
- %a{:title => "diff", :href => url_for("/node/version/diffs?node=#{@node}&group=#{@group}&oid=#{x[:oid]}&date=#{x[:date]}&num=#{nb}") }
57
- %img{:src=>url_for('/images/diff_15x17.png')}
58
-
59
-
60
-
@@ -9,7 +9,7 @@ module Oxidized
9
9
  module API
10
10
  class WebApp < Sinatra::Base
11
11
  helpers Sinatra::UrlForHelper
12
- set :public_folder, Proc.new { File.join(root, "public") }
12
+ set :public_folder, Proc.new { File.join(root, 'public') }
13
13
 
14
14
  get '/' do
15
15
  redirect url_for('/nodes')
@@ -46,14 +46,14 @@ module Oxidized
46
46
  end
47
47
 
48
48
  post '/nodes/conf_search' do
49
- @to_research = params[:search_in_conf_textbox]
49
+ @to_research = Regexp.new params[:search_in_conf_textbox]
50
50
  nodes_list = nodes.list.map
51
51
  @nodes_match = []
52
52
  nodes_list.each do |n|
53
53
  node, @json = route_parse n[:name]
54
54
  config = nodes.fetch node, n[:group]
55
- if config.include? @to_research
56
- @nodes_match.push({:node => n[:name], :full_name => n[:full_name]})
55
+ if config[@to_research]
56
+ @nodes_match.push({ node: n[:name], full_name: n[:full_name] })
57
57
  end
58
58
  end
59
59
  out :conf_search
@@ -116,12 +116,12 @@ module Oxidized
116
116
  out :node
117
117
  end
118
118
 
119
- #redirect to the web page for rancid - oxidized migration
119
+ # redirect to the web page for rancid - oxidized migration
120
120
  get '/migration' do
121
121
  out :migration
122
122
  end
123
123
 
124
- #get the files send
124
+ # get the files send
125
125
  post '/migration' do
126
126
  number = params[:number].to_i
127
127
  cloginrc_file = params['cloginrc'][:tempfile]
@@ -131,27 +131,26 @@ module Oxidized
131
131
 
132
132
  i = 1
133
133
  while i <= number do
134
- router_db_files.push({:file=>(params["file"+i.to_s][:tempfile]), :group=>params["group"+i.to_s]})
135
- i = i+1
134
+ router_db_files.push({ file: params["file#{i}"][:tempfile], group: params["group#{i}"] })
135
+ i = i + 1
136
136
  end
137
137
 
138
138
  migration = Mig.new(router_db_files, cloginrc_file, path_new_file)
139
139
  migration.go_rancid_migration
140
- redirect url_for("//nodes")
141
-
140
+ redirect url_for('//nodes')
142
141
  end
143
142
 
144
143
  get '/css/*.css' do
145
144
  sass "sass/#{params[:splat].first}".to_sym
146
145
  end
147
146
 
148
- #show the lists of versions for a node
147
+ # show the lists of versions for a node
149
148
  get '/node/version.?:format?' do
150
149
  @data = nil
151
150
  @group = nil
152
151
  @node = nil
153
152
  node_full = params[:node_full]
154
- if node_full.include? "/"
153
+ if node_full.include? '/'
155
154
  node_full = node_full.split('/')
156
155
  @group = node_full[0]
157
156
  @node = node_full[1]
@@ -163,19 +162,26 @@ module Oxidized
163
162
  out :versions
164
163
  end
165
164
 
166
- #show the blob of a version
165
+ # show the blob of a version
167
166
  get '/node/version/view.?:format?' do
168
167
  node, @json = route_parse :node
169
- @info = {:node => node, :group => params[:group],:oid => params[:oid],:date => params[:date],:num => params[:num]}
168
+ @info = {
169
+ node: node,
170
+ group: params[:group],
171
+ oid: params[:oid],
172
+ date: params[:date],
173
+ num: params[:num]
174
+ }
175
+
170
176
  @data = nodes.get_version node, @info[:group], @info[:oid]
171
177
  out :version
172
178
  end
173
179
 
174
- #show diffs between 2 version
180
+ # show diffs between 2 version
175
181
  get '/node/version/diffs' do
176
182
  node, @json = route_parse :node
177
183
  @data = nil
178
- @info = {:node => node, :group => params[:group],:oid => params[:oid],:date => params[:date],:num => params[:num], :num2 => (params[:num].to_i - 1)}
184
+ @info = {node: node, group: params[:group], oid: params[:oid], date: params[:date], num: params[:num], num2: (params[:num].to_i - 1)}
179
185
  group = nil
180
186
  if @info[:group] != ''
181
187
  group = @info[:group]
@@ -197,25 +203,25 @@ module Oxidized
197
203
  else
198
204
  @data = nodes.get_diff node, @info[:group], @info[:oid], nil
199
205
  end
200
- @stat = ["null","null"]
206
+ @stat = ['null', 'null']
201
207
  if @data != 'no diffs' && @data != nil
202
208
  @stat = @data[:stat]
203
209
  @data = @data[:patch]
204
210
  else
205
- @data = "no available"
211
+ @data = 'no available'
206
212
  end
207
213
  @diff = diff_view @data
208
214
  out :diffs
209
215
  end
210
216
 
211
- #used for diff between 2 distant commit
217
+ # used for diff between 2 distant commit
212
218
  post '/node/version/diffs' do
213
219
  redirect url_for("/node/version/diffs?node=#{params[:node]}&group=#{params[:group]}&oid=#{params[:oid]}&date=#{params[:date]}&num=#{params[:num]}&oid2=#{params[:oid2]}")
214
220
  end
215
221
 
216
222
  private
217
223
 
218
- def out template=:default
224
+ def out template = :default
219
225
  if @json or params[:format] == 'json'
220
226
  if @data.is_a?(String)
221
227
  json @data.lines
@@ -226,7 +232,7 @@ module Oxidized
226
232
  content_type :text
227
233
  @data
228
234
  else
229
- haml template, :layout => true
235
+ haml template, layout: true
230
236
  end
231
237
  end
232
238
 
@@ -248,12 +254,12 @@ module Oxidized
248
254
  [e.join('.'), json]
249
255
  end
250
256
 
251
- #give the time enlapsed between now and a date
257
+ # give the time enlapsed between now and a date
252
258
  def time_from_now date
253
259
  if date
254
- #if the + is missing
255
- unless date.include? "+"
256
- date.insert(21, "+")
260
+ # if the + is missing
261
+ unless date.include? '+'
262
+ date.insert(21, '+')
257
263
  end
258
264
  date = DateTime.parse date
259
265
  now = DateTime.now
@@ -262,7 +268,7 @@ module Oxidized
262
268
  hh, mm = mm.divmod(60)
263
269
  dd, hh = hh.divmod(24)
264
270
  if dd > 0
265
- date = "#{dd} days #{hh} hours ago"
271
+ date = "#{dd} days #{hh} hours ago"
266
272
  elsif hh > 0
267
273
  date = "#{hh} hours #{mm} min ago"
268
274
  else
@@ -272,7 +278,7 @@ module Oxidized
272
278
  date
273
279
  end
274
280
 
275
- #method the give diffs in separate view (the old and the new) as in github
281
+ # method the give diffs in separate view (the old and the new) as in github
276
282
  def diff_view diff
277
283
  old_diff = []
278
284
  new_diff = []
@@ -295,20 +301,20 @@ module Oxidized
295
301
  break
296
302
  end
297
303
  if (/^\-.*/.match(old_diff[i])) && !(/^\+.*/.match(new_diff[i]))
298
- #tag removed latter to add color syntax
304
+ # tag removed latter to add color syntax
299
305
  insert = 'empty_line'
300
- #ugly way to avoid asymmetry if at display the line takes 2 line on the screen
306
+ # ugly way to avoid asymmetry if at display the line takes 2 line on the screen
301
307
  insert = "&nbsp;\n"
302
- new_diff.insert(i,insert)
308
+ new_diff.insert(i, insert)
303
309
  length_n += 1
304
310
  elsif !(/^\-.*/.match(old_diff[i])) && (/^\+.*/.match(new_diff[i]))
305
311
  insert = 'empty_line'
306
312
  insert = "&nbsp;\n"
307
- old_diff.insert(i,insert)
313
+ old_diff.insert(i, insert)
308
314
  length_o += 1
309
315
  end
310
316
  end
311
- {:old_diff => old_diff, :new_diff => new_diff}
317
+ { old_diff: old_diff, new_diff: new_diff }
312
318
  end
313
319
  end
314
320
  end