Class: Oxidized::Telnet

Inherits:
Input
  • Object
show all
Includes:
Input::CLI
Defined in:
lib/oxidized/input/telnet.rb

Constant Summary collapse

RescueFail =
{}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Input::CLI

#connect_cli, #disconnect_cli, #get, #initialize, #password, #post_login, #pre_logout, #username

Methods included from Config::Vars

#vars

Instance Attribute Details

#telnetObject (readonly)

Returns the value of attribute telnet.



7
8
9
# File 'lib/oxidized/input/telnet.rb', line 7

def telnet
  @telnet
end

Instance Method Details

#cmd(cmd, expect = @node.prompt) ⇒ Object



39
40
41
42
43
44
# File 'lib/oxidized/input/telnet.rb', line 39

def cmd cmd, expect=@node.prompt
  Log.debug "Telnet: #{cmd} @#{@node.name}"
  args = { 'String' => cmd }
  args.merge!({ 'Match' => expect, 'Timeout' => @timeout }) if expect
  @telnet.cmd args
end

#connect(node) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/oxidized/input/telnet.rb', line 9

def connect node
  @node    = node
  @timeout = CFG.timeout
  @node.model.cfg['telnet'].each { |cb| instance_exec(&cb) }
  port = vars(:telnet_port) || 23

  opt = { 'Host'    => @node.ip,
          'Port'    => port.to_i,
          'Timeout' => @timeout,
          'Model'   => @node.model }
  opt['Output_log'] = Oxidized::Config::Crash + "-#{@node.ip}-telnet" if CFG.input.debug?

  @telnet  = Net::Telnet.new opt
  if @node.auth[:username] and @node.auth[:username].length > 0
    expect username
    @telnet.puts @node.auth[:username]
  end
  expect password
  @telnet.puts @node.auth[:password]
  begin
    expect @node.prompt
  rescue Timeout::Error
    raise PromptUndetect, [ 'unable to detect prompt:', @node.prompt ].join(' ')
  end
end

#connected?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/oxidized/input/telnet.rb', line 35

def connected?
  @telnet and not @telnet.sock.closed?
end

#outputObject



50
51
52
# File 'lib/oxidized/input/telnet.rb', line 50

def output
  @telnet.output
end

#send(data) ⇒ Object



46
47
48
# File 'lib/oxidized/input/telnet.rb', line 46

def send data
  @telnet.write data
end