foreman_abrt 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e90f9c2daa852c6ac8d2debd86a5d6e6f816641
4
- data.tar.gz: aa3047b35ec9493988d41327ebde7ed4add6e507
3
+ metadata.gz: 2a1e0fe4d7a14fcc470200bc41dbd3ccd7209e01
4
+ data.tar.gz: 656ef1589530a037fd2669cd6ea7014d29bbef31
5
5
  SHA512:
6
- metadata.gz: 90ea5b440d83acf850edb42699fcd3ad1985fef6f4fb5f2cae338909f93e5cdb08082831d5a78a172a9bb0efa045dda41ac2a3f2255021739d6276d8584d3b7e
7
- data.tar.gz: 003b81e150d41deab12c8ee4d40a8e4df164d91868b5d0dd331693f5997f9d2190c9309c9400a29096336f37ba1bb1e300adf930d963f167f916ffc98f0f8d95
6
+ metadata.gz: 12800b0a258c8d3f290c0e05b62a170b5f1de76834b1fd8488b7e879a833911250636fbbea47b48f421e1d69d60105bfd3a29b3b4c67883afabc5836b8b32c8b
7
+ data.tar.gz: 8e426bc88cf4bd925db6c213da9a2206665c22ecfbad1b4f057ab6d0cf1f2caf38b356754168fb3a489342309fc9e447ab4e06682f4451e860fd4fa5194fa4c0
@@ -1,11 +1,12 @@
1
1
  class AbrtReportsController < ApplicationController
2
2
  include Foreman::Controller::AutoCompleteSearch
3
+ include AbrtReportsHelper
4
+
3
5
  before_filter :setup_search_options, :only => :index
6
+ before_filter :find_by_id, :only => [:show, :destroy, :forward]
4
7
 
5
8
  def action_permission
6
9
  case params[:action]
7
- when 'json'
8
- :view
9
10
  when 'forward'
10
11
  :forward
11
12
  else
@@ -20,12 +21,14 @@ class AbrtReportsController < ApplicationController
20
21
 
21
22
  # GET /abrt_reports/42
22
23
  def show
23
- @abrt_report = resource_base.find(params[:id])
24
+ respond_to do |format|
25
+ format.html
26
+ format.json { render :json => @abrt_report.json }
27
+ end
24
28
  end
25
29
 
26
30
  # DELETE /abrt_reports/42
27
31
  def destroy
28
- @abrt_report = resource_base.find(params[:id])
29
32
  if @abrt_report.destroy
30
33
  notice _("Successfully deleted bug report.")
31
34
  else
@@ -34,19 +37,12 @@ class AbrtReportsController < ApplicationController
34
37
  redirect_to abrt_reports_url
35
38
  end
36
39
 
37
- # GET /abrt_reports/42/json
38
- def json
39
- @abrt_report = resource_base.find(params[:id])
40
- render :json => JSON.parse(@abrt_report.json)
41
- end
42
-
43
40
  # POST /abrt_reports/42/forward
44
41
  def forward
45
- @abrt_report = resource_base.find(params[:id])
46
42
  redirect_to abrt_report_url(@abrt_report)
47
43
 
48
44
  begin
49
- response = @abrt_report.forward
45
+ response = send_to_abrt_server @abrt_report
50
46
  rescue => e
51
47
  error _("Server rejected our report: #{e.message}") and return
52
48
  end
@@ -59,4 +55,10 @@ class AbrtReportsController < ApplicationController
59
55
 
60
56
  notice _("Report successfully forwarded")
61
57
  end
58
+
59
+ private
60
+
61
+ def find_by_id
62
+ @abrt_report = resource_base.find(params[:id])
63
+ end
62
64
  end
@@ -3,6 +3,7 @@ module Api
3
3
  class AbrtReportsController < V2::BaseController
4
4
  include Api::Version2
5
5
  include Foreman::Controller::SmartProxyAuth
6
+ include AbrtReportsHelper
6
7
 
7
8
  add_puppetmaster_filters :create
8
9
 
@@ -16,10 +17,15 @@ module Api
16
17
  return
17
18
  end
18
19
 
20
+ if abrt_reports.count == 0
21
+ render :json => { "Failed to import any report" => e.message }, :status => :unprocessable_entity
22
+ return
23
+ end
24
+
19
25
  if Setting[:abrt_automatically_forward]
