Feature #424 ยป 0001-Fixes-424-Added-responders-for-JSON-and-YAML-to-Dash.patch
app/controllers/dashboard_controller.rb | ||
---|---|---|
helper :hosts
|
||
def index
|
||
respond_to do |format|
|
||
format.html
|
||
format.yaml { render :text => @report.to_yaml }
|
||
format.json { render :json => @report.to_json }
|
||
end
|
||
end
|
||
private
|
||
def graphs
|
||
def graphs
|
||
data ={
|
||
:labels => [ ['string', "State"], ['number', "Number of Hosts"] ],
|
||
:values => [ ["Active", @active_hosts],["Error", @bad_hosts ], ["Out Of Sync", @out_of_sync_hosts ], ["OK", @good_hosts] ]
|
||
:values => [
|
||
["Active", @report[:active_hosts]],["Error", @report[:bad_hosts]],
|
||
["Out Of Sync", @report[:out_of_sync_hosts]], ["OK", @report[:good_hosts]]
|
||
]
|
||
}
|
||
options = { :title => "Puppet Clients Activity Overview"}#,
|
||
# :colors =>['#0000FF','#FF0000','#00FF00','#41A317'] }
|
||
... | ... | |
end
|
||
def prefetch_data
|
||
@total_hosts = Host.count
|
||
# hosts with errors in the last puppet run
|
||
@bad_hosts = Host.recent.with_error.count
|
||
# hosts with changes in the last puppet run
|
||
@active_hosts = Host.recent.with_changes.count
|
||
@good_hosts = Host.recent.successful.count
|
||
@percentage = (@good_hosts == 0 or @total_hosts == 0) ? 0 : @good_hosts *100 / @total_hosts
|
||
# all hosts with didn't run puppet in the <time interval> - regardless of their status
|
||
@out_of_sync_hosts = Host.out_of_sync.count
|
||
@intersting_reports = Report.with_changes.count
|
||
@disabled_hosts = Host.alerts_disabled.count
|
||
# the run interval to show in the dashboard graph
|
||
@report = {
|
||
:total_hosts => Host.count,
|
||
:bad_hosts => Host.recent.with_error.count,
|
||
:active_hosts => Host.recent.with_changes.count,
|
||
:good_hosts => Host.recent.successful.count,
|
||
:out_of_sync_hosts => Host.out_of_sync.count,
|
||
:intersting_reports => Report.with_changes.count,
|
||
:disabled_hosts => Host.alerts_disabled.count
|
||
}
|
||
@report[:percentage] = (@report[:good_hosts] == 0 or @report[:total_hosts] == 0) ? 0 : @report[:good_hosts]*100 / @report[:total_hosts]
|
||
end
|
||
end
|
app/views/dashboard/index.html.erb | ||
---|---|---|
<div id="dashboard">
|
||
<h1>Overview</h1>
|
||
<p>Generated at <%= Time.now.to_s(:short) %></p>
|
||
<p>Good Host Reports in the last <%= SETTINGS[:puppet_interval] %> minutes <%= "#{@good_hosts} / #{@total_hosts}" %> hosts (<%=@percentage%>%) </p>
|
||
<p>Good Host Reports in the last <%= SETTINGS[:puppet_interval] %> minutes <%= "#{@report[:good_hosts]} / #{@report[:total_hosts]}" %> hosts (<%=@report[:percentage]%>%) </p>
|
||
<h1>Summary</h1>
|
||
<p>Hosts that had performed modifications <%= link_to @active_hosts, :controller => "hosts", :action => "active" %></p>
|
||
<p>Out Of Sync Hosts <%= link_to @out_of_sync_hosts, :controller => "hosts", :action => "out_of_sync" %></p>
|
||
<p>Hosts in Error State <%= link_to @bad_hosts, :controller => "hosts", :action => "errors" %></p>
|
||
<p>Hosts With Alerts Disabled <%= link_to @disabled_hosts, :controller => "hosts", :action => "disabled" %></p>
|
||
<p>Hosts that had performed modifications <%= link_to @report[:active_hosts], :controller => "hosts", :action => "active" %></p>
|
||
<p>Out Of Sync Hosts <%= link_to @report[:out_of_sync_hosts], :controller => "hosts", :action => "out_of_sync" %></p>
|
||
<p>Hosts in Error State <%= link_to @report[:bad_hosts], :controller => "hosts", :action => "errors" %></p>
|
||
<p>Hosts With Alerts Disabled <%= link_to @report[:disabled_hosts], :controller => "hosts", :action => "disabled" %></p>
|
||
<div id='overview'></div>
|
||
<%= @overview.render('overview') %>
|