ref: refs/heads/master commit a1118b74da5a55b120bf0aeb5e176bf2436ec7e4 Author: Klaus Kämpf <kkaempf@suse.de> Date: Wed Jul 22 17:29:12 2009 +0200 Make webclient-status build --- plugins/status/.gitignore | 2 + plugins/status/package/www.tar.bz2 | Bin 0 -> 4780 bytes plugins/status/package/www/README | 7 + plugins/status/package/www/Rakefile | 10 + .../www/app/controllers/status_controller.rb | 231 ++++++++++++++++++++ .../package/www/app/helpers/status_helper.rb | 7 + plugins/status/package/www/app/models/status.rb | 4 + .../www/app/views/status/_status_summary.html.erb | 16 ++ .../package/www/app/views/status/edit.html.erb | 47 ++++ .../package/www/app/views/status/index.html.erb | 115 ++++++++++ plugins/status/package/www/config/rails_parent.rb | 15 ++ plugins/status/package/www/init.rb | 1 + plugins/status/package/www/install.rb | 1 + plugins/status/package/www/shortcuts.yml | 9 + plugins/status/package/www/tasks/status_tasks.rake | 6 + plugins/status/package/www/uninstall.rb | 1 + plugins/status/package/yast2-webclient-status.spec | 76 +++++++ 17 files changed, 548 insertions(+), 0 deletions(-) diff --git a/plugins/status/.gitignore b/plugins/status/.gitignore new file mode 100644 index 0000000..09a651e --- /dev/null +++ b/plugins/status/.gitignore @@ -0,0 +1,2 @@ +package/www +package/www.tar.bz2 diff --git a/plugins/status/package/www.tar.bz2 b/plugins/status/package/www.tar.bz2 new file mode 100644 index 0000000..bc965c5 Binary files /dev/null and b/plugins/status/package/www.tar.bz2 differ diff --git a/plugins/status/package/www/README b/plugins/status/package/www/README new file mode 100644 index 0000000..3906624 --- /dev/null +++ b/plugins/status/package/www/README @@ -0,0 +1,7 @@ +Status +============ + +Plugin for showing system information like CPU, memorry, .... + + +Copyright (c) 2009 Novell, released under the MIT license diff --git a/plugins/status/package/www/Rakefile b/plugins/status/package/www/Rakefile new file mode 100644 index 0000000..ca63e76 --- /dev/null +++ b/plugins/status/package/www/Rakefile @@ -0,0 +1,10 @@ +require 'rake' +require 'rake/testtask' +require 'rake/rdoctask' +require File.join(File.dirname(__FILE__), 'config', 'rails_parent') +require File.join(RailsParent.parent, 'config', 'boot') +require 'tasks/rails' + +desc 'Default: run unit tests.' +task :default => :test + diff --git a/plugins/status/package/www/app/controllers/status_controller.rb b/plugins/status/package/www/app/controllers/status_controller.rb new file mode 100644 index 0000000..114c57a --- /dev/null +++ b/plugins/status/package/www/app/controllers/status_controller.rb @@ -0,0 +1,231 @@ +require 'yast/service_resource' + +class StatusController < ApplicationController + before_filter :login_required + layout "main" + + private + def client_permissions + @client = YaST::ServiceResource.proxy_for('org.opensuse.yast.system.status') + unless @client + flash[:notice] = _("Invalid session, please login again.") + redirect_to( logout_path ) and return + end + @permissions = @client.permissions + end + + def create_data_map( tree, label = "") + data_map = Hash.new + if tree.methods.include?("attributes") + tree.attributes.each do |key, branch| + if key.start_with?("t_") + data_map[key] = branch.to_f + elsif key == "limit" + @limits[label] = branch.attributes + else + next_label = label + if key != "value" + next_label += "/" + key + end + data_map = create_data_map(branch, next_label) + if data_map.size > 0 + data_list = [] + flatten_map = data_map.sort #Sorting for timestamps + flatten_map.each {|data| data_list << data[1] } + @data[next_label] = data_list + data_map = {} + end + end + end + else + logger.error "wrong result: #{tree.inspect}" + end + return data_map + end + + def create_data + @data = Hash.new + @limits = Hash.new + @limits_list = Hash.new + @data_group = Hash.new + status = [] + begin + till = Time.new + from = till - 300 #last 5 minutes + + status = @client.find(:dummy_param, :params => { :start => from.to_i.to_s, :stop => till.to_i.to_s }) + + rescue ActiveResource::ClientError => e + flash[:error] = YaST::ServiceResource.error(e) + return false + end + + create_data_map status + + #grouping graphs to memory, cpu,... + @data.each do |key, list_value| + if @limits.has_key?(key) + graph_list = [] + key_split = key.split("/") + for i in 0..list_value.size-1 do + if key_split.size>1 && key_split[1]=="memory" # take MByte for the value + graph_list << [i,@limits[key]["value"]/1024/1024] + else + graph_list << [i,@limits[key]["value"]] + end + end + @limits_list[key] = graph_list + end + + key_split = key.split("/") + if key_split.size > 1 + group_map = {} + group_map = @data_group[key_split[1]] if @data_group.has_key?(key_split[1]) + label_name = "" + for i in 2..key_split.size-1 do + if i==2 + label_name = key_split[i] + else + label_name += "/" + key_split[i] + end + end + graph_list = [] + store_data = false #take only a list which has one value greater than 0 at least + for i in 0..list_value.size-1 + store_data = true if list_value[i] != 0 + value_list = [i] + if key_split[1]=="memory" # take MByte for the value + value_list << list_value[i]/1024/1024 + else + value_list << list_value[i] + end + graph_list << value_list + end + if store_data + group_map[label_name] = graph_list + @data_group[key_split[1]] = group_map + end + else + logger.error "empty key: #{@key} #{list.inspect}" + end + end + logger.debug "Limits: #{@limits.inspect}" +# logger.debug "System information: #{@data_group.inspect}" + true + end + + #removing logging data and add limits which are defined in params + def create_save_data(status, params, label = "") + status.each do |key, value| + if key.start_with?("t_") + status.delete(key) + elsif + next_label = label+ "/" + key + create_save_data(value, params, next_label) if value.is_a? Hash + end + end + if params.has_key?(label+"/value") + limit = Hash.new + key_split = label.split("/") + if key_split.size>1 && key_split[1]=="memory" # MByte for the value --> change it to Byte + limit["value"] = params[label+"/value"].to_f*1024*1024 + else + limit["value"] = params[label+"/value"] + end + limit["maximum"] = params[label+"/maximum"] == "true"?true:false + status["limit"] = limit + end + return status + end + + # Initialize GetText and Content-Type. + init_gettext "yast_webclient_status" + + public + + def initialize + end + + def edit + return unless client_permissions + create_data + end + + def index + return unless client_permissions + create_data + end + + + def show_summary + return unless client_permissions + unless create_data + erase_redirect_results #reset all redirects + erase_render_results + flash.clear #no flash from load_proxy + render :partial => "status_summary", :locals => { :status => nil } + return false + end + status = "" + @data_group.each do |key, map| + error_found = false + map.each do |graph_key, list_value| + limit_key = "/#{key}/#{graph_key}" + if @limits_list.has_key?(limit_key) + cmp_value = @limits_list[limit_key][0][1] #take thatone cause it has already the right format + #( e.g. MByte for memory) + list_value.each do |value| + if (@limits[limit_key]["maximum"] && value[1]>= cmp_value) || + (!@limits[limit_key]["maximum"] && value[1]<= cmp_value) + error_found = true + break + end + end + end + end + if error_found + status += "; " unless status.blank? + status += key + " " + _("limits exceeded") + end + end + + render :partial => "status_summary", :locals => { :status => status } + end + + def save + return unless client_permissions + begin + till = Time.new + from = till - 300 #last 5 minutes + status = @client.find(:dummy_param, :params => { :start => from.to_i.to_s, :stop => till.to_i.to_s }) + + rescue ActiveResource::ClientError => e + flash[:error] = YaST::ServiceResource.error(e) + redirect_to :controller=>"status", :action=>"edit" + return false + end + + save_hash = create_save_data(Hash.from_xml(status.to_xml)["status"], params) + logger.debug "writing #{save_hash.inspect}" + + save_status = @client.new() + save_status.load(save_hash) + + success = true + begin + save_status.save + logger.debug "limits have been written" + flash[:notice] = _("Limits have been written.") + rescue ActiveResource::ClientError => e + flash[:error] = YaST::ServiceResource.error(e) + ExceptionLogger.log_exception e + success = false + end + if success + redirect_to :controller=>"status", :action=>"index" + else + redirect_to :controller=>"status", :action=>"edit" + end + end + +end diff --git a/plugins/status/package/www/app/helpers/status_helper.rb b/plugins/status/package/www/app/helpers/status_helper.rb new file mode 100644 index 0000000..ad1a785 --- /dev/null +++ b/plugins/status/package/www/app/helpers/status_helper.rb @@ -0,0 +1,7 @@ +module StatusHelper + def graph id, width, height, last = false + html = "<div id='#{id}' style='width:#{width}px;height:#{height}px;float:left'><img src='/images/spinner.gif'></div>" + html += "<br style='clear: both'>" if last + return html + end +end diff --git a/plugins/status/package/www/app/models/status.rb b/plugins/status/package/www/app/models/status.rb new file mode 100644 index 0000000..3621ed4 --- /dev/null +++ b/plugins/status/package/www/app/models/status.rb @@ -0,0 +1,4 @@ +require 'yast/service_resource' +class Status < YaST::ServiceResource::Base + +end diff --git a/plugins/status/package/www/app/views/status/_status_summary.html.erb b/plugins/status/package/www/app/views/status/_status_summary.html.erb new file mode 100644 index 0000000..3f70230 --- /dev/null +++ b/plugins/status/package/www/app/views/status/_status_summary.html.erb @@ -0,0 +1,16 @@ +<div class="status_status"> + <% unless status %> + <div class="status-icon warning"></div> + <span><%= _("Error occur during loading status information.") %></span> + <% else %> + <% link_to "status" do %> + <% if !status.blank? %> + <img src="/images/button_critical.png" alt="error found"/> + <%= status %> + <% else %> + <img src="/images/button_ok.png" alt="Your system is healthy"/> + <%= _("Your system is healthy.") %> + <% end %> + <% end %> + <% end %> +</div> diff --git a/plugins/status/package/www/app/views/status/edit.html.erb b/plugins/status/package/www/app/views/status/edit.html.erb new file mode 100644 index 0000000..73fb003 --- /dev/null +++ b/plugins/status/package/www/app/views/status/edit.html.erb @@ -0,0 +1,47 @@ +<% disabled = ! @permissions[:writelimits] %> + +<h2><%=_("Configure Status Limits")%></h2> + +<% form_tag '/status/save' do %> +<table class="list"> + <tr> + <th width=350><%=_("Status Path")%></th> + <th width=100><%=_("Limit Value")%></th> + <th width=40><%=_("Maximum Reached") %></th> + </tr> + + <% @data_group.each do |key, map| %> + <% map.each do |graph_key, list_value| %> + <tr> + <% limit_key = "/#{key}/#{graph_key}" %> + <td><%= limit_key %></td> + + <% if @limits_list.has_key?(limit_key) %> + <td> + <input name=<%= limit_key+"/value" %> type="text" size="10" maxlength="15" value=<%= @limits_list[limit_key][0][1] %>> + </td> + <td> + <input type="checkbox" name= <%= limit_key+"/maximum" %> id=<%= limit_key+"/maximum" %> value="true" + <%= @limits[limit_key]["maximum"] ? "checked" : "" %> + <%= "disabled="disabled"" if disabled %> /> + </td> + <% else %> + <td> + <input name=<%= limit_key+"/value" %> type="text" size="10" maxlength="15" value=0> + </td> + <td> + <input type="checkbox" name= <%= limit_key+"/maximum" %> id=<%= limit_key+"/maximum" %> value="true" + <%= "disabled="disabled"" if disabled %> /> + </td> + <% end %> + </tr> + <% end %> + <% end %> +</table> +<%= submit_tag _("Save"), :disabled=> disabled, :class => 'button' -%> +<% end -%> +<br> +<a href="/" class="button"><%=_("Back")%></a> +<br> + + diff --git a/plugins/status/package/www/app/views/status/index.html.erb b/plugins/status/package/www/app/views/status/index.html.erb new file mode 100644 index 0000000..ed63eb3 --- /dev/null +++ b/plugins/status/package/www/app/views/status/index.html.erb @@ -0,0 +1,115 @@ + +<h1>Status</h1> + +<% column = 1 %> +<% @data_group.each do |key, map| %> + <% if column != 1 %> + <br style='clear: both'> + <br> + <% column = 1 %> + <% end %> + <% if key == "df" %> + <h3><%= _("Disk usage") %></h3> + <% else %> + <h3><%= key.tr('_',' ').capitalize %></h3> + <% end %> + + <% map.each do |graph_key, list_value| %> + <% if key != "df" || !graph_key.end_with? ("used") %> + <% graph_id = key + "_" + graph_key.tr('/','_') %> + <%= graph(graph_id, 200, 150, column == 4?true:false) %> + <% if column == 4 %> + <br> + <% column = 1 %> + <% else %> + <% column += 1 %> + <% end %> + <% end %> + <% end %> +<% end %> +<% if column != 1 %> + <br style='clear: both'> + <br> +<% end %> +<br> +<br> +<%= button_to _("edit limits"), :action => :edit, :class => "button" %> +<br> +<%= button_to _("Back"), :back %> +<br> +<script type="text/javascript"> + + +function plotPieGraph (graph_id, graph_title, graph_data ) { + $.jqplot(graph_id, [graph_data], { + title: graph_title, + legend: { + show: true + }, + seriesDefaults: { + renderer: $.jqplot.PieRenderer, + rendererOptions: { + sliceMargin: 0, + diameter: 100 + } + }, + + cursor: { + show: false + }, + }); +} + + +function plotLineGraph(graph_id, graph_title, graph_data ) { + $.jqplot(graph_id, graph_data, { + title: graph_title, + axes: { + xaxis: { + showTicks: false + }, + yaxis: { + showTicks: true, + min: 0 + } + }, + series:[{color:'#5FAB78', + lineWidth: 1, + markerOptions: { + size: 0 + } + }, + {color:'#E89120', + lineWidth: 1, + markerOptions: { + size: 0 + } + }] + }); +} + + $(function() { + <% @data_group.each do |key, map| %> + <% map.each do |graph_key, list_value| %> + <% graph_id = key + "_" + graph_key.tr('/','_') %> + <% if key != "df" %> + $('#' + '<%= graph_id %>').html(""); + <% limit_key = "/#{key}/#{graph_key}" %> + <% if @limits_list.has_key?(limit_key) %> + plotLineGraph('<%= graph_id %>', '<%= graph_key.tr('/','_').tr('_',' ').capitalize %>', [<%= list_value.inspect %>, <%= @limits_list[limit_key].inspect %>]); + <% else %> + plotLineGraph('<%= graph_id %>', '<%= graph_key.tr('/','_').tr('_',' ').capitalize %>', [<%= list_value.inspect %>]); + <% end %> + <% else %> + <% if graph_key.end_with? ("free") %> + $('#' + '<%= graph_id %>').html(""); + <% used_key = graph_key[0..graph_key.length-5] + "used" %> + plotPieGraph ('<%= graph_id %>', '<%= graph_key[2..graph_key.length-5].tr('_','/') %>', [["<%= _("free") %>", <%= list_value.last[1] %>], ["<%= _("used") %>", <%= map[used_key].last[1] %>]]); + <% end %> + <% end %> + <% end %> + <% end %> + + }); +</script> + diff --git a/plugins/status/package/www/config/rails_parent.rb b/plugins/status/package/www/config/rails_parent.rb new file mode 100644 index 0000000..59e7892 --- /dev/null +++ b/plugins/status/package/www/config/rails_parent.rb @@ -0,0 +1,15 @@ +class RailsParent + + def RailsParent.parent + parent = ENV["RAILS_PARENT"] + unless parent + parent = File.expand_path(File.join('..','..','..', 'webclient'), File.dirname(__FILE__)) + unless File.directory?( parent || "" ) + $stderr.puts "Nope: #{parent}\nPlease set RAILS_PARENT environment" + exit 1 + end + end + parent + end + +end diff --git a/plugins/status/package/www/init.rb b/plugins/status/package/www/init.rb new file mode 100644 index 0000000..3c19a74 --- /dev/null +++ b/plugins/status/package/www/init.rb @@ -0,0 +1 @@ +# Include hook code here diff --git a/plugins/status/package/www/install.rb b/plugins/status/package/www/install.rb new file mode 100644 index 0000000..f7732d3 --- /dev/null +++ b/plugins/status/package/www/install.rb @@ -0,0 +1 @@ +# Install hook code here diff --git a/plugins/status/package/www/shortcuts.yml b/plugins/status/package/www/shortcuts.yml new file mode 100644 index 0000000..a381312 --- /dev/null +++ b/plugins/status/package/www/shortcuts.yml @@ -0,0 +1,9 @@ +main: + icon: '/images/monitoring.png' + url: /status + groups: [ Access ] + tags: [ access] + title: Status + description: Show system status + resources: [ status ] + diff --git a/plugins/status/package/www/tasks/status_tasks.rake b/plugins/status/package/www/tasks/status_tasks.rake new file mode 100644 index 0000000..1568c54 --- /dev/null +++ b/plugins/status/package/www/tasks/status_tasks.rake @@ -0,0 +1,6 @@ +begin + require 'tasks/webservice' +rescue LoadError => e + $stderr.puts "Install rubygem-yast2-webservice-tasks.rpm" +end + diff --git a/plugins/status/package/www/uninstall.rb b/plugins/status/package/www/uninstall.rb new file mode 100644 index 0000000..9738333 --- /dev/null +++ b/plugins/status/package/www/uninstall.rb @@ -0,0 +1 @@ +# Uninstall hook code here diff --git a/plugins/status/package/yast2-webclient-status.spec b/plugins/status/package/yast2-webclient-status.spec new file mode 100644 index 0000000..85b07a8 --- /dev/null +++ b/plugins/status/package/yast2-webclient-status.spec @@ -0,0 +1,76 @@ +# +# spec file for package yast2-webclient-status (Version 0.1) +# +# Copyright (c) 2008 SUSE LINUX Products GmbH, Nuernberg, Germany. +# This file and all modifications and additions to the pristine +# package are under the same license as the package itself. +# +# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# + + +Name: yast2-webclient-status +PreReq: yast2-webclient >= 0.0.2 +License: GPL +Group: Productivity/Networking/Web/Utilities +Autoreqprov: on +Version: 0.0.2 +Release: 0 +Summary: YaST2 - Webclient - status +Source: www.tar.bz2 +BuildRoot: %{_tmppath}/%{name}-%{version}-build +BuildArch: noarch + +# +%define pkg_user yast +%define plugin_name status +# + + +%description +YaST2 - Webclient - UI for YaST-webservice in order to handle time and date. +Authors: +-------- + Stefan Schubert <schubi@opensuse.org> + Josef Reidinger <jreidinger@suse.cz> +%prep +%setup -q -n www + +%build +(rake makemo) + +%install + +# +# Install all web and frontend parts. +# +mkdir -p $RPM_BUILD_ROOT/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name} +cp -a * $RPM_BUILD_ROOT/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name} + + +%clean +rm -rf $RPM_BUILD_ROOT + +%files +%defattr(-,root,root) +%dir /srv/www/%{pkg_user} +%dir /srv/www/%{pkg_user}/vendor +%dir /srv/www/%{pkg_user}/vendor/plugins +%dir /srv/www/%{pkg_user}/vendor/plugins/%{plugin_name} +%dir /srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/config +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/README +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/Rakefile +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/init.rb +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/install.rb +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/uninstall.rb +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/app +#/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/lib +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/tasks +#/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/test +#/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/locale +#/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/po +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/shortcuts.yml +#/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/config/routes.rb +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/config/rails_parent.rb + +%changelog -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org