Sha256: 825dff1da88d3fcb0bc32346b5378691d77adae142c552c2fe573d31b2fdd41b

Contents?: true

Size: 1.56 KB

Versions: 32

Compression:

Stored size: 1.56 KB

Contents

require_relative 'common'
require 'kontena/cli/helpers/health_helper'

module Kontena::Cli::Etcd
  class HealthCommand < Kontena::Command
    include Kontena::Cli::Common
    include Kontena::Cli::GridOptions
    include Kontena::Cli::Helpers::HealthHelper

    parameter "[NODE]", "Show health for specific node"

    requires_current_master
    requires_current_grid

    def execute
      require_api_url
      token = require_token

      health = true

      if self.node
        node_health = client.get("nodes/#{current_grid}/#{self.node}/health")

        health = show_node_health(node_health)
      else
        nodes = client.get("grids/#{current_grid}/nodes")['nodes']

        nodes.each do |node|
          node_health = client.get("nodes/#{current_grid}/#{node['name']}/health")

          if !show_node_health(node_health)
            health = false
          end
        end
      end

      return health
    end

    # @return [Boolean]
    def show_node_health(node_health)
      etcd_health = node_health['etcd_health']

      if !node_health['connected']
        puts "#{health_icon :offline} Node #{node_health['name']} is offline"
        return false
      elsif etcd_health['health']
        puts "#{health_icon :ok} Node #{node_health['name']} is healthy"
        return true
      elsif etcd_health['error']
        puts "#{health_icon :error} Node #{node_health['name']} is unhealthy: #{etcd_health['error']}"
        return false
      else
        puts "#{health_icon :error} Node #{node_health['name']} is unhealthy"
        return false
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
kontena-cli-1.3.5 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.3.5.rc1 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.3.4 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.3.4.rc1 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.3.3 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.3.3.rc1 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.3.2 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.3.2.rc2 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.3.2.rc1 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.3.1 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.3.1.rc2 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.3.1.rc1 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.3.0 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.3.0.rc4 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.3.0.rc3 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.3.0.rc2 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.3.0.rc1 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.3.0.pre2 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.3.0.pre1 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.2.2 lib/kontena/cli/etcd/health_command.rb