[Ultrapossum-cvs 208] demo/haviewer 1.2, 1.3, haviewer.glade 1.3, 1.4, haviewer.rb

アーカイブの一覧に戻る

Masato Taruishi taru****@sourc*****
2004年 6月 23日 (水) 00:21:27 JST


===================================================================
RCS file: demo/haviewer/haviewer.glade,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- demo/haviewer/haviewer.glade	2004/06/18 05:35:40	1.2
+++ demo/haviewer/haviewer.glade	2004/06/22 15:21:26	1.3
@@ -128,25 +128,190 @@
 	  </child>
 
 	  <child>
-	    <widget class="GtkScrolledWindow" id="scrolledwindow1">
-	      <property name="border_width">4</property>
-	      <property name="width_request">408</property>
+	    <widget class="GtkVBox" id="vbox3">
 	      <property name="visible">True</property>
-	      <property name="can_focus">True</property>
-	      <property name="hscrollbar_policy">GTK_POLICY_NEVER</property>
-	      <property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
-	      <property name="shadow_type">GTK_SHADOW_NONE</property>
-	      <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+	      <property name="homogeneous">False</property>
+	      <property name="spacing">0</property>
 
 	      <child>
-		<widget class="GtkTreeView" id="treeview1">
+		<widget class="GtkFrame" id="frame1">
+		  <property name="visible">True</property>
+		  <property name="label_xalign">0</property>
+		  <property name="label_yalign">0.5</property>
+		  <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property>
+
+		  <child>
+		    <widget class="GtkHBox" id="hbox3">
+		      <property name="border_width">4</property>
+		      <property name="visible">True</property>
+		      <property name="homogeneous">False</property>
+		      <property name="spacing">0</property>
+
+		      <child>
+			<widget class="GtkHBox" id="hbox4">
+			  <property name="visible">True</property>
+			  <property name="homogeneous">False</property>
+			  <property name="spacing">0</property>
+
+			  <child>
+			    <widget class="GtkLabel" id="label3">
+			      <property name="visible">True</property>
+			      <property name="label" translatable="yes">Master:</property>
+			      <property name="use_underline">False</property>
+			      <property name="use_markup">False</property>
+			      <property name="justify">GTK_JUSTIFY_LEFT</property>
+			      <property name="wrap">False</property>
+			      <property name="selectable">False</property>
+			      <property name="xalign">0.5</property>
+			      <property name="yalign">0.5</property>
+			      <property name="xpad">8</property>
+			      <property name="ypad">0</property>
+			    </widget>
+			    <packing>
+			      <property name="padding">0</property>
+			      <property name="expand">False</property>
+			      <property name="fill">False</property>
+			    </packing>
+			  </child>
+
+			  <child>
+			    <widget class="GtkLabel" id="master_icon">
+			      <property name="visible">True</property>
+			      <property name="label" translatable="yes">OOO</property>
+			      <property name="use_underline">False</property>
+			      <property name="use_markup">False</property>
+			      <property name="justify">GTK_JUSTIFY_LEFT</property>
+			      <property name="wrap">False</property>
+			      <property name="selectable">False</property>
+			      <property name="xalign">0.5</property>
+			      <property name="yalign">0.5</property>
+			      <property name="xpad">0</property>
+			      <property name="ypad">0</property>
+			    </widget>
+			    <packing>
+			      <property name="padding">0</property>
+			      <property name="expand">False</property>
+			      <property name="fill">True</property>
+			    </packing>
+			  </child>
+			</widget>
+			<packing>
+			  <property name="padding">0</property>
+			  <property name="expand">True</property>
+			  <property name="fill">True</property>
+			</packing>
+		      </child>
+
+		      <child>
+			<widget class="GtkHBox" id="hbox5">
+			  <property name="visible">True</property>
+			  <property name="homogeneous">False</property>
+			  <property name="spacing">0</property>
+
+			  <child>
+			    <widget class="GtkLabel" id="label6">
+			      <property name="visible">True</property>
+			      <property name="label" translatable="yes">Slave:</property>
+			      <property name="use_underline">False</property>
+			      <property name="use_markup">False</property>
+			      <property name="justify">GTK_JUSTIFY_LEFT</property>
+			      <property name="wrap">False</property>
+			      <property name="selectable">False</property>
+			      <property name="xalign">0.5</property>
+			      <property name="yalign">0.5</property>
+			      <property name="xpad">8</property>
+			      <property name="ypad">0</property>
+			    </widget>
+			    <packing>
+			      <property name="padding">0</property>
+			      <property name="expand">False</property>
+			      <property name="fill">False</property>
+			    </packing>
+			  </child>
+
+			  <child>
+			    <widget class="GtkLabel" id="slave_icon">
+			      <property name="visible">True</property>
+			      <property name="label" translatable="yes">OOO</property>
+			      <property name="use_underline">False</property>
+			      <property name="use_markup">False</property>
+			      <property name="justify">GTK_JUSTIFY_LEFT</property>
+			      <property name="wrap">False</property>
+			      <property name="selectable">False</property>
+			      <property name="xalign">0.5</property>
+			      <property name="yalign">0.5</property>
+			      <property name="xpad">0</property>
+			      <property name="ypad">0</property>
+			    </widget>
+			    <packing>
+			      <property name="padding">0</property>
+			      <property name="expand">False</property>
+			      <property name="fill">True</property>
+			    </packing>
+			  </child>
+			</widget>
+			<packing>
+			  <property name="padding">0</property>
+			  <property name="expand">True</property>
+			  <property name="fill">True</property>
+			</packing>
+		      </child>
+		    </widget>
+		  </child>
+
+		  <child>
+		    <widget class="GtkLabel" id="label2">
+		      <property name="visible">True</property>
+		      <property name="label" translatable="yes">Status Summary</property>
+		      <property name="use_underline">False</property>
+		      <property name="use_markup">False</property>
+		      <property name="justify">GTK_JUSTIFY_LEFT</property>
+		      <property name="wrap">False</property>
+		      <property name="selectable">False</property>
+		      <property name="xalign">0.5</property>
+		      <property name="yalign">0.5</property>
+		      <property name="xpad">0</property>
+		      <property name="ypad">0</property>
+		    </widget>
+		    <packing>
+		      <property name="type">label_item</property>
+		    </packing>
+		  </child>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">False</property>
+		  <property name="fill">True</property>
+		</packing>
+	      </child>
+
+	      <child>
+		<widget class="GtkScrolledWindow" id="scrolledwindow1">
+		  <property name="border_width">4</property>
+		  <property name="width_request">408</property>
 		  <property name="visible">True</property>
 		  <property name="can_focus">True</property>
