Module: SystemdServiceCheck::Utils
- Included in:
- Base
- Defined in:
- lib/systemd_service_check/utils.rb
Overview
Included in: SystemdServiceCheck::Base
Defined Under Namespace
Classes: InvalidOptionError, Result, Server, Service
Constant Summary collapse
- PROPERTY =
TODO: systemctl show -p
%w[LoadState ActiveState SubState UnitFileState Type].freeze
- PROPERTY_TO_SNAKE_SYM =
PROPERTY.map { |v| Thor::Util.snake_case(v).to_sym }
Instance Method Summary collapse
-
#configure_target_envs(argv, servers) ⇒ Array<String>
Environment list to be processed.
- #configure_target_servers(servers, target_envs, role) ⇒ Array<Utils::Server>
- #servers_from(yaml_filename) ⇒ Array<Utils::Server>
Instance Method Details
#configure_target_envs(argv, servers) ⇒ Array<String>
Returns Environment list to be processed.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/systemd_service_check/utils.rb', line 36 def configure_target_envs(argv, servers) all_envs = servers.map { |s| s[:env] }.uniq target_envs = all_envs & argv # If there is no argument. target_envs = all_envs.first if target_envs.empty? && argv.empty? # If there is only one argument and it is `all`. target_envs = all_envs if argv.size == 1 && argv.first == 'all' Array(target_envs) end |
#configure_target_servers(servers, target_envs, role) ⇒ Array<Utils::Server>
51 52 53 54 |
# File 'lib/systemd_service_check/utils.rb', line 51 def configure_target_servers(servers, target_envs, role) servers.select { |s| target_envs.include?(s[:env]) } .select { |s| role.nil? || role.empty? ? true : s[:role] == role } end |
#servers_from(yaml_filename) ⇒ Array<Utils::Server>
23 24 25 26 27 28 29 30 31 |
# File 'lib/systemd_service_check/utils.rb', line 23 def servers_from(yaml_filename) # rubocop:disable Metrics/AbcSize yaml = JSON.parse(YAML.load_file(yaml_filename).to_json, symbolize_names: true) yaml[:servers].map do |s| raise InvalidOptionError, "ENV: #{s[:env]}" if [s[:password], s[:key]].all?(&:nil?) # rubocop:disable Metrics/LineLength = { password: s[:password], keys: [s[:key] || ""] } Server.new(s[:env], s[:role], s[:ip], s[:user], , s[:services]) end end |