Masato Taruishi
taru****@users*****
2004年 9月 10日 (金) 00:45:14 JST
=================================================================== RCS file: demo/haviewer/haviewer.glade,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- demo/haviewer/haviewer.glade 2004/09/09 13:03:32 1.10 +++ demo/haviewer/haviewer.glade 2004/09/09 15:45:13 1.11 @@ -392,13 +392,13 @@ </child> <child> - <widget class="GtkEntry" id="entry1"> + <widget class="GtkEntry" id="monitor_entry"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="editable">True</property> <property name="visibility">True</property> <property name="max_length">0</property> - <property name="text" translatable="yes">cn=test,o=ultrapossum</property> + <property name="text" translatable="yes">cn=u0001,o=ultrapossum</property> <property name="has_frame">True</property> <property name="invisible_char" translatable="yes">*</property> <property name="activates_default">False</property> =================================================================== RCS file: demo/haviewer/haviewer.rb,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- demo/haviewer/haviewer.rb 2004/09/09 14:55:09 1.22 +++ demo/haviewer/haviewer.rb 2004/09/09 15:45:13 1.23 @@ -95,11 +95,6 @@ class 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" - def initialize( host, type ) super(); @host = host; @@ -108,51 +103,12 @@ @type = type 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) - + def update end attr_reader :row, :host, :sign - attr_accessor :type, :status, :pid, :since - + attr_accessor :type + end class View @@ -166,46 +122,121 @@ end class UltraPossum < View - - Column = ["S", "Host", "Type", "Status", "Pid", "Since" ] + + class UltraPossumHost < Host - def initialize(haview) - super - @list = Gtk::ListStore.new( String, String, String, String, String, String) - @columns = [] - Column.size.times do |i| - @columns << Gtk::TreeViewColumn.new(Column[i], Gtk::CellRendererText.new, { :markup => i }) + OID = "private.12345" # .2.101.1" + OID_STATUS = OID + ".1.1.0" + OID_PID = OID + ".1.2.0" + OID_SINCE = OID + ".1.3.0" + + def update + snmp + monitor_entry + end + + def monitor_entry + @entryCSN = "" + `ldapsearch -x -h #{@host} -b cn=u0001,o=ultrapossum -s base -LLL +`.each_line do |line| + case line + when /entryCSN: (.+)/ + @entryCSN = $1 + end + 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 - @row = {} - hash = {} - `ultrapossum-config get MASTER BACKUP SYNCBACKUPS`.each_line do |line| - host = nil - case line - when /(MASTER|BACKUP|SYNCBACKUPS)="(.+)"\n/ - $2.split(' ').each do |s| - host = Host.new(s,"master") + + attr_accessor :status, :pid, :since, :entryCSN + + end + + UltraPossumHosts = [] + begin + hash = {} + `ultrapossum-config get MASTER BACKUP SYNCBACKUPS`.each_line do |line| + host = nil + case line + when /(MASTER|BACKUP|SYNCBACKUPS)="(.+)"\n/ + $2.split(' ').each do |s| + host = UltraPossumHost.new(s,"master") if hash[s].nil? - @row[host] =****@list***** - Hosts << host + UltraPossumHosts << host + Hosts << host hash[s] = host end end - end - end + end + end `ultrapossum-config get SLAVES`.each_line do |line| host = nil case line when /SLAVES="(.+)"\n/ $1.split(' ').each do |s| - host = Host.new(s,"slave") + host = UltraPossumHost.new(s,"slave") if hash[s].nil? @row[host] =****@list***** - Hosts << host + UltraPossumHosts << host + Hosts << host hash[s] = host end end end end + end + + Column = ["S", "Host", "Type", "Status", "Pid", "Since" ] + + def initialize(haview) + super + @list = Gtk::ListStore.new( String, String, String, String, String, String) + @columns = [] + Column.size.times do |i| + @columns << Gtk::TreeViewColumn.new(Column[i], Gtk::CellRendererText.new, { :markup => i }) + end + @row = {} + UltraPossumHosts.each do |host| + @row[host] =****@list***** + end @master_icon = Signal::SignalFactory.create @slave_icon = Signal::SignalFactory.create columns.each do |val| @@ -227,7 +258,7 @@ def summary master = "" slave = "" - Hosts.each do |h| + UltraPossumHosts.each do |h| if h.type == "master" case h.status when "ACTIVE" @@ -262,23 +293,33 @@ attr_reader :list, :columns - end - - class UltraPossumTest < View + class EntryView < View - Column = ["S", "Host", "Type", "Status", "entryCSN" ] + Column = ["S", "Host", "Type", "Status", "entryCSN" ] - def initialize(haview) - super - @list = Gtk::ListStore.new( String, String, String, String, String ) - @columns = [] - Column.size.times do |i| - @columns << Gtk::TreeViewColumn.new(Column[i], Gtk::CellRendererText.new, { :markup => i }) - end - @columns.each do |val| - @glade["treeview2"].append_column(val) + def initialize(haview) + super + @list = Gtk::ListStore.new( String, String, String, String, String ) + @columns = [] + Column.size.times do |i| + @columns << Gtk::TreeViewColumn.new(Column[i], Gtk::CellRendererText.new, { :markup => i }) + end + @row = {} + UltraPossumHosts.each do |host| + @row[host] =****@list***** + end + @columns.each do |val| + @glade["treeview2"].append_column(val) + end + @glade["treeview2"].set_model(@list) end - @glade["treeview2"].set_model(@list) + + def update(host) + @list.set_value(@row[host], 1, host.host) + @list.set_value(@row[host], 2, host.type) + @list.set_value(@row[host], 4, host.entryCSN) + end + end end @@ -310,7 +351,7 @@ haview = HAViewer.new('haviewer.glade') haview.add_view( HAViewer::View::UltraPossum.new(haview) ) -haview.add_view( HAViewer::View::UltraPossumTest.new(haview) ) +haview.add_view( HAViewer::View::UltraPossum::EntryView.new(haview) ) haview.update HAViewer::Hosts.each do |host| haview.views.each do |view| @@ -318,7 +359,7 @@ end Thread.new { while(1) do - host.snmp + host.update haview.views.each do |view| view.update(host) haview.update