Sha256: 3bc23ba04a63d875baf12b4071ea02f1a7cef14a2f4202c659e67c8f8928eb45

Contents?: true

Size: 1.52 KB

Versions: 14

Compression:

Stored size: 1.52 KB

Contents

require_relative 'common'

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

14 entries across 14 versions & 1 rubygems

Version Path
kontena-cli-1.1.6 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.1.5 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.1.5.rc3 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.1.5.rc2 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.1.5.rc1 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.1.4 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.1.3 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.1.2 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.1.2.rc2 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.1.2.rc1 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.1.1 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.1.1.rc1 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.1.0 lib/kontena/cli/etcd/health_command.rb
kontena-cli-1.1.0.rc2 lib/kontena/cli/etcd/health_command.rb