20
26
  abrt_reports.each do |report|
21
27
  begin
22
- response = report.forward
28
+ response = send_to_abrt_server report
23
29
  report.add_response response
24
30
  rescue => e
25
31
  logger.error "Failed to forward ABRT report: #{e.message}"
@@ -6,7 +6,6 @@ module ForemanAbrt::DashboardControllerExtensions
6
6
  end
7
7
 
8
8
  def prefetch_abrt_data
9
- # fetch reports from last 24 hours
10
- @abrt_reports = AbrtReport.authorized(:view_abrt_reports).where(:created_at => (Time.now - 24.hours)..Time.now).search_for(params[:search])
9
+ @abrt_reports = AbrtReport.authorized(:view_abrt_reports)
11
10
  end
12
11
  end
@@ -8,18 +8,60 @@ module AbrtReportsHelper
8
8
  end
9
9
 
10
10
  def count_abrt_reports abrt_reports
11
+ range_days = 14
11
12
  data = []
12
- interval = 1.hours
13
- start = Time.now.utc - 24.hours
14
- (0..23).each do |i|
15
- t = start + (interval * i)
16
- data << [24-i, abrt_reports.where(:created_at => t..(t+interval)).count]
13
+ now = Time.now.utc
14
+ start = now - range_days.days
15
+ by_day = abrt_reports.where(:reported_at => start..now).
16
+ group('DATE(reported_at)').
17
+ sum(:count)
18
+
19
+ range_days.downto(1) do |days_back|
20
+ date = (now - (days_back-1).days).strftime('%Y-%m-%d')
21
+ crashes = by_day[date] or 0
22
+ data << [days_back, crashes]
17
23
  end
18
24
  data
19
25
  end
20
26
 
21
27
  def render_abrt_graph abrt_reports, options = {}
22
28
  data = count_abrt_reports abrt_reports
23
- flot_bar_chart 'abrt_graph', _('Hours Ago'), _('Number of crashes'), data, options
29
+ flot_bar_chart 'abrt_graph', _('Days Ago'), _('Number of crashes'), data, options
30
+ end
31
+
32
+ def send_to_abrt_server abrt_report
33
+ request_params = {
34
+ :timeout => 60,
35
+ :open_timeout => 10,
36
+ :verify_ssl => Setting[:abrt_server_verify_ssl] ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
37
+ }
38
+
39
+ if Setting[:abrt_server_ssl_ca_file] && !Setting[:abrt_server_ssl_ca_file].empty?
40
+ request_params[:ssl_ca_file] = Setting[:abrt_server_ssl_ca_file]
41
+ end
42
+
43
+ if Setting[:abrt_server_ssl_certificate] && !Setting[:abrt_server_ssl_certificate].empty? \
44
+ && Setting[:abrt_server_ssl_priv_key] && !Setting[:abrt_server_ssl_priv_key].empty?
45
+ request_params[:ssl_client_cert] = OpenSSL::X509::Certificate.new(File.read(Setting[:abrt_server_ssl_certificate]))
46
+ request_params[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(Setting[:abrt_server_ssl_priv_key]))
47
+ end
48
+
49
+ resource = RestClient::Resource.new(Setting[:abrt_server_url], request_params)
50
+ response = resource['reports/new/'].post({:file => abrt_report.json, :multipart => true}, :content_type => :json, :accept => :json)
51
+
52
+ if response.code != 202
53
+ logger.error "Failed to forward bug report: #{response.code}: #{response.to_str}"
54
+ raise ::Foreman::Exception.new(N_("Failed to forward bug report: %s: %s", response.code, response.to_str))
55
+ end
56
+
57
+ JSON.parse(response.body)
58
+ end
59
+
60
+ def format_reason reason
61
+ if reason.nil? or reason.empty?
62
+ _("Unknown")
63
+ else
64
+ reason
65
+ end
24
66
  end
25
67
  end
@@ -13,6 +13,7 @@ class AbrtReport < ActiveRecord::Base
13
13
  validates :json, :presence => true
14
14
  validates :count, :numericality => { :only_integer => true, :greater_than => 0 }
15
15
  validates :duphash, :format => { :with => /\A[0-9a-fA-F]+\z/ }, :allow_blank => true
16
+ validates :reported_at, :presence => true
16
17
 
17
18
  scoped_search :in => :host, :on => :name, :complete_value => true, :rename => :host