-		  <property name="headers_visible">True</property>
-		  <property name="rules_hint">False</property>
-		  <property name="reorderable">False</property>
-		  <property name="enable_search">True</property>
+		  <property name="hscrollbar_policy">GTK_POLICY_NEVER</property>
+		  <property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
+		  <property name="shadow_type">GTK_SHADOW_NONE</property>
+		  <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+		  <child>
+		    <widget class="GtkTreeView" id="treeview1">
+		      <property name="visible">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="headers_visible">True</property>
+		      <property name="rules_hint">False</property>
+		      <property name="reorderable">False</property>
+		      <property name="enable_search">True</property>
+		    </widget>
+		  </child>
 		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">True</property>
+		  <property name="fill">True</property>
+		</packing>
 	      </child>
 	    </widget>
 	    <packing>
===================================================================
RCS file: demo/haviewer/haviewer.rb,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- demo/haviewer/haviewer.rb	2004/06/21 16:10:43	1.3
+++ demo/haviewer/haviewer.rb	2004/06/22 15:21:26	1.4
@@ -20,6 +20,29 @@
   Red = "#FF0000"
   DarkRed = "#550000"
 
+  def HAViewer._icon(color)
+    on  = HAViewer._coloring(Uconv.euctou8("●"), color)
+    off_g = HAViewer._coloring(Uconv.euctou8("●"), DarkGreen )
+    off_y = HAViewer._coloring(Uconv.euctou8("●"), DarkYellow )
+    off_r = HAViewer._coloring(Uconv.euctou8("●"), DarkRed )
+    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
+    else
+       buf = off_g + off_y + off_r
+    end
+    return "<span background=\"#000000\">(#{buf})</span>"
+  end
+
+  def HAViewer._coloring(buf, color)
+    return "<span foreground=\"#{color}\"><tt>#{buf}</tt></span>"
+  end
+
   class Host
     def initialize( host, type, viewer )
       super();
