Class: SystemdServiceCheck::Base
- Inherits:
-
Object
- Object
- SystemdServiceCheck::Base
- Defined in:
- lib/systemd_service_check/base.rb
Overview
Base
Defined Under Namespace
Classes: InvalidOption, Result, Server, Service
Constant Summary collapse
- STATES =
TODO: systemctl show -p
%w[LoadState ActiveState SubState UnitFileState Type].freeze
- SHOW_GREP =
TODO: setting by yaml
/env/i
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#env_names ⇒ Object
readonly
Returns the value of attribute env_names.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#servers ⇒ Object
readonly
Returns the value of attribute servers.
-
#target_env ⇒ Object
readonly
Returns the value of attribute target_env.
-
#target_servers ⇒ Object
readonly
Returns the value of attribute target_servers.
Instance Method Summary collapse
-
#initialize(argv, yaml) ⇒ Base
constructor
A new instance of Base.
- #run ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(argv, yaml) ⇒ Base
Returns a new instance of Base.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/systemd_service_check/base.rb', line 24 def initialize(argv, yaml) @argv = argv || [] @env_names = [] @servers = [] @target_env = [] @target_servers = [] @results = [] raise InvalidOption if yaml.nil? || yaml.empty? load_settings(yaml) configure_target_servers run rescue InvalidOption => e puts "<#{e}>", " Argument yaml must not be nil or empty.", " yaml.class: [#{yaml.class}]" puts " #{e.backtrace_locations.first}" end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
22 23 24 |
# File 'lib/systemd_service_check/base.rb', line 22 def argv @argv end |
#env_names ⇒ Object (readonly)
Returns the value of attribute env_names.
22 23 24 |
# File 'lib/systemd_service_check/base.rb', line 22 def env_names @env_names end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
22 23 24 |
# File 'lib/systemd_service_check/base.rb', line 22 def results @results end |
#servers ⇒ Object (readonly)
Returns the value of attribute servers.
22 23 24 |
# File 'lib/systemd_service_check/base.rb', line 22 def servers @servers end |
#target_env ⇒ Object (readonly)
Returns the value of attribute target_env.
22 23 24 |
# File 'lib/systemd_service_check/base.rb', line 22 def target_env @target_env end |
#target_servers ⇒ Object (readonly)
Returns the value of attribute target_servers.
22 23 24 |
# File 'lib/systemd_service_check/base.rb', line 22 def target_servers @target_servers end |
Instance Method Details
#run ⇒ Object
43 44 45 |
# File 'lib/systemd_service_check/base.rb', line 43 def run @results = @target_servers.map { |server| ssh(server) } end |
#to_json ⇒ Object
47 48 49 50 51 52 |
# File 'lib/systemd_service_check/base.rb', line 47 def to_json @results.map do |result| { server: result.server.to_h, services: result.services.map(&:to_h) } end.to_json end |