Masato Taruishi
taru****@users*****
2004年 9月 16日 (木) 15:04:43 JST
=================================================================== RCS file: demo/haviewer/lib/haviewer/haviewer.rb,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- demo/haviewer/lib/haviewer/haviewer.rb 2004/09/15 09:24:36 1.4 +++ demo/haviewer/lib/haviewer/haviewer.rb 2004/09/16 06:04:43 1.5 @@ -164,7 +164,7 @@ $haview.add_view( "status", HAViewer::UltraPossum.new($haview) ) $haview.add_view( "entry", HAViewer::UltraPossum::EntryView.new($haview) ) $haview.add_view( "config", HAViewer::UltraPossum::ConfigView.new($haview) ) -$haview.glade["dialog1"].set_title( "UltraPossum HA Viewer (#{HAViewer::UltraPossum::Conf["ORGANIZATION"]})" ) +$haview.glade["dialog1"].set_title( "UltraPossum HA Viewer (#{HAViewer::UltraPossumHost.conf["ORGANIZATION"]})" ) $haview.update HAViewer::Hosts.each do |host| $haview.views.each do |name,view| =================================================================== RCS file: demo/haviewer/lib/haviewer/ultrapossum.rb,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- demo/haviewer/lib/haviewer/ultrapossum.rb 2004/09/15 09:24:36 1.8 +++ demo/haviewer/lib/haviewer/ultrapossum.rb 2004/09/16 06:04:43 1.9 @@ -1,157 +1,163 @@ -require 'open3' require 'ultrapossum' class HAViewer - class UltraPossum < HAViewer::View - - Conf = ::UltraPossum::Config.new - - class UltraPossumHost < Host + class UltraPossumHost < Host - OID = "private.12345" # .2.101.1" - OID_STATUS = OID + ".1.1.0" - OID_PID = OID + ".1.2.0" - OID_SINCE = OID + ".1.3.0" - - @@latest_entryCSN = "" - @@monitored_entry = "cn=u0001,#{Conf["SUFFIX"]}" - - def UltraPossumHost.update_latest_entryCSN - `ldapsearch -l 1 -x -h #{Conf["LDAPMASTER"]} -b #{@@monitored_entry} -s base -LLL +`.each_line do |line| - case line - when /entryCSN: (.+)/ - @@latest_entryCSN = $1 - end + OID = "private.12345" # .2.101.1" + OID_STATUS = OID + ".1.1.0" + OID_PID = OID + ".1.2.0" + OID_SINCE = OID + ".1.3.0" + + @@conf = ::UltraPossum::Config.new + @@latest_entryCSN = "" + @@monitored_entry = "cn=u0001,#{@@conf["SUFFIX"]}" + + def UltraPossumHost.update_latest_entryCSN + `ldapsearch -l 1 -x -h #{UltraPossumHost.conf["LDAPMASTER"]} -b #{@@monitored_entry} -s base -LLL +`.each_line do |line| + case line + when /entryCSN: (.+)/ + @@latest_entryCSN = $1 end - UltraPossumHosts.each do |host| - case host.entryCSN - when "" - host.repl_sign.off - when @@latest_entryCSN - host.repl_sign.on(Green) - else - host.repl_sign.on(Yellow) - end + end + UltraPossumHosts.each do |host| + case host.entryCSN + when "" + host.repl_sign.off + when @@latest_entryCSN + host.repl_sign.on(Green) + else + host.repl_sign.on(Yellow) end end + end - def UltraPossumHost.monitored_entry - @@monitored_entry - end - - def UltraPossumHost.latest_entryCSN - @@latest_entryCSN - end + def UltraPossumHost.monitored_entry + @@monitored_entry + end + + def UltraPossumHost.latest_entryCSN + @@latest_entryCSN + end - def initialize( host, type ) - super - @entryCSN = "" - end + def UltraPossumHost.conf + return @@conf + end - def update - snmp - monitor_entry - end + def UltraPossumHost.set_conf( conf ) + @@conf = conf + end - def monitor_entry - @entryCSN = "" - return if ! avail? - `ldapsearch -l 1 -x -h #{@host} -b #{@@monitored_entry} -s base -LLL +`.each_line do |line| - case line - when /entryCSN: (.+)/ - @entryCSN = $1 - end - end - case @entryCSN - when "" - @repl_sign.off - when @@latest_entryCSN - @repl_sign.on(Green) - else - @repl_sign.on(Red) - end + def initialize( host, type ) + super + @entryCSN = "" + end + + def update + snmp + monitor_entry + end + + def monitor_entry + @entryCSN = "" + return if ! avail? + `ldapsearch -l 1 -x -h #{@host} -b #{@@monitored_entry} -s base -LLL +`.each_line do |line| + case line + when /entryCSN: (.+)/ + @entryCSN = $1 + end + end + case @entryCSN + when "" + @repl_sign.off + when @@latest_entryCSN + @repl_sign.on(Green) + else + @repl_sign.on(Red) end + end - def snmp - statusbuf = nil - pidbuf = nil - sincebuf = nil - puts "snmpget -v1 -t 3 -c ultrapossum #{@host} #{OID_STATUS} #{OID_PID} #{OID_SINCE}" if $DEBUG - buf = `snmpget -v1 -t 3 -c ultrapossum #{@host} #{OID_STATUS} #{OID_PID} #{OID_SINCE}` - buf.each_line do |line| - case line - when /#{OID_STATUS}/ - statusbuf = line.gsub(/^[^"]+"(.*)"\n/, '\1') - statusbuf = "-----" if statusbuf.size == 0 - when /#{OID_PID}/ - pidbuf = line.gsub(/^[^"]+"(.*)"\n/, '\1') - pidbuf = "-----" if pidbuf.size == 0 - when /#{OID_SINCE}/ - sincebuf = line.gsub(/^[^"]+"(.*)"\n/, '\1') - sincebuf = "-----" if sincebuf.size == 0 - end - end - @status = statusbuf - @pid = pidbuf - @since = sincebuf - - c = "" - case @status - when "DEAD" - c = Red - when "STOP" - c = Red - when "ACTIVE" - c = Green - when "FAOVER" - c = Yellow - when "STANDBY" - c = Green - when "RUN" - c = Green - end - @sign.on(c) - end - - def avail? - return true if @status == "STANDBY" || @status == "ACTIVE" || @status == "RUN" - return false - end - - attr_accessor :status, :pid, :since, :entryCSN + def snmp + statusbuf = nil + pidbuf = nil + sincebuf = nil + puts "snmpget -v1 -t 3 -c ultrapossum #{@host} #{OID_STATUS} #{OID_PID} #{OID_SINCE}" if $DEBUG + buf = `snmpget -v1 -t 3 -c ultrapossum #{@host} #{OID_STATUS} #{OID_PID} #{OID_SINCE}` + buf.each_line do |line| + case line + when /#{OID_STATUS}/ + statusbuf = line.gsub(/^[^"]+"(.*)"\n/, '\1') + statusbuf = "-----" if statusbuf.size == 0 + when /#{OID_PID}/ + pidbuf = line.gsub(/^[^"]+"(.*)"\n/, '\1') + pidbuf = "-----" if pidbuf.size == 0 + when /#{OID_SINCE}/ + sincebuf = line.gsub(/^[^"]+"(.*)"\n/, '\1') + sincebuf = "-----" if sincebuf.size == 0 + end + end + @status = statusbuf + @pid = pidbuf + @since = sincebuf + + c = "" + case @status + when "DEAD" + c = Red + when "STOP" + c = Red + when "ACTIVE" + c = Green + when "FAOVER" + c = Yellow + when "STANDBY" + c = Green + when "RUN" + c = Green + end + @sign.on(c) + end + def avail? + return true if @status == "STANDBY" || @status == "ACTIVE" || @status == "RUN" + return false end - UltraPossumHosts = [] - begin - hash = {} - ary = [ Conf["MASTER"], Conf["BACKUP"], Conf["SYNCBACKUPS"] ] - ary.each do |val| - next if val.nil? - host = nil - val.split(' ').each do |s| - host = UltraPossumHost.new(s,"master") - if hash[s].nil? - UltraPossumHosts << host - Hosts << host - hash[s] = host - end + attr_accessor :status, :pid, :since, :entryCSN + + end + + UltraPossumHosts = [] + begin + hash = {} + ary = [ UltraPossumHost.conf["MASTER"], UltraPossumHost.conf["BACKUP"], UltraPossumHost.conf["SYNCBACKUPS"] ] + ary.each do |val| + next if val.nil? + host = nil + val.split(' ').each do |s| + host = UltraPossumHost.new(s,"master") + if hash[s].nil? + UltraPossumHosts << host + Hosts << host + hash[s] = host end end - if ! Conf["SLAVES"].nil? - Conf["SLAVES"].split(' ').each do |s| - host = UltraPossumHost.new(s,"slave") - if hash[s].nil? - UltraPossumHosts << host - Hosts << host - hash[s] = host - end + end + if ! UltraPossumHost.conf["SLAVES"].nil? + UltraPossumHost.conf["SLAVES"].split(' ').each do |s| + host = UltraPossumHost.new(s,"slave") + if hash[s].nil? + UltraPossumHosts << host + Hosts << host + hash[s] = host end end end - UltraPossumHost.update_latest_entryCSN + end + UltraPossumHost.update_latest_entryCSN + class UltraPossum < HAViewer::View + Column = ["S", "Host", "Type", "Status", "Pid", "Since" ] def initialize(haview) @@ -237,7 +243,7 @@ STDERR.reopen(pe[1]) pe[1].close - exec("ldapmodify -x -h #{Conf["LDAPMASTER"]} -D #{Conf["ROOTDN"]} -w #{Conf["ROOTPW"]}") + exec("ldapmodify -x -h #{UltraPossumHost.conf["LDAPMASTER"]} -D #{UltraPossumHost.conf["ROOTDN"]} -w #{UltraPossumHost.conf["ROOTPW"]}") } pw[0].close @@ -314,10 +320,10 @@ @columns << Gtk::TreeViewColumn.new(Column[i], Gtk::CellRendererText.new, { :markup => i }) end @row = {} - Conf.keys.sort.each do |key| + UltraPossumHost.conf.keys.sort.each do |key| @row[key] =****@list***** @list.set_value(@row[key], 0, key ) - @list.set_value(@row[key], 1, Conf[key] ) + @list.set_value(@row[key], 1, UltraPossumHost.conf[key] ) end @columns.each do |val| @glade["treeview3"].append_column(val)