foreman_abrt 0.0.1

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.
Files changed (35) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +619 -0
  3. data/README.md +191 -0
  4. data/Rakefile +40 -0
  5. data/app/assets/javascripts/abrt_reports.js +2 -0
  6. data/app/assets/stylesheets/abrt_reports.css +4 -0
  7. data/app/controllers/abrt_reports_controller.rb +62 -0
  8. data/app/controllers/api/v2/abrt_reports_controller.rb +37 -0
  9. data/app/helpers/abrt_reports_helper.rb +9 -0
  10. data/app/models/abrt_report.rb +120 -0
  11. data/app/models/abrt_report_response_destination.rb +5 -0
  12. data/app/models/abrt_report_response_solution.rb +5 -0
  13. data/app/models/concerns/foreman_abrt/host_extensions.rb +18 -0
  14. data/app/models/setting/abrt.rb +28 -0
  15. data/app/overrides/add_host_bug_report_tab.rb +11 -0
  16. data/app/views/abrt_reports/_host_tab.html.erb +1 -0
  17. data/app/views/abrt_reports/_host_tab_pane.html.erb +21 -0
  18. data/app/views/abrt_reports/_list.html.erb +33 -0
  19. data/app/views/abrt_reports/_show_response.html.erb +59 -0
  20. data/app/views/abrt_reports/index.html.erb +3 -0
  21. data/app/views/abrt_reports/show.html.erb +35 -0
  22. data/config/routes.rb +22 -0
  23. data/db/migrate/20140414095631_create_abrt_reports.rb +33 -0
  24. data/lib/foreman_abrt.rb +5 -0
  25. data/lib/foreman_abrt/engine.rb +61 -0
  26. data/lib/foreman_abrt/version.rb +3 -0
  27. data/lib/tasks/foreman_abrt_tasks.rake +21 -0
  28. data/test/factories/foreman_abrt_factories.rb +5 -0
  29. data/test/fixtures/abrt_reports.yml +11 -0
  30. data/test/functional/abrt_reports_controller_test.rb +7 -0
  31. data/test/test_plugin_helper.rb +6 -0
  32. data/test/unit/abrt_report_test.rb +7 -0
  33. data/test/unit/foreman_abrt_test.rb +12 -0
  34. data/test/unit/helpers/abrt_reports_helper_test.rb +4 -0
  35. metadata +98 -0
