Last active
August 29, 2015 14:27
-
-
Save gabtastic/02e0e34e9f595448ba1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# This script remotely logs into a Ruckus Zone Director and output sysinfo to json | |
# | |
require 'pty' | |
require 'expect' | |
require 'json' | |
require 'timeout' | |
password = ARGV.shift || 'ihintl' | |
username = 'admin' | |
$expect_verbose=false | |
@info = {} | |
def harvest_info(buffers) | |
wan = '' | |
arr = {} | |
buffers.each do |buffer| | |
buffer.lines.each do |line| | |
if line.match(/ Connection Name.*/) | |
a = line.chop.strip | |
key,value = a.split ': ',2 | |
arr[value] = [] | |
wan = value | |
elsif line.match(/.*: .*/) | |
a = line.chop.strip | |
key,value = a.split ': ',2 | |
if wan != '' | |
arr[wan].concat([key.strip=>value]) | |
elsif | |
arr[key.strip] = value | |
end | |
end | |
end | |
end | |
@info.merge(arr) | |
end | |
peplinkip = '' | |
#peplinkip = `mysql --skip-column-names -e "select device_ip from devices where device_id = 'Peplink' and device_type='server';" LineAdmin` | |
peplinkip = '192.168.1.1' | |
if !peplinkip.empty? | |
@info = {"peplinkip" => peplinkip.chomp} | |
begin | |
status = Timeout::timeout(10) do | |
PTY.spawn("sshpass -p 'Sderkl123' ssh -p 10022 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no admin@#{peplinkip}") do |ssh_out, ssh_in, pid| | |
begin | |
ssh_out.expect(/> /) do |r| | |
ssh_in.printf("get system\n\n") | |
end | |
ssh_out.expect(/^> /) do |r| | |
@info = harvest_info(r) | |
end | |
ssh_out.expect(/> /) do |r| | |
ssh_in.printf("get wan\n\n") | |
end | |
ssh_out.expect(/^> /) do |r| | |
@info = harvest_info(r) | |
end | |
ssh_in.printf("exit\n\n") | |
puts @info.to_json | |
rescue Errno::EIO | |
#maybe add an error message | |
errormsg = { "error" => "ssh not available"} | |
puts @info.merge(errormsg).to_json | |
end | |
end | |
end | |
rescue Timeout::Error | |
puts @info.to_json | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment