I did this very hackily (to get dhcp table info out of some switches) by
writing two small scripts on my zenoss box...
First, an Expect script that handles the telnet login and pulls the data:
Code:
#!/usr/bin/expect
set target [lrange $argv 0 0]
spawn telnet $target
#LOGIN
expect -re "Username:" {send "username\r"}
expect -re "Password:" {send "password\r"}
expect ">" {send "enable\r"}
expect "Password:" {send "password\r"}
expect "#" {send "sho ip dhcp-server binding\r\r\r"}
expect "#" {send "logout\r"}
Then, a ruby script which parses that data and makes it zenoss friendly:
Code:
#!/usr/bin/ruby -w
#include hash of pool sizes
require '/usr/local/zenoss/zendhcp/total_hash.rb'
#grab hostname from command line argument
HOSTNAME = ARGV[0]
#get dhcp table from switch using expect script
exec("/usr/local/zenoss/common/libexec/expect_script.sh "+HOSTNAME+" |sed
'/spawn/,/binding/d;/^$/d' >
/usr/local/zenoss/zendhcp/"+HOSTNAME+".dhcpbindings.out") if fork.nil?
Process.wait
#count lines in dhcp table
file_out = File.new("/usr/local/zenoss/zendhcp/"+HOSTNAME+".dhcpbindings.out",
"r")
lines = -1
file_out.each_line do |line|
lines += 1
end
#get pool size for host
dtot = Total_hash[HOSTNAME]
#get available ips
ava = dtot.to_i-lines
#print the shit
puts "SWITCH-DHCP OK|leases="+lines.to_s+" total="+dtot.to_s+" avail="+ava.to_s
Then I just call the ruby script using zencommand. It works fine, but it's
really pretty ugly, e.g. I wrote the username/password in the script. Theyre
low security devices in my case so I dont care... telnet is completely insecure
anyway.
Hope this helps...
-------------------- m2f --------------------
Read this topic online here:
http://forums.zenoss.com/viewtopic.php?p=36862#36862
-------------------- m2f --------------------
_______________________________________________
zenoss-users mailing list
[email protected]
http://lists.zenoss.org/mailman/listinfo/zenoss-users