class Miab

usage: puts Miab.new(“temperature”, domain: 'home', target: 'angelo',

user: 'pi', password: 'secret').cast

nearest SSH equivalent `ssh pi@angelo.home exec \

"cat /sys/class/thermal/thermal_zone0/temp"`

Public Class Methods

new(scroll, domain: nil, target: nil, pwlist: {}, password: nil, user: nil, debug: false, dns: '208.67.222.222') click to toggle source
# File lib/miab.rb, line 306
def initialize(scroll, domain: nil, target: nil, pwlist: {}, password: nil, 
  user: nil, debug: false, dns: '208.67.222.222')

  @results = {}

  @scroll, @debug, @dns = scroll, debug, dns
  
  puts '@dns: ' + @dns.inspect if @debug
  
  target = [target] if target.is_a? String

  @nodes = if target then

    target = [target] if target.is_a? String

    target.inject({}) do |r,x|
      host = domain ? x + '.' + domain : x
      passwd = pwlist[x] || password
      userhost = user ? user + '@' + host : host
      r.merge({userhost => passwd})
    end

  else
    {}
  end
end

Public Instance Methods

cast() click to toggle source

cast out the thing and hope for the best

# File lib/miab.rb, line 335
def cast()

  if @nodes.any? then
    
    threads = []
    dns = @dns

    @nodes.each do |raw_host, password|
      
      host, user = raw_host.split(/@/,2).reverse
      @results[host] = {}
      
      threads << Thread.new do
        begin
          puts ('host: ' + host.inspect).debug if @debug
          ssh = Net::SSH.start( host, user, password: password)
          @results[host] = Session.new(host, ssh, dns: dns, debug: @debug).exec @scroll
          ssh.close
          puts (host + ' result: ' + @results[host].inspect).debug if @debug
        rescue
          @results[host] = nil
        end
      end
      
    end      

    threads.each(&:join)

  else
    
    if @scroll then
      host = `hostname`.chomp
      @results[host] = Session.new(host, dns: @dns, debug: @debug).exec(@scroll)
    end
    
  end

  @scroll = nil
  @results
end