18
19
  scoped_search :in => :environment, :on => :name, :complete_value => true, :rename => :environment
@@ -41,47 +42,18 @@ class AbrtReport < ActiveRecord::Base
41
42
  def self.import(json)
42
43
  host = Host.find_by_name(json[:host])
43
44
  reports = []
44
- AbrtReport.transaction do
45
- json[:reports].each do |report|
46
- # import one report
47
- reason = nil # try extracting reason from the report
48
- reason ||= report[:full][:reason] if report[:full].has_key? :reason
45
+
46
+ json[:reports].each do |report|
47
+ begin
49
48
  reports << AbrtReport.create!(:host => host, :count => report[:count], :json => report[:full].to_json,
50
- :duphash => report[:duphash], :reason => reason,
49
+ :duphash => report[:duphash], :reason => report[:full][:reason],
51
50
  :reported_at => report[:reported_at])
51
+ rescue => e
52
+ logger.error "Failed to import ABRT report from #{host}: #{e.class}:#{e.message}"
52
53
  end
53
54
  end
54
- reports
55
- end
56
-
57
- # XXX is the network communication acceptable in a model?
58
- def forward
59
- request_params = {
60
- :timeout => 60,
61
- :open_timeout => 10,
62
- :verify_ssl => Setting[:abrt_server_verify_ssl] ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
63
- }
64
-
65
- if Setting[:abrt_server_ssl_ca_file] && !Setting[:abrt_server_ssl_ca_file].empty?
66
- request_params[:ssl_ca_file] = Setting[:abrt_server_ssl_ca_file]
67
- end
68
55
 
69
- # XXX what certificates will be used if communicating with e.g. customer portal?
70
- if Setting[:abrt_server_ssl_certificate] && !Setting[:abrt_server_ssl_certificate].empty? \
71
- && Setting[:abrt_server_ssl_priv_key] && !Setting[:abrt_server_ssl_priv_key].empty?
72
- request_params[:ssl_client_cert] = OpenSSL::X509::Certificate.new(File.read(Setting[:abrt_server_ssl_certificate]))
73
- request_params[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(Setting[:abrt_server_ssl_priv_key]))
74
- end
75
-
76
- resource = RestClient::Resource.new(Setting[:abrt_server_url], request_params)
77
- response = resource['reports/new/'].post({:file => json, :multipart => true}, :content_type => :json, :accept => :json)
78
-
79
- if response.code != 202
80
- logger.error "Failed to forward bug report: #{response.code}: #{response.to_str}"
81
- raise ::Foreman::Exception.new(N_("Failed to forward bug report: %s: %s", response.code, response.to_str))
82
- end
83
-
84
- JSON.parse(response.body)
56
+ reports
85
57
  end
86
58
 
87
59
  def add_response(response)
@@ -6,13 +6,6 @@ module ForemanAbrt::HostExtensions
6
6
  end
7
7
 
8
8
  def recent_abrt_reports
9
- abrt_reports.where(:created_at => (Time.now - 1.month)..Time.now)
9
+ abrt_reports.where(:reported_at => (Time.now - 1.week)..Time.now).limit(10)
10
10
  end
11
-
12
- #module ClassMethods
13
- # # create or overwrite class methods...
14
- # def class_method_name
15
- # end
16
- #end
17
-
18
11
  end
@@ -6,10 +6,10 @@ class Setting::Abrt < ::Setting
6
6
  fqdn = Facter.value(:fqdn) || SETTINGS[:fqdn]
7
7
  lower_fqdn = fqdn.downcase
8
8
 
9
- ssl_cert = "#{SETTINGS[:puppetvardir]}/ssl/certs/#{lower_fqdn}.pem"
10
- ssl_ca_file = "#{SETTINGS[:puppetvardir]}/ssl/certs/ca.pem"
11
- ssl_priv_key = "#{SETTINGS[:puppetvardir]}/ssl/private_keys/#{lower_fqdn}.pem"
12
- #XXX initialize from ssl_{certificate,ca_file,priv_key}
9
+ # Try taking the provisioning SSL setup for default
10
+ ssl_cert = Setting[:ssl_certificate] or "#{SETTINGS[:puppetvardir]}/ssl/certs/#{lower_fqdn}.pem"
11
+ ssl_ca_file = Setting[:ssl_ca_file] or "#{SETTINGS[:puppetvardir]}/ssl/certs/ca.pem"
12
+ ssl_priv_key = Setting[:ssl_priv_key] or "#{SETTINGS[:puppetvardir]}/ssl/private_keys/#{lower_fqdn}.pem"
13
13
 
