Class: Oxidized::Telnet
Constant Summary
collapse
- RescueFail =
{}
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
#vars
Instance Attribute Details
#telnet ⇒ Object
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
34
35
36
37
38
39
|
# File 'lib/oxidized/input/telnet.rb', line 34
def cmd cmd, expect = @node.prompt
Oxidized.logger.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
|
# 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
login
rescue Timeout::Error
raise PromptUndetect, ['unable to detect prompt:', @node.prompt].join(' ')
end
end
|
#connected? ⇒ Boolean
30
31
32
|
# File 'lib/oxidized/input/telnet.rb', line 30
def connected?
@telnet and not @telnet.sock.closed?
end
|
#output ⇒ Object
45
46
47
|
# File 'lib/oxidized/input/telnet.rb', line 45
def output
@telnet.output
end
|
#send(data) ⇒ Object
41
42
43
|
# File 'lib/oxidized/input/telnet.rb', line 41
def send data
@telnet.write data
end
|