From c4c1a5deba37f4242dc71031e7574ec382f6e56a Mon Sep 17 00:00:00 2001 From: bee0005 Date: Thu, 29 Sep 2016 09:35:57 +0000 Subject: [PATCH 1/3] update nodes --- app/controllers/application_controller.rb | 2 +- app/controllers/node_controller.rb | 26 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7f54ca7..2e4f3c6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base include ApplicationHelper include HomeHelper include VolumeHelper + include NodeHelper def require_login unless user_signed_in? @@ -12,5 +13,4 @@ class ApplicationController < ActionController::Base redirect_to "/users/sign_in" # halts request cycle end end - end diff --git a/app/controllers/node_controller.rb b/app/controllers/node_controller.rb index 90fc615..f72f91a 100644 --- a/app/controllers/node_controller.rb +++ b/app/controllers/node_controller.rb @@ -2,7 +2,31 @@ class NodeController < ApplicationController before_action :require_login def index @hosts = Array.new - @nodes = Node.all.order("id asc") + @nodes = Node.all.order("id asc") + + @node_connect = Hash.new + @node_info = Array.new + one_node = Node.take + if !one_node.blank? + if ping_test?(one_node.host_ip) + command = String.new + command << "sshpass -p#{one_node.user_password} ssh #{one_node.user_name}@#{one_node.host_ip} gluster peer status info" + puts command + output = `#{command}`.split("\n") + output << "\n" + output.each do |t| + next if t.equal? output.first + if t.include? ":" + temp = t.split(":") + @node_info << temp[1] + else + @node_connect[one_node.id] << @node_info + @node_info = Array.new + end + end + end + end + if get_hosts.blank? flash[:danger] = "Check Server" else From 616e76c4f0deb2d383b674ebb8bcf5cdf1eecd27 Mon Sep 17 00:00:00 2001 From: bee0005 Date: Thu, 29 Sep 2016 09:44:06 +0000 Subject: [PATCH 2/3] update --- app/controllers/node_controller.rb | 48 ++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/app/controllers/node_controller.rb b/app/controllers/node_controller.rb index f72f91a..16eec3e 100644 --- a/app/controllers/node_controller.rb +++ b/app/controllers/node_controller.rb @@ -4,9 +4,14 @@ class NodeController < ApplicationController @hosts = Array.new @nodes = Node.all.order("id asc") - @node_connect = Hash.new - @node_info = Array.new + @node_connects = Array.new + node_info = Hash.new one_node = Node.take + + node_info["Hostname"] = one_node.host_name + node_info["State"] = "Peer in Cluster Disconnected" + node_info = Hash.new + if !one_node.blank? if ping_test?(one_node.host_ip) command = String.new @@ -14,18 +19,51 @@ class NodeController < ApplicationController puts command output = `#{command}`.split("\n") output << "\n" + output.each do |t| next if t.equal? output.first if t.include? ":" temp = t.split(":") - @node_info << temp[1] + node_info[temp[0]] = temp[1] else - @node_connect[one_node.id] << @node_info - @node_info = Array.new + @node_connects << node_info + node_info = Hash.new end end + end end + volumes = Array.new + volume = Hash.new + node = Node.take + df = get_df + # error check : node is nil + if node.nil? + return volumes + end + command = String.new + command << "sshpass -p#{node.user_password} ssh #{node.user_name}@#{node.host_ip} gluster volume info" + puts command + output = `#{command}`.split("\n") + output << "\n" + output.each do |t| + next if t.equal? output.first + if t.include? ":" + temp = t.split(":") + volume[temp[0]] = temp[1] + else + volume['Mount State'] = "unmounted" + df.each do |u| + next if !u['Filesystem'].include? volume['Volume Name'].delete(' ') + volume['Mount State'] = "mounted" + volume['Mount Point'] = u['Mounted on'] + end + volumes << volume + volume = Hash.new + end + end + return volumes + if get_hosts.blank? flash[:danger] = "Check Server" From fb55a7a71c4035bc09385955b5dc335e4730a849 Mon Sep 17 00:00:00 2001 From: bee0005 Date: Thu, 29 Sep 2016 09:45:06 +0000 Subject: [PATCH 3/3] update --- app/controllers/node_controller.rb | 31 ------------------------------ 1 file changed, 31 deletions(-) diff --git a/app/controllers/node_controller.rb b/app/controllers/node_controller.rb index 16eec3e..778d597 100644 --- a/app/controllers/node_controller.rb +++ b/app/controllers/node_controller.rb @@ -33,37 +33,6 @@ class NodeController < ApplicationController end end - volumes = Array.new - volume = Hash.new - node = Node.take - df = get_df - # error check : node is nil - if node.nil? - return volumes - end - command = String.new - command << "sshpass -p#{node.user_password} ssh #{node.user_name}@#{node.host_ip} gluster volume info" - puts command - output = `#{command}`.split("\n") - output << "\n" - output.each do |t| - next if t.equal? output.first - if t.include? ":" - temp = t.split(":") - volume[temp[0]] = temp[1] - else - volume['Mount State'] = "unmounted" - df.each do |u| - next if !u['Filesystem'].include? volume['Volume Name'].delete(' ') - volume['Mount State'] = "mounted" - volume['Mount Point'] = u['Mounted on'] - end - volumes << volume - volume = Hash.new - end - end - return volumes - if get_hosts.blank? flash[:danger] = "Check Server"