system_report.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class SystemReport < ApplicationModel
  3. store :data
  4. before_create :prepare_uuid
  5. def self.fetch
  6. {
  7. system_report: fetch_system_report,
  8. }
  9. end
  10. def self.fetch_with_create
  11. SystemReport.create(data: fetch, created_by_id: UserInfo.current_user_id || 1)
  12. end
  13. def self.plugins
  14. SystemReport::Plugin.list.map { |plugin| plugin.to_s.split('::').last }
  15. end
  16. def self.descriptions
  17. SystemReport::Plugin.list.map { |plugin| "#{plugin}::DESCRIPTION".constantize }
  18. end
  19. def self.fetch_system_report
  20. system_report = {}
  21. SystemReport::Plugin.list.each do |plugin|
  22. plugin_instance = plugin.new
  23. path = plugin_instance.class.path
  24. last_path = path.pop # Remove and store the last key
  25. nested_hash = path.inject(system_report) do |current_hash, key|
  26. current_hash[key] ||= {}
  27. current_hash[key]
  28. end
  29. # Set the value to the last key
  30. nested_hash[last_path] = plugin_instance.fetch
  31. end
  32. system_report
  33. end
  34. private_class_method :fetch_system_report
  35. def filename
  36. File.basename("zammad_system_report_#{Setting.get('fqdn')}_#{uuid}.json")
  37. end
  38. private
  39. def prepare_uuid
  40. self.uuid = SecureRandom.uuid
  41. end
  42. end