14
14
  Setting.transaction do
15
15
  [
@@ -10,7 +10,7 @@
10
10
  <tr>
11
11
  <td> <%= link_to (_("%s ago") % time_ago_in_words(abrt_report.reported_at.getlocal)), abrt_report %></td>
12
12
  <td> <%= abrt_report.count %> </td>
13
- <td> <%= abrt_report.reason %> </td>
13
+ <td> <%= format_reason abrt_report.reason %> </td>
14
14
  </tr>
15
15
  <% end %>
16
16
  </table>
@@ -19,7 +19,7 @@
19
19
  <% end %>
20
20
  <% end %>
21
21
  <td> <%= link_to(_("%s ago") % time_ago_in_words(abrt_report.reported_at.getlocal), abrt_report_path(abrt_report)) %> </td>
22
- <td> <%= if abrt_report.reason.nil? or abrt_report.reason.empty? then _("Unknown") else abrt_report.reason end %> </td>
22
+ <td> <%= format_reason abrt_report.reason %> </td>
23
23
  <td> <%= abrt_report.count %> </td>
24
24
  <td> <%= checked_icon !abrt_report.forwarded_at.nil? %> </td>
25
25
  <td align="right">
@@ -2,7 +2,6 @@
2
2
 
3
3
  <%= title_actions link_to(_("Host details"), @abrt_report.host),
4
4
  link_to(_("Other reports for this host"), host_abrt_reports_path(@abrt_report.host)),
5
- link_to(_("JSON"), json_abrt_report_path(@abrt_report)),
6
5
  link_to(_("Forward report"),
7
6
  forward_abrt_report_path(@abrt_report),
8
7
  :class => "btn btn-success",
@@ -14,7 +13,7 @@
14
13
  <div class="row">
15
14
  <div class="col-md-12">
16
15
  <table class="table table-bordered table-striped">
17
- <tr><th><%= _('Reason') %></th><td><%= @abrt_report.reason %></td></tr>
16
+ <tr><th><%= _('Reason') %></th><td><%= format_reason @abrt_report.reason %></td></tr>
18
17
  <tr><th><%= _('First reported') %></th><td><%= @abrt_report.reported_at.getlocal %></td></tr>
19
18
  <tr><th><%= _('Repeated') %></th><td><%= @abrt_report.count %></td></tr>
20
19
  <tr><th><%= _('Duplication hash') %></th><td><%= @abrt_report.duphash %></td></tr>
@@ -1,2 +1,2 @@
1
- <h4 style="text-align: center;"><%= _('Bug report distribution in last 24 hours') %></h4>
1
+ <h4 style="text-align: center;"><%= _('Bug report distribution in last 14 days') %></h4>
2
2
  <%= render_abrt_graph(@abrt_reports, :class => 'statistics-bar') %>
data/config/routes.rb CHANGED
@@ -2,9 +2,11 @@ Rails.application.routes.draw do
2
2
 
3
3
  resources :abrt_reports, :only => [:index, :show, :destroy] do
4
4
  member do
5
- get 'json'
6
5
  post 'forward'
7
6
  end
7
+ collection do
8
+ get 'auto_complete_search'
9
+ end
8
10
  end
9
11
  get 'hosts/:host_id/abrt_reports', :to => 'abrt_reports#index',
10
12
  :constraints => {:host_id => /[^\/]+/},
@@ -0,0 +1,5 @@
1
+ class AbrtReportsDropTimestamps < ActiveRecord::Migration
2
+ def change
3
+ remove_timestamps :abrt_reports
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module ForemanAbrt
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_abrt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Milata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-26 00:00:00.000000000 Z
11
+ date: 2014-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface
@@ -53,6 +53,7 @@ files:
53
53
  - app/views/dashboard/_foreman_abrt_widget.html.erb
54
54
  - config/routes.rb
55
55
  - db/migrate/20140414095631_create_abrt_reports.rb
56
+ - db/migrate/20140909170102_abrt_reports_drop_timestamps.rb
56
57
  - lib/foreman_abrt/version.rb
57
58
  - lib/foreman_abrt/engine.rb
58
59
  - lib/foreman_abrt.rb