Class: HammerCLIForeman::CommandExtensions::Ping
- Inherits:
-
HammerCLI::CommandExtensions
- Object
- HammerCLI::CommandExtensions
- HammerCLIForeman::CommandExtensions::Ping
- Defined in:
- lib/hammer_cli_foreman/command_extensions/ping.rb
Class Method Summary collapse
- .check_for_unrecognized(plugins, output_definition) ⇒ Object
- .failed?(services) ⇒ Boolean
- .format_cache(cache) ⇒ Object
Class Method Details
.check_for_unrecognized(plugins, output_definition) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/hammer_cli_foreman/command_extensions/ping.rb', line 27 def self.check_for_unrecognized(plugins, output_definition) failed = plugins.select { |_, data| data['services'] } .each_with_object([]) { |(_, d), s| s << d['services'] } .reduce({}, :merge) .select do |name, data| begin output_definition.find_field(name) false rescue ArgumentError data['status'] == _('FAIL') end end return if failed.empty? warn [_('%{count} more service(s) failed, but not shown:') % { count: failed.size }, failed.keys.join(', '), ''].join("\n") end |
.failed?(services) ⇒ Boolean
46 47 48 49 |
# File 'lib/hammer_cli_foreman/command_extensions/ping.rb', line 46 def self.failed?(services) services['foreman']['database']['active'] == 'FAIL' || services.each_value.any? { |s| s['status'] == _('FAIL') } end |
.format_cache(cache) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hammer_cli_foreman/command_extensions/ping.rb', line 15 def self.format_cache(cache) servers = cache['servers'].map do |server| { status: server['status'], duration_ms: _('Duration: %sms') % server['duration_ms'] } end { 'servers': servers } end |