module SystemdServiceCheck::SSH

SSH

Public Instance Methods

hostname(ssh) click to toggle source

@param ssh [Net::SSH::Connection::Session] @return [String]

# File lib/systemd_service_check/ssh.rb, line 21
def hostname(ssh)
  ssh.exec!('hostname').chomp
end
ssh(server) click to toggle source

@param server [Utils::Server] @return [Utils::Result]

# File lib/systemd_service_check/ssh.rb, line 7
def ssh(server)
  services = []
  Net::SSH.start(*server.conn_info) do |ssh|
    server[:hostname] = hostname(ssh)
    services =
      server[:services].map { |service_name| systemctl_show(ssh, service_name) }
    # TODO: store in Result object
    # puts ssh.exec!("systemctl list-timers")
  end
  Utils::Result.new(server, services)
end
systemctl_show(ssh, service_name) click to toggle source

@param ssh [Net::SSH::Connection::Session] @param service_name [String] @return [Utils::Service]

# File lib/systemd_service_check/ssh.rb, line 28
def systemctl_show(ssh, service_name)
  prop = ssh.exec!("systemctl show #{service_name} -p #{Utils::PROPERTY.join(",")}")
  Utils::Service.new(service_name, *split_property(prop))
end

Private Instance Methods

split_property(property) click to toggle source
# File lib/systemd_service_check/ssh.rb, line 35
def split_property(property)
  ret = property.split("\n")
                .map { |v| v.split("=") }
                .map { |(v1, v2)| [Thor::Util.snake_case(v1).to_sym, v2] }
                .each_with_object({}) { |(k, v), memo| memo[k] = v }

  Utils::PROPERTY_TO_SNAKE_SYM.map { |k| ret[k] }
end