Class: Oxidized::Telnet

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

Constant Summary collapse

RescueFail =
{}.freeze

Instance Attribute Summary collapse

Attributes included from Input::CLI

#node

Instance Method Summary collapse

Methods included from Input::CLI

#connect_cli, #disconnect_cli, #get, #initialize, #login, #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_str, expect = @node.prompt) ⇒ Object



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

def cmd(cmd_str, expect = @node.prompt)
  return send(cmd_str + "\r\n") unless expect

  Oxidized.logger.debug "Telnet: #{cmd_str} @#{@node.name}"
  args = { 'String'  => cmd_str,
           'Match'   => expect,
           'Timeout' => @timeout }
  @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
# File 'lib/oxidized/input/telnet.rb', line 9

def connect(node)
  @node    = node
  @timeout = Oxidized.config.timeout
  @node.model.cfg['telnet'].each { |cb| instance_exec(&cb) }
  @log = File.open(Oxidized::Config::Log + "/#{@node.ip}-telnet", 'w') if Oxidized.config.input.debug?
  port = vars(:telnet_port) || 23

  telnet_opts = {
    'Host'    => @node.ip,
    'Port'    => port.to_i,
    'Timeout' => @timeout,
    'Model'   => @node.model,
    'Log'     => @log
  }

  @telnet = Net::Telnet.new telnet_opts
  begin
    
  rescue Timeout::Error
    raise PromptUndetect, ['unable to detect prompt:', @node.prompt].join(' ')
  end
  connected?
end

#connected?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/oxidized/input/telnet.rb', line 33

def connected?
  @telnet && (not @telnet.sock.closed?)
end

#outputObject



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

def output
  @telnet.output
end

#send(data) ⇒ Object



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

def send(data)
  @telnet.write data
end