Class: SensuCli::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sensu-cli/base.rb

Instance Method Summary collapse

Instance Method Details

#api_path(cli) ⇒ Object



27
28
29
30
31
# File 'lib/sensu-cli/base.rb', line 27

def api_path(cli)
  p = PathCreator.new
  p.respond_to?(cli[:command]) ? path = p.send(cli[:command], cli) : (puts "Something Bad Happened";exit)
  @api = {:path => path[:path], :method => cli[:method], :command => cli[:command], :payload => (path[:payload] || false)}
end

#make_callObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/sensu-cli/base.rb', line 33

def make_call
  opts = {
    :path => @api[:path],
    :method => @api[:method],
    :payload => @api[:payload],
    :host => Config.host,
    :port => Config.port,
    :ssl => Config.ssl || false,
    :user => Config.user || nil,
    :password => Config.password || nil
  }
  api = Api.new
  res = api.request(opts)
  msg = api.response(res.code, res.body, @api[:command])
  if res.code != '200'
    exit
  elsif @format == "single"
    Pretty.table(msg)
  else
    Pretty.print(msg)
  end
  Pretty.count(msg)
end

#settingsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sensu-cli/base.rb', line 13

def settings
  directory = "#{Dir.home}/.sensu"
  file = "#{directory}/settings.rb"
  alt = "/etc/sensu/sensu-cli/settings.rb"
  settings = Settings.new
  if settings.is_file?(file)
    SensuCli::Config.from_file(file)
  elsif settings.is_file?(alt)
    SensuCli::Config.from_file(alt)
  else
    settings.create(directory,file)
  end
end

#setupObject



4
5
6
7
8
9
10
11
# File 'lib/sensu-cli/base.rb', line 4

def setup
  clis = Cli.new
  cli = clis.global
  @format = cli[:fields][:format] || "long"
  settings
  api_path(cli)
  make_call
end