Class: RedhatAccess::Telemetry::MessagingService

Inherits:
Object
  • Object
show all
Includes:
LookUps
Defined in:
app/services/redhat_access/telemetry/messaging_service.rb

Constant Summary collapse

WEEKLY_SUMMARY_PATH =
'v1/messaging/data/weeklyinfo'
RULE_STATS_PATH =
'v3/stats/rules'
SYSTEM_STATS_PATH =
'v3/stats/systems'

Instance Method Summary collapse

Methods included from LookUps

#can_mask_rules, #can_unregister_system, #current_organization_object, #disconnected_org?, #get_basic_auth_options, #get_branch_id_for_org, #get_branch_id_for_uuid, #get_content_host, #get_content_hosts, #get_default_ssl_ca_file, #get_http_options, #get_http_user_agent, #get_leaf_id, #get_mutual_tls_auth_options, #get_organization, #get_plugin_parent_name, #get_plugin_parent_version, #get_portal_http_proxy, #get_rha_plugin_name, #get_rha_plugin_rpm_name, #get_rha_plugin_version, #get_ssl_options_for_org, #get_ssl_options_for_uuid, #get_tapi_timeout, #get_telemetry_config, #get_upload_timeout, #insights_api_host, #is_org_selected?, #is_susbcribed_to_redhat?, #telemetry_enabled?, #telemetry_enabled_for_uuid?, #upstream_owner, #use_basic_auth?, #use_subsets?, #user_login_to_hash

Constructor Details

#initialize(org) ⇒ MessagingService

Returns a new instance of MessagingService.



14
15
16
17
# File 'app/services/redhat_access/telemetry/messaging_service.rb', line 14

def initialize(org)
  @org = org
  @branch_id = get_branch_id_for_org(org)
end

Instance Method Details

#all_weekly_mail_dataObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/services/redhat_access/telemetry/messaging_service.rb', line 51

def all_weekly_mail_data
  data = []
  @user_map = current_user_map
  current_user_map.each do |key,user|
    begin
      user_data = weekly_summary_data(user.)
      data.push(user_data) unless user_data.nil? || user_data[:data].nil? || user_data[:data].total_systems == 0
    rescue => e
      Rails.logger.warn("Unable to get weekly email data for user : #{e}")
    end
  end
  data
end

#get_auth_opts(creds) ⇒ Object



108
109
110
# File 'app/services/redhat_access/telemetry/messaging_service.rb', line 108

def get_auth_opts(creds)
  get_ssl_options_for_org(@org, nil)
end

#get_credsObject



112
113
114
115
# File 'app/services/redhat_access/telemetry/messaging_service.rb', line 112

def get_creds
  #legacy
  nil
end

#get_current_organizationObject



104
105
106
# File 'app/services/redhat_access/telemetry/messaging_service.rb', line 104

def get_current_organization
  @org
end

#get_machinesObject



96
97
98
99
100
101
102
# File 'app/services/redhat_access/telemetry/messaging_service.rb', line 96

def get_machines
  machines = get_content_hosts(@org)
  if machines.empty?
    machines = ['NULL_SET']
  end
  machines.sort
end

#risk_summaryObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/services/redhat_access/telemetry/messaging_service.rb', line 19

def risk_summary
  begin
    rule_counts = rules_stat_summary
    critical_counts = http_get_from_json(SYSTEM_STATS_PATH, {:minSeverity => :CRITICAL}, true)
    return OpenStruct.new({:critical_count => critical_counts.affected,
                           :system_count => critical_counts.total,
                           :low_percent => percent(rule_counts.info,rule_counts.total),
                           :medium_percent => percent(rule_counts.warn,rule_counts.total),
                           :high_percent => percent(rule_counts.error,rule_counts.total),
                           :critical_percent => percent(rule_counts.critical,rule_counts.total)
                          })
  rescue Exception => e
    return error_response("Unable to get risk summary : #{e}")
  end
  # return {:critical_count => 10,
  #         :system_count => 100,
  #         :low_percent => 1.2,
  #         :medium_percent => 38.4,
  #         :high_percent => 17.5,
  #         :critical_percent => 24.2
  # }
end

#rules_stat_summaryObject



42
43
44
45
46
47
48
# File 'app/services/redhat_access/telemetry/messaging_service.rb', line 42

def rules_stat_summary
  begin
    http_get_from_json(RULE_STATS_PATH, {}, true)
  rescue Exception => e
    return error_response("Unable to get rule summary : #{e}")
  end
end

#weekly_summary_data(username) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/services/redhat_access/telemetry/messaging_service.rb', line 65

def weekly_summary_data(username)
  User.as username do
    options = {:method => :GET,
               :resource => WEEKLY_SUMMARY_PATH,
               :params => {},
               :payload => nil,
               :use_subsets => true
    }
    json_data = http_request(options, true)
    # Sample expected output: {
    #     "total_systems": 43,
    #     "checking_in_pct": 2,
    #     "total_actions": 22,
    #     "high_severity_hits": 11,
    #     "new_rules": [
    #         {
    #             "rule_id": "vfs_cache_pressure|VFS_CACHE_PRESSURE_TOO_HIGH",
    #             "summary": Rule summary,
    #             "description": "VFS cache pressue"
    #         }
    #     ]
    # }
    data = JSON.parse(json_data, object_class: OpenStruct)
    info = {
        user: User.current,
        data: data
    }
    info
  end
end