Module: AbrtReportsHelper
- Included in:
- AbrtReportsController, Api::V2::AbrtReportsController
- Defined in:
- app/helpers/abrt_reports_helper.rb
Defined Under Namespace
Classes: StringIOWithPath
Instance Method Summary collapse
- #ask_for_auth? ⇒ Boolean
- #count_abrt_reports(abrt_reports) ⇒ Object
- #display_forward_button(abrt_report) ⇒ Object
- #format_reason(reason) ⇒ Object
- #forward_auth_login ⇒ Object
- #forward_auth_text ⇒ Object
- #forward_auth_title ⇒ Object
- #render_abrt_graph(abrt_reports, options = {}) ⇒ Object
- #send_to_abrt_server(abrt_report, username = nil, password = nil) ⇒ Object
- #simple_format_if_multiline(str) ⇒ Object
- #using_redhat_server? ⇒ Boolean
Instance Method Details
#ask_for_auth? ⇒ Boolean
93 94 95 96 97 98 99 100 101 |
# File 'app/helpers/abrt_reports_helper.rb', line 93 def ask_for_auth? if !Setting[:abrt_server_basic_auth_username].empty? && !Setting[:abrt_server_basic_auth_password].empty? false elsif Setting[:abrt_server_basic_auth_required] || using_redhat_server? true else false end end |
#count_abrt_reports(abrt_reports) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/helpers/abrt_reports_helper.rb', line 10 def count_abrt_reports(abrt_reports) range_days = 14 data = [] now = Time.now.utc start = now - range_days.days by_day = abrt_reports.where(:reported_at => start..now). group('DATE(reported_at)'). sum(:count) range_days.downto(1) do |days_back| date = (now - (days_back-1).days).strftime('%Y-%m-%d') crashes = (by_day[date] || 0) data << [days_back, crashes] end data end |
#display_forward_button(abrt_report) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/helpers/abrt_reports_helper.rb', line 103 def (abrt_report) if ask_for_auth? _('Send for analysis'), :id => 'forward_auth_button', :class => 'btn btn-success' else = { :class => 'btn btn-success', :method => :post } if abrt_report.forwarded_at [:confirm] = _('The report has already been sent. Sending it again will overwrite the previous response.') end link_to _('Send for analysis'), forward_abrt_report_path(abrt_report), end end |
#format_reason(reason) ⇒ Object
80 81 82 83 84 85 86 |
# File 'app/helpers/abrt_reports_helper.rb', line 80 def format_reason(reason) if reason.nil? or reason.empty? _('Unknown') else reason end end |
#forward_auth_login ⇒ Object
123 124 125 126 127 128 129 |
# File 'app/helpers/abrt_reports_helper.rb', line 123 def forward_auth_login if using_redhat_server? _('Red Hat Login') else _('Login') end end |
#forward_auth_text ⇒ Object
131 132 133 134 135 136 137 138 |
# File 'app/helpers/abrt_reports_helper.rb', line 131 def forward_auth_text if using_redhat_server? _('The problem report will be sent to Red Hat in order to determine if a solution exists. '\ 'You need to provide your Red Hat Customer Portal login and password in order to proceed.') else _('Your ABRT server is configured to require login and password.') end end |
#forward_auth_title ⇒ Object
115 116 117 118 119 120 121 |
# File 'app/helpers/abrt_reports_helper.rb', line 115 def forward_auth_title if using_redhat_server? _('Please provide Red Hat Customer Portal credentials') else _('Please provide ABRT server credentials') end end |
#render_abrt_graph(abrt_reports, options = {}) ⇒ Object
27 28 29 30 |
# File 'app/helpers/abrt_reports_helper.rb', line 27 def render_abrt_graph(abrt_reports, = {}) data = count_abrt_reports abrt_reports 'abrt_graph', _('Days Ago'), _('Number of crashes'), data, end |
#send_to_abrt_server(abrt_report, username = nil, password = nil) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/helpers/abrt_reports_helper.rb', line 42 def send_to_abrt_server(abrt_report, username = nil, password = nil) request_params = { :timeout => 60, :open_timeout => 10, :verify_ssl => Setting[:abrt_server_verify_ssl] ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE } if Setting[:abrt_server_ssl_ca_file] && !Setting[:abrt_server_ssl_ca_file].empty? request_params[:ssl_ca_file] = Setting[:abrt_server_ssl_ca_file] end if Setting[:abrt_server_ssl_certificate] && !Setting[:abrt_server_ssl_certificate].empty? \ && Setting[:abrt_server_ssl_priv_key] && !Setting[:abrt_server_ssl_priv_key].empty? request_params[:ssl_client_cert] = OpenSSL::X509::Certificate.new(File.read(Setting[:abrt_server_ssl_certificate])) request_params[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(Setting[:abrt_server_ssl_priv_key])) end # basic auth if !Setting[:abrt_server_basic_auth_username].empty? && !Setting[:abrt_server_basic_auth_password].empty? request_params[:user] = Setting[:abrt_server_basic_auth_username] request_params[:password] = Setting[:abrt_server_basic_auth_password] elsif username && password request_params[:user] = username request_params[:password] = password end resource = RestClient::Resource.new(Setting[:abrt_server_url], request_params) report_file = StringIOWithPath.new(abrt_report.json, '*buffer*', 'application/json') response = resource['reports/new/'].post({ :file => report_file, :multipart => true }, :content_type => :json, :accept => :json) if response.code != 202 logger.error "Failed to send the report for analysis: #{response.code}: #{response.to_str}" raise ::Foreman::Exception.new(N_('Failed to forward problem report: %s: %s', response.code, response.to_str)) end JSON.parse(response.body) end |
#simple_format_if_multiline(str) ⇒ Object
2 3 4 5 6 7 8 |
# File 'app/helpers/abrt_reports_helper.rb', line 2 def simple_format_if_multiline(str) if str and str.include? "\n" simple_format str else str end end |
#using_redhat_server? ⇒ Boolean
88 89 90 91 |
# File 'app/helpers/abrt_reports_helper.rb', line 88 def using_redhat_server? match = %r{^https://[^/]*access\.redhat\.com/}.match(Setting[:abrt_server_url]) !!match end |