[PATCH/foreman 1/1] fixes #1298 - Make the run distribution chart appear within the same scope as the rest of the dashboard

patch fixes #1298 - forgot to mention that…

··· Op 7 november 2011 22:19 heeft Tim Speetjens het volgende geschreven: > Signed-off-by: Tim Speetjens > --- > app/controllers/dashboard_controller.rb | 14 +++++++------- > app/helpers/dashboard_helper.rb | 4 ++-- > app/models/host.rb | 9 +++++++++ > app/views/dashboard/index.html.erb | 2 +- > 4 files changed, 19 insertions(+), 10 deletions(-) > > diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb > index 90797c9..2914670 100644 > --- a/app/controllers/dashboard_controller.rb > +++ b/app/controllers/dashboard_controller.rb > @@ -13,14 +13,14 @@ class DashboardController < ApplicationController > > private > def prefetch_data > - hosts = Host.search_for(params[:search]) > + @hosts = Host.search_for(params[:search]) > @report = { > - :total_hosts => hosts.count, > - :bad_hosts => hosts.recent.with_error.count, > - :active_hosts => hosts.recent.with_changes.count, > - :ok_hosts => hosts.recent.successful.count, > - :out_of_sync_hosts => hosts.out_of_sync.count, > - :disabled_hosts => hosts.alerts_disabled.count > + :total_hosts => @hosts.count, > + :bad_hosts => @hosts.recent.with_error.count, > + :active_hosts => @hosts.recent.with_changes.count, > + :ok_hosts => @hosts.recent.successful.count, > + :out_of_sync_hosts => @hosts.out_of_sync.count, > + :disabled_hosts => @hosts.alerts_disabled.count > } > @report[:good_hosts] = @report[:ok_hosts] + @report[:active_hosts] > @report[:percentage] = (@report[:good_hosts] == 0 or @report[:total_hosts] == 0) ? 0 : @report[:good_hosts]*100 / @report[:total_hosts] > diff --git a/app/helpers/dashboard_helper.rb b/app/helpers/dashboard_helper.rb > index 3ac6231..4e45eaa 100644 > --- a/app/helpers/dashboard_helper.rb > +++ b/app/helpers/dashboard_helper.rb > @@ -1,13 +1,13 @@ > module DashboardHelper > > - def count_reports() > + def count_reports(hosts) > interval = Setting[:puppet_interval] / 10 > counter = [] > labels = [] > start =Time.now.utc - Setting[:puppet_interval].minutes > (1..(Setting[:puppet_interval] / interval)).each do > now = start + interval.minutes > - counter < {:reported_at => start..(now-1.second)}) > + counter < labels < start = now > end > diff --git a/app/models/host.rb b/app/models/host.rb > index 9df1389..7e59d3f 100644 > --- a/app/models/host.rb > +++ b/app/models/host.rb > @@ -97,6 +97,15 @@ class Host < Puppet::Rails::Host > > named_scope :completer_scope, lambda { my_hosts.scope(:find) } > > + named_scope :run_distribution, lambda { |fromtime,totime| > + unless fromtime.nil? or totime.nil? > + { :joins => "INNER JOIN reports ON reports.host_id = hosts.id", > + :conditions => ["reports.reported_at BETWEEN ? AND ?", fromtime, (totime - 1.second)] } > + else > + raise "invalid timerange" > + end > + } > + > # audit the changes to this model > acts_as_audited :except => [:last_report, :puppet_status, :last_compile] > > diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb > index 7b40f57..9c4a699 100644 > --- a/app/views/dashboard/index.html.erb > +++ b/app/views/dashboard/index.html.erb > @@ -29,7 +29,7 @@ > >
> <%= render_overview(@report, :class => 'statistics_pie span8') %> > - <%= render_run_distribution(count_reports, :class => 'statistics_bar span8') %> > + <%= render_run_distribution(count_reports(@hosts), :class => 'statistics_bar span8') %> >
> > > -- > 1.7.2.5 >