@@ -41,30 +64,8 @@
       }
     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("●"), DarkGreen );
-      off_y = _coloring(Uconv.euctou8("●"), DarkYellow );
-      off_r = _coloring(Uconv.euctou8("●"), DarkRed );
-      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=\"#000000\">(#{buf})</span>"
-    end
-
     def update
-#      @list.set_value(@row, 0, _markup(@status[0,1]))
-      @list.set_value(@row, 0, _icon) 
+      @list.set_value(@row, 0, HAViewer._icon(@color)) 
       @list.set_value(@row, 1, @host)
       @list.set_value(@row, 2, @type)
       @list.set_value(@row, 3, @status)
@@ -78,18 +79,22 @@
       @status = buf.gsub(/^[^"]+"(.+)"\n/, '\1')
       @status = "-----" if****@statu***** == 0
 
+      @color = Yellow
+
       case @status
       when "DEAD"
         @color = Red
       when "STOP"
         @color = Red
-      when "-----"
-        @color = Yellow
       when "ACTIVE"
         @color = Green
+      when "STANDBY"
+        @color = Green
+      when "RUN"
+        @color = Green
       end
 
-      @list.set_value(@row, 0, _icon) if****@statu*****
+      @list.set_value(@row, 0, HAViewer._icon(@color)) if****@statu*****
 
       @list.set_value(@row, 6, "|")
       buf = `snmpget -v1 -c ultrapossum #{@host} #{OID}.3.101.1`
@@ -126,8 +131,9 @@
 
     h = Host.new(`ultrapossum-config get MASTER`.gsub!(/MASTER="(.+)"\n/, '\1'), "master", self)
     Hosts << h
+    backup = `ultrapossum-config get BACKUP`.gsub!(/BACKUP="(.+)"\n/, '\1')
     `ultrapossum-config get SLAVES`.gsub!(/SLAVES="(.*)"\n/, '\1').split(' ').each do |s|
-      h = Host.new(s.chomp, "slave", self)
+      h = Host.new(s.chomp, (backup==s)?"master":"slave", self)
       Hosts << h
     end
 
@@ -136,6 +142,39 @@
   def update
     @glade["time"].set_text(`date | iconv --to UTF-8`.chomp!)
     @glade["uptime"].set_text(`uptime`.chomp!)
+
+    master_icon = ""
+    slave_icon = ""
+    Hosts.each do |h|
+      if h.type == "master"
+        case h.status
+        when "ACTIVE"
+	  master_icon = Green
+	when "STANDBY"
+	  slave_icon = Green
+	when "FAOVER"
+	  master_icon = Yellow
+	when "STOP"
+	  master_icon = Red if master_icon != Green && master_icon != Yellow
+	when "DEAD"
+	  master_icon = Red if master_icon != Green && master_icon != Yellow
+	end
+      else
+        case h.status
+	when "RUN"
+	  slave_icon = Green
+	when "ACTIVE"
+	  slave_icon = Green
+	when "STOP"
+	  slave_icon = Red if slave_icon != Green
+	when "DEAD"
+	  slave_icon = Red if slave_icon != Green
+	end
+      end
+    end
+    @glade["master_icon"].set_markup(HAViewer._icon(master_icon))
+    @glade["slave_icon"].set_markup(HAViewer._icon(slave_icon))
+
   end
 
   attr_reader :list



Ultrapossum-cvs メーリングリストの案内
アーカイブの一覧に戻る