BUFFALO WBR-G54 54Mbps無線LAN AirStation を使っている。 Muninで 監視しようと思ったのだが、昔、MRTGで監視させたときは、しばらくすると管理画面に アクセスできなくなるという問題があって、あきらめたのだった。
定期的に再起動させればなんとかなるだろう、ということで、
Rubyの勉強もかねて
再起動のスクリプトを書いてみる。
#!/usr/bin/env ruby
require 'net/http'
require 'rubygems'
require 'hpricot'
require 'pp'
host = '127.0.0.1'
userid = 'root'
userpw = 'toor'
Net::HTTP.version_1_2
top_path = '/'
check_client_path = '/advance/ad-admin-client.htm'
reboot_path = '/advance/apply.cgi?action=Reboot'
logout_path = '/advance/apply.cgi?action=Logout'
res = 1 # The return code meaning error
Net::HTTP.start(host) {|http|
# 1st access is the dummy.
req = Net::HTTP::Get.new(top_path)
req.basic_auth(userid, userpw)
response = http.request(req)
req = Net::HTTP::Get.new(check_client_path)
req.basic_auth(userid, userpw)
response = http.request(req)
case response
when Net::HTTPSuccess then
doc = Hpricot(response.body).at(:table)
if doc and (doc.containers.length == 1)
# Only header line is exist. No clients are connected.
req = Net::HTTP::Get.new(reboot_path)
req.basic_auth(userid, userpw)
response = http.request(req)
case response
when Net::HTTPSuccess then
res = 0
else
pp response
end
else
print 'There are some clients connected. Reboot was canceled.\n'
end
else
pp response
end
if res == 1
req = Net::HTTP::Get.new(logout_path)
req.basic_auth(userid, userpw)
response = http.request(req)
end
}
res # Return code
BUFFALO WBR-G54 54Mbps無線LAN AirStation
posted with amazlet on 08.01.13
バッファロー (2003/01/31)
売り上げランキング: 6358
売り上げランキング: 6358