hammer_cli_foreman_host_reports 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ab8c54026b19b65dfeecaff96990dad57591b93209bfe9dc399b7cfad63e850c
4
+ data.tar.gz: 50b239a0918a7d9afc9764dec836dfecb69801347f2d3ed316dd974425491752
5
+ SHA512:
6
+ metadata.gz: e25b17aafa25b0edd3520c14e8462c298aa7d11fbd8a3b9f01f569d6f1461c6d744531b95d5a645a1d61463e00ddf733e768e8f66aad257c165078f415a70c4d
7
+ data.tar.gz: 70899f6c7ff939f6fec2fd01b6dabdd1b7f512c96cfdaf4d27dd115b2d27328073f033d24ca8c75d02bd9cc7a63872f49cf7f9e3d2ef87af34f2d27134ff3306
data/LICENSE ADDED
@@ -0,0 +1,5 @@
1
+ This program and entire repository is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
2
+
3
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
4
+
5
+ You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Hammer CLI Foreman Host Reports
2
+
3
+ This Hammer CLI plugin contains set of commands for [foreman_host_reports](
4
+ https://github.com/theforeman/foreman_host_reports
5
+ ), a plugin to Foreman for Host Reports.
6
+
7
+ ## Versions
8
+
9
+ This is the list of which version of Foreman Host Reports is needed to which version of this plugin.
10
+
11
+ | hammer_cli_foreman_host_reports | 0.0.1+ | 0.1.0+ |
12
+ |---------------------------------|--------|--------|
13
+ | foreman_host_reports | 0.0.4+ | 1.0.0+ |
14
+
15
+ ## Installation
16
+
17
+ $ gem install hammer_cli_foreman_host_reports
18
+
19
+ $ mkdir -p ~/.hammer/cli.modules.d/
20
+
21
+ $ cat <<EOQ > ~/.hammer/cli.modules.d/foreman_host_reports.yml
22
+ :foreman_host_reports:
23
+ :enable_module: true
24
+ EOQ
25
+
26
+ # to confirm things work, this should return useful output
27
+ hammer host-report --help
28
+
29
+ ## More info
30
+
31
+ See our [Hammer CLI installation and configuration instuctions](
32
+ https://github.com/theforeman/hammer-cli/blob/master/doc/installation.md#installation).
@@ -0,0 +1,2 @@
1
+ :foreman_host_reports:
2
+ :enable_module: true
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HammerCLIForemanHostReports
4
+ module CommandExtensions
5
+ class HostReport < HammerCLI::CommandExtensions
6
+ output do |definition, _, command_class|
7
+ definition.append do
8
+ field :id, _('Id')
9
+ field :host_name, _('Host')
10
+ field :reported_at, _('Reported at'), Fields::Date
11
+ field :format, _('Format')
12
+ end
13
+ summary = proc do
14
+ field :change, _('Change')
15
+ field :nochange, _('No change')
16
+ field :failure, _('Failure')
17
+ end
18
+ if command_class.action == :show
19
+ definition.insert(:after, :host_name) do
20
+ field :host_id, _('Host id')
21
+ field :proxy_name, _('Proxy')
22
+ field :proxy_id, _('Proxy id')
23
+ field :keywords, _('Keywords'), Fields::List
24
+ end
25
+ definition.insert(:after, :format) do
26
+ label _('Summary'), id: :summary, &summary
27
+ end
28
+ else
29
+ definition.insert(:after, :format, &summary)
30
+ end
31
+ end
32
+
33
+ before_print do |data, _, command_class|
34
+ if command_class.action == :show
35
+ begin
36
+ parsed = JSON.parse(data['body'])
37
+ data['format'] = parsed['format']&.capitalize
38
+ case parsed['format']
39
+ when 'ansible'
40
+ HammerCLIForemanHostReports::CommandExtensions::HostReport.adjust_for_ansible(command_class, data, parsed)
41
+ when 'puppet'
42
+ HammerCLIForemanHostReports::CommandExtensions::HostReport.adjust_for_puppet(command_class, data, parsed)
43
+ end
44
+ rescue StandardError => e
45
+ command_class.logger.debug("Could not parse report's body: #{e.message}")
46
+ end
47
+ end
48
+ end
49
+
50
+ def self.adjust_for_ansible(command_class, data, parsed)
51
+ command_class.output_definition.insert(:after, :format) do
52
+ field :check_mode, _('Check mode'), Fields::Boolean
53
+ end
54
+ command_class.output_definition.insert(:after, :summary) do
55
+ collection :logs, _('Logs') do
56
+ field :level, _('Level')
57
+ field :task, _('Task')
58
+ field :message, _('Message')
59
+ end
60
+ end
61
+ data['check_mode'] = parsed['check_mode']
62
+ data['logs'] = parsed['results']&.each_with_object([]) do |log, logs|
63
+ logs << {
64
+ level: log['level'],
65
+ task: log['task']['name'],
66
+ message: log['friendly_message']
67
+ }
68
+ end
69
+ end
70
+
71
+ def self.adjust_for_puppet(command_class, data, parsed)
72
+ command_class.output_definition.insert(:after, :format) do
73
+ field :environment, _('Puppet environment')
74
+ end
75
+ command_class.output_definition.insert(:after, :summary) do
76
+ collection :logs, _('Logs') do
77
+ field :level, _('Level')
78
+ field :resource, _('Resource')
79
+ field :message, _('Message')
80
+ end
81
+ end
82
+ data['environment'] = parsed['environment']
83
+ data['logs'] = parsed['logs']&.each_with_object([]) do |log, logs|
84
+ logs << {
85
+ level: log[0],
86
+ resource: log[1],
87
+ message: log[2]
88
+ }
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1 @@
1
+ require 'hammer_cli_foreman_host_reports/command_extensions/host_report'
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HammerCLIForemanHostReports
4
+ class HostReport < HammerCLIForeman::Command
5
+ resource :host_reports
6
+
7
+ class ListCommand < HammerCLIForeman::ListCommand
8
+ build_options
9
+
10
+ extend_with(HammerCLIForemanHostReports::CommandExtensions::HostReport.new)
11
+ end
12
+
13
+ class InfoCommand < HammerCLIForeman::InfoCommand
14
+ build_options
15
+
16
+ extend_with(HammerCLIForemanHostReports::CommandExtensions::HostReport.new)
17
+ end
18
+
19
+ class CreateCommand < HammerCLIForeman::CreateCommand
20
+ success_message _('Host report created.')
21
+ failure_message _('Could not create the host report')
22
+
23
+ build_options
24
+ end
25
+
26
+ class DeleteCommand < HammerCLIForeman::DeleteCommand
27
+ success_message _('Host report deleted.')
28
+ failure_message _('Could not delete the host report')
29
+
30
+ build_options
31
+ end
32
+
33
+ autoload_subcommands
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HammerCLIForemanHostReports
4
+ def self.version
5
+ @version ||= Gem::Version.new '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module HammerCLIForemanHostReports
2
+ require 'hammer_cli'
3
+ require 'hammer_cli_foreman'
4
+
5
+ require 'hammer_cli_foreman_host_reports/version'
6
+ require 'hammer_cli_foreman_host_reports/command_extensions'
7
+ require 'hammer_cli_foreman_host_reports/host_report'
8
+
9
+ HammerCLI::MainCommand.lazy_subcommand(
10
+ 'host-report',
11
+ 'Manage host reports',
12
+ 'HammerCLIForemanHostReports::HostReport',
13
+ 'hammer_cli_foreman_host_reports/host_report'
14
+ )
15
+ end