Class: HammerCLICsv::CsvCommand::ReportsCommand
- Inherits:
-
BaseCommand
- Object
- HammerCLI::Apipie::Command
- BaseCommand
- HammerCLICsv::CsvCommand::ReportsCommand
show all
- Defined in:
- lib/hammer_cli_csv/reports.rb
Constant Summary
collapse
- TIME =
'Time'
- APPLIED =
'Applied'
- RESTARTED =
'Restarted'
- FAILED =
'Failed'
- FAILED_RESTARTS =
'Failed Restarts'
- SKIPPED =
'Skipped'
- PENDING =
'Pending'
- METRICS =
'Metrics'
Constants inherited
from BaseCommand
BaseCommand::COUNT, BaseCommand::NAME
Instance Method Summary
collapse
Methods inherited from BaseCommand
#apipie_check_param, #associate_locations, #associate_organizations, #authenticate_request, #build_os_name, #check_server_status, #collect_column, #count, #execute, #export_column, #foreman_architecture, #foreman_container, #foreman_domain, #foreman_environment, #foreman_filter, #foreman_host, #foreman_hostgroup, #foreman_location, #foreman_medium, #foreman_operatingsystem, #foreman_organization, #foreman_partitiontable, #foreman_permission, #foreman_provisioning_template, #foreman_role, #foreman_smart_proxy, #foreman_template_kind, #hammer, #hammer_context, #help, help_columns, #katello_contentview, #katello_contentviewversion, #katello_hostcollection, #katello_product, #katello_repository, #labelize, #lifecycle_environment, #namify, #pluralize, #split_os_name, #supported?, supported?, #thread_import
#api_connection
Instance Method Details
#create_reports_from_csv(line) ⇒ Object
38
39
40
41
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
|
# File 'lib/hammer_cli_csv/reports.rb', line 38
def create_reports_from_csv(line)
count(line[COUNT]).times do |number|
name = namify(line[NAME], number)
if !@existing_reports[name]
print "Creating report '#{name}'..." if option_verbose?
reported_at = line[TIME] || Time.now
report = @api.resource(:reports).call(:create, {
'host' => name,
'reported_at' => reported_at,
'status' => {
'applied' => line[APPLIED],
'restarted' => line[RESTARTED],
'failed' => line[FAILED],
'failed_restarts' => line[FAILED_RESTARTS],
'skipped' => line[SKIPPED],
'pending' => line[PENDING]
},
'metrics' => JSON.parse(line[METRICS]),
'logs' => []
})
@existing_reports[name] = report['id']
else
print "Updating report '#{name}'..." if option_verbose?
@api.resource(:reports).call(:update, {
'id' => @existing_reports[name]
})
end
puts 'done' if option_verbose?
end
end
|
#export(csv) ⇒ Object
16
17
18
19
20
21
22
23
|
# File 'lib/hammer_cli_csv/reports.rb', line 16
def export(csv)
csv << [NAME]
@api.resource(:reports).call(:index, {
'per_page' => 999999
})['results'].each do |report|
csv << [report['host_name'], report['metrics'].to_json]
end
end
|
#import ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/hammer_cli_csv/reports.rb', line 25
def import
@existing_reports = {}
@api.resource(:reports).call(:index, {
'per_page' => 999999
})['results'].each do |report|
@existing_reports[report['name']] = report['id']
end
thread_import do |line|
create_reports_from_csv(line)
end
end
|