Class: ZBX::CLI::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/zbx/cli.rb

Instance Method Summary collapse

Instance Method Details

#doc(method = '') ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/zbx/cli.rb', line 66

def doc method=''
  version = options[:version]
  base = "https://www.zabbix.com/documentation/#{version}/"
  suffix = case version
           when 1.8
             'api/'
           when 2.0
             'manual/appendix/api/'
           when 2.2
             'manual/api/reference/'
           end
  url = base << suffix << method.gsub('.', '/')
  say "browse #{url}"
  Helper.browse url
end

#send(method, data = '{}') ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/zbx/cli.rb', line 41

def send(method, data='{}')
  config_file = File.expand_path('~/.zbxconfig')
  default = File.exists?(config_file) ? YAML.load_file(config_file) : {}
  client = ZBX::API.new(options[:user] || default["user"],
                        options[:password] || default["password"],
                        options[:api_url] || default["api_url"])
  # x = method.split('.')
  say client.request method, JSON.parse(data)
  # say client.send(x.first).send(x.last, JSON.parse(data))
end