@@ -0,0 +1,5 @@
1
+ class AbrtReportResponseDestination < ActiveRecord::Base
2
+ include Authorizable
3
+
4
+ belongs_to :abrt_report
5
+ end
@@ -0,0 +1,5 @@
1
+ class AbrtReportResponseSolution < ActiveRecord::Base
2
+ include Authorizable
3
+
4
+ belongs_to :abrt_report
5
+ end
@@ -0,0 +1,18 @@
1
+ module ForemanAbrt::HostExtensions
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ has_many :abrt_reports, :dependent => :destroy, :foreign_key => "host_id"
6
+ end
7
+
8
+ def recent_abrt_reports
9
+ abrt_reports.where(:created_at => (Time.now - 1.month)..Time.now)
10
+ end
11
+
12
+ #module ClassMethods
13
+ # # create or overwrite class methods...
14
+ # def class_method_name
15
+ # end
16
+ #end
17
+
18
+ end
@@ -0,0 +1,28 @@
1
+ class Setting::Abrt < ::Setting
2
+
3
+ def self.load_defaults
4
+ return unless super
5
+
6
+ fqdn = Facter.value(:fqdn) || SETTINGS[:fqdn]
7
+ lower_fqdn = fqdn.downcase
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}
13
+
14
+ Setting.transaction do
15
+ [
16
+ self.set('abrt_server_url', N_('URL of the ABRT server to forward reports to'), 'https://localhost/faf'),
17
+ self.set('abrt_server_verify_ssl', N_('Verify ABRT server certificate?'), true),
18
+ self.set('abrt_server_ssl_certificate', N_('SSL certificate path that Foreman would use to communicate with ABRT server'), ssl_cert),
19
+ self.set('abrt_server_ssl_priv_key', N_('SSL private key path that Foreman would use to communicate with ABRT server'), ssl_priv_key),
20
+ self.set('abrt_server_ssl_ca_file', N_('SSL CA file that Foreman will use to communicate with ABRT server'), ssl_ca_file),
21
+ self.set('abrt_automatically_forward', N_('Automatically forward every report to ABRT server?'), false),
22
+ ].compact.each { |s| self.create s.update(:category => "Setting::Abrt") }
23
+ end
24
+
25
+ true
26
+
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ Deface::Override.new(:virtual_path => "hosts/show",
2
+ :name => "add_bug_report_tab",
3
+ :insert_bottom => "ul.nav-tabs",
4
+ :partial => "abrt_reports/host_tab"
5
+ )
6
+
7
+ Deface::Override.new(:virtual_path => "hosts/show",
8
+ :name => "add_bug_report_tab_pane",
9
+ :insert_bottom => "div.tab-content",
10
+ :partial => "abrt_reports/host_tab_pane"
11
+ )
@@ -0,0 +1 @@
1
+ <li><a href="#abrt" data-toggle="tab"><%= _("Bug reports") %></a></li>
@@ -0,0 +1,21 @@
1
+ <div class="tab-pane" id="abrt">
2
+ <% if @host.recent_abrt_reports.any? %>
3
+ <table class="table table-bordered table-striped">
4
+ <tr>
5
+ <th>Reported</th>
6
+ <th>#</th>
7
+ <th>Reason</th>
8
+ </tr>
9
+ <% @host.recent_abrt_reports.each do |abrt_report| %>
10
+ <tr>
11
+ <td> <%= link_to (_("%s ago") % time_ago_in_words(abrt_report.reported_at.getlocal)), abrt_report %></td>
12
+ <td> <%= abrt_report.count %> </td>
13
+ <td> <%= abrt_report.reason %> </td>
14
+ </tr>
15
+ <% end %>
16
+ </table>
17
+ <%= link_to _("All bug reports for this host"), host_abrt_reports_path(@host), :class => "btn btn-default" %>
18
+ <% else %>
19
+ <div class="alert alert-success"> <%= _("No bug reports for this host in the last month") %> </div>
20
+ <% end %>
21
+ </div>
@@ -0,0 +1,33 @@
1
+ <table class="table table-bordered table-striped ellipsis">
2
+ <tr>
3
+ <% unless params[:host_id] %>
4
+ <th><%= sort :host %></th>
5
+ <% end %>
6
+ <th><%= sort :reported, :as => _("Reported") %></th>
7
+ <th class="col-md-1"><%= sort :reason, :as => _("Reason") %></th>
8
+ <th class="col-md-1"><%= _("Repeated") %></th>
9
+ <th class="col-md-1"><%= _("Forwarded") %></th>
10
+ <th class="col-md-1"></th>
11
+ </tr>
12
+ <% for abrt_report in @abrt_reports %>
13
+ <tr>
14
+ <% if params[:host_id].nil? %>
15
+ <% if abrt_report.host.nil? %>
16
+ <td></td>
17
+ <% else %>
18
+ <td><%= link_to abrt_report.host, host_abrt_reports_path(abrt_report) %></td>
19
+ <% end %>
20
+ <% end %>
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>
23
+ <td> <%= abrt_report.count %> </td>
24
+ <td> <%= checked_icon !abrt_report.forwarded_at.nil? %> </td>
25
+ <td align="right">
26
+ <%= display_delete_if_authorized hash_for_abrt_report_path(:id => abrt_report.id).merge(:auth_object => abrt_report, :authorizer => authorizer),
27
+ :confirm => _("Delete bug report for %s?") % abrt_report.host.try(:name) %>
28
+ </td>
29
+ </tr>
30
+ <% end %>
31
+ </table>
32
+ <%= page_entries_info @abrt_reports %>
33
+ <%= will_paginate @abrt_reports %>
@@ -0,0 +1,59 @@
1
+ <div class="row">
2
+ <div class="col-md-12">
3
+ <p><%= _('The report has been forwarded to ABRT server on %s.') % @abrt_report.forwarded_at.getlocal %></p>
4
+ </div>
5
+ </div>
6
+
7
+ <div class="row">
8
+ <div class="col-md-12">
9
+ <table class="table table-bordered table-striped">
10
+ <tr><th><%= _('Known problem') %></th><td><%= @abrt_report.response_known %></td></tr>
11
+ <tr><th><%= _('Server hash') %></th><td><%= @abrt_report.response_bthash %></td></tr>
12
+ <tr><th><%= _('Message') %></th><td><%= simple_format_if_multiline @abrt_report.response_message %></td></tr>
13
+ </table>
14
+ </div>
15
+ </div>
16
+
17
+ <div class="row">
18
+ <div class="col-md-6">
19
+ <h3>Reported to</h3>
20
+ <% if !@abrt_report.abrt_report_response_destinations.empty? %>
21
+ <table class="table table-bordered table-striped">
22
+ <% for destination in @abrt_report.abrt_report_response_destinations %>
23
+ <tr>
24
+ <% if destination.desttype == 'url' %>
25
+ <td><a href="<%= destination.value %>"><%= destination.reporter %></a></td>
26
+ <% else %>
27
+ <td><%= "#{destination.reporter}: #{destination.value}" %></td>
28
+ <% end %>
29
+ </tr>
30
+ <% end %>
31
+ </table>
32
+ <% else %>
33
+ <div class="alert alert-info">
34
+ <%= _('No additional instances of the problem.') %>
35
+ </div>
36
+ <% end %>
37
+ </div>
38
+ <div class="col-md-6">
39
+ <h3>Solutions</h3>
40
+ <% if !@abrt_report.abrt_report_response_solutions.empty? %>
41
+ <table class="table table-bordered table-striped">
42
+ <% for solution in @abrt_report.abrt_report_response_solutions %>
43
+ <tr>
44
+ <% if solution.url %>
45
+ <td><a href="<%= solution.url %>"><%= solution.cause %></a></td>
46
+ <% else %>
47
+ <td><%= solution.cause %></td>
48
+ <% end %>
49
+ <td><%= simple_format_if_multiline solution.note %></td>
50
+ </tr>
51
+ <% end %>
52
+ </table>
53
+ <% else %>
54
+ <div class="alert alert-info">
55
+ <%= _('Server did not provide any solution.') %>
56
+ </div>
57
+ <% end %>
58
+ </div>
59
+ </div>
@@ -0,0 +1,3 @@
1
+ <% title _("Bug reports") %>
2
+
3
+ <%= render :partial => 'list' %>
@@ -0,0 +1,35 @@
1
+ <% title @abrt_report.host.to_s %>
2
+
3
+ <%= title_actions link_to(_("Host details"), @abrt_report.host),
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
+ link_to(_("Forward report"),
7
+ forward_abrt_report_path(@abrt_report),
8
+ :class => "btn btn-success",
9
+ :method => :post,
10
+ :confirm => @abrt_report.forwarded_at ? _("The report has already been sent to the ABRT server. Send again and overwrite the previous response?") : nil),
11
+ display_delete_if_authorized(hash_for_abrt_report_path(:id => @abrt_report), :class => "btn btn-danger")
12
+ %>
13
+
14
+ <div class="row">
15
+ <div class="col-md-12">
16
+ <table class="table table-bordered table-striped">
17
+ <tr><th><%= _('Reason') %></th><td><%= @abrt_report.reason %></td></tr>
18
+ <tr><th><%= _('First reported') %></th><td><%= @abrt_report.reported_at.getlocal %></td></tr>
19
+ <tr><th><%= _('Repeated') %></th><td><%= @abrt_report.count %></td></tr>
20
+ <tr><th><%= _('Duplication hash') %></th><td><%= @abrt_report.duphash %></td></tr>
21
+ </table>
22
+ </div>
23
+ </div>
24
+
25
+ <hr>
26
+
27
+ <% if @abrt_report.forwarded_at %>
28
+ <%= render :partial => 'show_response' %>
29
+ <% else %>
30
+ <div class="row">
31
+ <div class="col-md-12">
32
+ <p><%= _("The report hasn't been forwarded to ABRT server.") %></p>
33
+ </div>
34
+ </div>
35
+ <% end %>
data/config/routes.rb ADDED
@@ -0,0 +1,22 @@
1
+ Rails.application.routes.draw do
2
+
3
+ resources :abrt_reports, :only => [:index, :show, :destroy] do
4
+ member do
5
+ get 'json'
6
+ post 'forward'
7
+ end
8
+ end
9
+ get 'hosts/:host_id/abrt_reports', :to => 'abrt_reports#index',
10
+ :constraints => {:host_id => /[^\/]+/},
11
+ :as => "host_abrt_reports"
12
+
13
+ namespace :api, :defaults => {:format => 'json'} do
14
+ scope "(:apiv)", :module => :v2,
15
+ :defaults => {:apiv => 'v2'},
16
+ :apiv => /v1|v2/,
17
+ :constraints => ApiConstraints.new(:version => 2) do
18
+ resources :abrt_reports, :only => [:create]
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,33 @@
1
+ class CreateAbrtReports < ActiveRecord::Migration
2
+ def change
3
+ create_table :abrt_reports do |t|
4
+ t.references :host, :null => false
5
+ t.text :json
6
+ t.string :reason
7
+ t.integer :count
8
+ t.string :duphash
9
+ t.timestamp :reported_at
10
+
11
+ t.timestamp :forwarded_at
12
+ t.string :response_message
13
+ t.boolean :response_known
14
+ t.string :response_bthash
15
+
16
+ t.timestamps
17
+ end
18
+
19
+ create_table :abrt_report_response_destinations do |t|
20
+ t.references :abrt_report, :null => false
21
+ t.string :reporter
22
+ t.string :desttype
23
+ t.string :value
24
+ end
25
+
26
+ create_table :abrt_report_response_solutions do |t|
27
+ t.references :abrt_report, :null => false
28
+ t.string :cause
29
+ t.text :note
30
+ t.string :url
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ require "foreman_abrt/engine"
2
+
3
+ module ForemanAbrt
4
+ ENGINE_NAME = 'abrt'
5
+ end
@@ -0,0 +1,61 @@
1
+ require 'deface'
2
+
3
+ module ForemanAbrt
4
+ class Engine < ::Rails::Engine
5
+
6
+ config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
7
+ config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
8
+ config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
9
+ config.autoload_paths += Dir["#{config.root}/app/overrides"]
10
+
11
+ # Initialize settings
12
+ initializer 'foreman_abrt.load_default_settings', :before => :load_config_initializers do |app|
13
+ require_dependency File.expand_path('../../../app/models/setting/abrt.rb', __FILE__) if (Setting.table_exists? rescue(false))
14
+ end
15
+
16
+ # Add any db migrations
17
+ initializer "foreman_abrt.load_app_instance_data" do |app|
18
+ app.config.paths['db/migrate'] += ForemanAbrt::Engine.paths['db/migrate'].existent
19
+ end
20
+
21
+ initializer 'foreman_abrt.register_plugin', :after=> :finisher_hook do |app|
22
+ Foreman::Plugin.register :foreman_abrt do
23
+ requires_foreman '>= 1.5'
24
+
25
+ # Add permissions
26
+ security_block :foreman_abrt do
27
+ permission :view_abrt_reports, {:abrt_reports => [:index, :show, :auto_complete_search] }
28
+ permission :destroy_abrt_reports, {:abrt_reports => [:destroy] }
29
+ permission :upload_abrt_reports, {:abrt_reports => [:create] }
30
+ permission :forward_abrt_reports, {:abrt_reports => [:forward] }
31
+ end
32
+
33
+ # Add a new role
34
+ role "ABRT reports handling", [:view_abrt_reports, :destroy_abrt_reports, :upload_abrt_reports, :forward_abrt_reports]
35
+
36
+ #add menu entry
37
+ menu :top_menu, :template,
38
+ :url_hash => {:controller => :'abrt_reports', :action => :index},
39
+ :caption => _('Bug reports'),
40
+ :parent => :monitor_menu,
41
+ :after => :reports
42
+ end
43
+ end
44
+
45
+ #Include concerns in this config.to_prepare block
46
+ config.to_prepare do
47
+ begin
48
+ Host::Managed.send(:include, ForemanAbrt::HostExtensions)
49
+ rescue => e
50
+ puts "ForemanAbrt: skipping engine hook (#{e.to_s})"
51
+ end
52
+ end
53
+
54
+ rake_tasks do
55
+ Rake::Task['db:seed'].enhance do
56
+ ForemanAbrt::Engine.load_seed
57
+ end
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module ForemanAbrt
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ # Tests
2
+ namespace :test do
3
+ desc "Test ForemanAbrt"
4
+ Rake::TestTask.new(:foreman_abrt) do |t|
5
+ test_dir = File.join(File.dirname(__FILE__), '../..', 'test')
6
+ t.libs << ["test",test_dir]
7
+ t.pattern = "#{test_dir}/**/*_test.rb"
8
+ t.verbose = true
9
+ end
10
+ end
11
+
12
+ Rake::Task[:test].enhance do
13
+ Rake::Task['test:foreman_abrt'].invoke
14
+ end
15
+
16
+ load 'tasks/jenkins.rake'
17
+ if Rake::Task.task_defined?(:'jenkins:setup')
18
+ Rake::Task["jenkins:unit"].enhance do
19
+ Rake::Task['test:foreman_abrt'].invoke
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :host do
3
+ name 'foreman_abrt'
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ # This model initially had no columns defined. If you add columns to the
4
+ # model remove the '{}' from the fixture names and add the columns immediately
5
+ # below each fixture, per the syntax in the comments below
6
+ #
7
+ one: {}
8
+ # column: value
9
+ #
10
+ two: {}
11
+ # column: value
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class AbrtReportsControllerTest < ActionController::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,6 @@
1
+ # This calls the main test_helper in Foreman-core
2
+ require 'test_helper'
3
+
4
+ # Add plugin to FactoryGirl's paths
5
+ FactoryGirl.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
6
+ FactoryGirl.reload
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class AbrtReportTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,12 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class ForemanAbrtTest < ActiveSupport::TestCase
4
+ setup do
5
+ User.current = User.find_by_login "admin"
6
+ end
7
+
8
+ test "the truth" do
9
+ assert true
10
+ end
11
+
12
+ end