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 +4 -4
- data/app/controllers/abrt_reports_controller.rb +14 -12
- data/app/controllers/api/v2/abrt_reports_controller.rb +7 -1
- data/app/controllers/concerns/foreman_abrt/dashboard_controller_extensions.rb +1 -2
- data/app/helpers/abrt_reports_helper.rb +48 -6
- data/app/models/abrt_report.rb +8 -36
- data/app/models/concerns/foreman_abrt/host_extensions.rb +1 -8
- data/app/models/setting/abrt.rb +4 -4
- data/app/views/abrt_reports/_host_tab_pane.html.erb +1 -1
- data/app/views/abrt_reports/_list.html.erb +1 -1
- data/app/views/abrt_reports/show.html.erb +1 -2
- data/app/views/dashboard/_foreman_abrt_widget.html.erb +1 -1
- data/config/routes.rb +3 -1
- data/db/migrate/20140909170102_abrt_reports_drop_timestamps.rb +5 -0
- data/lib/foreman_abrt/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a1e0fe4d7a14fcc470200bc41dbd3ccd7209e01
|
4
|
+
data.tar.gz: 656ef1589530a037fd2669cd6ea7014d29bbef31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
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
|
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
|
-
|
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
|
-
|
13
|
-
start =
|
14
|
-
(
|
15
|
-
|
16
|
-
|
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', _('
|
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
|
data/app/models/abrt_report.rb
CHANGED
@@ -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
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
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(:
|
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
|
data/app/models/setting/abrt.rb
CHANGED
@@ -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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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> <%=
|
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
|
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 => /[^\/]+/},
|
data/lib/foreman_abrt/version.rb
CHANGED
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.
|
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-
|
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
|