diff --git a/app/controllers/node_controller.rb b/app/controllers/node_controller.rb index 462839f..b7d5927 100644 --- a/app/controllers/node_controller.rb +++ b/app/controllers/node_controller.rb @@ -1,39 +1,7 @@ class NodeController < ApplicationController before_action :require_login + def index - @nodes = Node.all.order("id asc") - @node_connects = Array.new - node_info = Hash.new - begin - 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 - 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[0]] = temp[1] - else - @node_connects << node_info - node_info = Hash.new - end - end - - end - end - rescue => ex - puts ex - end end def node_add diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e46ff7f..8d5b40e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -113,7 +113,44 @@ module ApplicationHelper return volumes end - def ssh_peer_status + def ssh_nodes + nodes = Array.new + node = Hash.new + db_nodes = Node.all.order("id asc") + db_nodes.each do |db_node| + node["id"] = db_node.id + node["host_name"] = db_node.host_name + node["host_ip"] = db_node.host_ip + node["user_name"] = db_node.user_name + node["user_password"] = db_node.user_password + node["created_at"] = db_node.created_at + node["updated_at"] = db_node.updated_at + node["ping"] = (ping_test?(db_node.host_ip) ? "true" : "false") + + if node["ping"].eql? "true" + command = String.new + command << "sshpass -p#{node["user_password"]} ssh #{node["user_name"]}@#{node["host_ip"]} gluster peer status" + puts command + output = `#{command}`.split("\n") + + if output[0].include? "Number of Peers" + node["ssh"] = "on" + node["gluster"] = "on" + node["number_of_peers"] = output[0].split(": ")[1] + # put peers + + elsif output[0].include? "check if gluster daemon is operational." + node["ssh"] = "on" + node["gluster"] = "off" + else + node["ssh"] = "off" + node["gluster"] = "off" + end + end + nodes << node + node = Hash.new + end + return nodes end def ssh_peer_probe diff --git a/app/views/node/index.html.erb b/app/views/node/index.html.erb index 2912b36..35e12f5 100644 --- a/app/views/node/index.html.erb +++ b/app/views/node/index.html.erb @@ -89,6 +89,7 @@
+ <% nodes = ssh_nodes %>Host Name | Host IP | User Name | -Date | - <%@nodes.each do |t|%> + <% nodes.each do |node| %> | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
- | Attached | - <%else%> -- | - <%end%> - | <%=t.host_name%> | -<%=t.host_ip%> | -<%=t.user_name%> | -<%=t.created_at%> | -+ <% if node["ping"].eql? "true" %> + | + <% else %> + | + <% end %> + <% if node["gluster"].eql? "on" %> + | Attached | + <% else %> +Not operational | + <% end %> +<%= node["host_name"] %> | +<%= node["host_ip"] %> | +<%= node["user_name"] %> | +"> |