Class: SystemdServiceCheck::Base

Inherits:
Object
  • Object
show all
Includes:
SSH, Utils
Defined in:
lib/systemd_service_check.rb

Overview

Base

Constant Summary

Constants included from Utils

Utils::PROPERTY, Utils::PROPERTY_TO_SNAKE_SYM

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SSH

#hostname, #ssh, #systemctl_show

Methods included from Utils

#configure_target_envs, #configure_target_servers, #servers_from

Constructor Details

#initialize(envs, yaml, role = nil) ⇒ Base

Returns a new instance of Base.

Parameters:

  • envs (Arrat<String>)
  • yaml (String)
  • role (String) (defaults to: nil)

Raises:



24
25
26
27
28
29
30
31
32
33
# File 'lib/systemd_service_check.rb', line 24

def initialize(envs, yaml, role = nil)
  raise Utils::InvalidOptionError, "Argument `yaml` must not be blank." if blank? yaml

  @envs           = envs || []
  @role           = role.nil? || role.empty? ? nil : role
  @servers        = servers_from(yaml)
  @target_envs    = configure_target_envs(envs, @servers)
  @target_servers = configure_target_servers(@servers, @target_envs, @role)
  @results        = []
end

Instance Attribute Details

#envsObject (readonly)

Returns the value of attribute envs.



19
20
21
# File 'lib/systemd_service_check.rb', line 19

def envs
  @envs
end

#resultsObject (readonly)

Returns the value of attribute results.



19
20
21
# File 'lib/systemd_service_check.rb', line 19

def results
  @results
end

#roleObject (readonly)

Returns the value of attribute role.



19
20
21
# File 'lib/systemd_service_check.rb', line 19

def role
  @role
end

#serversObject (readonly)

Returns the value of attribute servers.



19
20
21
# File 'lib/systemd_service_check.rb', line 19

def servers
  @servers
end

#target_envsObject (readonly)

Returns the value of attribute target_envs.



19
20
21
# File 'lib/systemd_service_check.rb', line 19

def target_envs
  @target_envs
end

#target_serversObject (readonly)

Returns the value of attribute target_servers.



19
20
21
# File 'lib/systemd_service_check.rb', line 19

def target_servers
  @target_servers
end

Instance Method Details

#runObject



35
36
37
# File 'lib/systemd_service_check.rb', line 35

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

#to_jsonObject



39
40
41
42
43
44
# File 'lib/systemd_service_check.rb', line 39

def to_json
  @results.map do |result|
    { server:   result.server.to_h,
      services: result.services.map(&:to_h) }
  end.to_json
end