Class: SystemdServiceCheck::Base

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#argvObject (readonly)

Returns the value of attribute argv.



22
23
24
# File 'lib/systemd_service_check/base.rb', line 22

def argv
  @argv
end

#env_namesObject (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

#resultsObject (readonly)

Returns the value of attribute results.



22
23
24
# File 'lib/systemd_service_check/base.rb', line 22

def results
  @results
end

#serversObject (readonly)

Returns the value of attribute servers.



22
23
24
# File 'lib/systemd_service_check/base.rb', line 22

def servers
  @servers
end

#target_envObject (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_serversObject (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

#runObject



43
44
45
# File 'lib/systemd_service_check/base.rb', line 43

def run
  @results = @target_servers.map { |server| ssh(server) }
end

#to_jsonObject



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