Masato Taruishi
taru****@sourc*****
2004年 6月 21日 (月) 20:56:05 JST
=================================================================== RCS file: demo/haviewer/haviewer.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- demo/haviewer/haviewer.rb 2004/06/21 08:30:23 1.1 +++ demo/haviewer/haviewer.rb 2004/06/21 11:56:05 1.2 @@ -1,6 +1,6 @@ #!/usr/bin/env ruby - +require 'uconv' require 'libglade2' def on_close_clicked @@ -9,17 +9,20 @@ class HAViewer - Column = ["S", "Host", "Type", "Status", "Pid", "Since" ] + Column = ["S", "Host", "Type", "Status", "Pid", "Since", "I" ] Hosts = [] OID = "private.12345" # .2.101.1" class Host - def initialize( host, viewer ) + def initialize( host, type, viewer ) super(); @host = host; @viewer = viewer @list = viewer.list @row =****@list***** + @color = "green" + @status = "" + @type = type update @t = Thread.new { while(1) do @@ -31,7 +34,30 @@ } end + def _coloring(buf, color) + return "<span foreground=\"#{color}\"><tt>#{buf}</tt></span>" + end + + def _icon + on = _coloring(Uconv.euctou8("●"), @color); + off_g = _coloring(Uconv.euctou8("●"), "#007700" ); + off_y = _coloring(Uconv.euctou8("●"), "#777700" ); + off_r = _coloring(Uconv.euctou8("●"), "#770000" ); + buf = "" + case @color + when "green" + buf = on + off_y + off_r + when "yellow" + buf = off_g + on + off_r + when "red" + buf = off_g + off_y + on + end + return "<span background=\"black\">(#{buf})</span>" + end + def update +# @list.set_value(@row, 0, _markup(@status[0,1])) + @list.set_value(@row, 0, _icon) @list.set_value(@row, 1, @host) @list.set_value(@row, 2, @type) @list.set_value(@row, 3, @status) @@ -40,16 +66,36 @@ end def snmp - @list.set_value(@row, 0, "\\") + @list.set_value(@row, 6, "\\") buf = `snmpget -v1 -c ultrapossum #{@host} #{OID}.2.101.1` @status = buf.gsub(/^[^"]+"(.+)"\n/, '\1') - @list.set_value(@row, 0, "|") + @status = "-----" if****@statu***** == 0 + + case @status + when "DEAD" + @color = "red" + when "STOP" + @color = "red" + when "-----" + @color = "yellow" + when "ACTIVE" + @color = "green" + end + + @list.set_value(@row, 0, _icon) if****@statu***** + + @list.set_value(@row, 6, "|") buf = `snmpget -v1 -c ultrapossum #{@host} #{OID}.3.101.1` @pid = buf.gsub(/^[^"]+"(.+)"\n/, '\1') - @list.set_value(@row, 0, "/") + @pid = "-----" if****@pid***** == 0 + + @list.set_value(@row, 6, "/") buf = `snmpget -v1 -c ultrapossum #{@host} #{OID}.4.101.1` @since = buf.gsub(/^[^"]+"(.+)"\n/, '\1') - @list.set_value(@row, 0, "-") + @since = "-----" if****@since***** == 0 + + @list.set_value(@row, 6, "-") + end attr_reader :row, :host @@ -59,10 +105,10 @@ def initialize(glade) @glade = @glade = GladeXML.new(glade) {|handler| method(handler)} - @list = Gtk::ListStore.new(String, String, String, String, String, String) + @list = Gtk::ListStore.new(String, String, String, String, String, String, String) @columns = [] Column.size.times do |i| - @columns << Gtk::TreeViewColumn.new(Column[i], Gtk::CellRendererText.new, {:text => i}) + @columns << Gtk::TreeViewColumn.new(Column[i], Gtk::CellRendererText.new, { :markup => i }) # {:text => i, :markup => 1}) end @columns.each do |val| @glade["treeview1"].append_column(val) @@ -71,12 +117,10 @@ update - h = Host.new(`ultrapossum-config get MASTER`.gsub!(/MASTER="(.+)"\n/, '\1'), self) - h.type = "master" + h = Host.new(`ultrapossum-config get MASTER`.gsub!(/MASTER="(.+)"\n/, '\1'), "master", self) Hosts << h `ultrapossum-config get SLAVES`.gsub!(/SLAVES="(.*)"\n/, '\1').split(' ').each do |s| - h = Host.new(s.chomp, self) - h.type = "slave" + h = Host.new(s.chomp, "slave", self) Hosts << h end