lib/zabbix-ruby-client/cli.rb in zabbix-ruby-client-0.0.15 vs lib/zabbix-ruby-client/cli.rb in zabbix-ruby-client-0.0.16
- old
+ new
@@ -1,9 +1,9 @@
require "thor"
-require "zabbix-ruby-client"
+require "zabbix-ruby-client/runner"
-class ZabbixRubyClient
+module ZabbixRubyClient
class Cli < Thor
include Thor::Actions
def self.source_root
@@ -33,17 +33,33 @@
Bundler.require
rescue Bundler::GemfileNotFound
say "No Gemfile found", :red
abort
end
- zrc = ZabbixRubyClient.new(options[:configfile],options[:taskfile])
+ config = YAML::load_file(options[:configfile])
+ if File.exists? options[:taskfile]
+ tasks = YAML::load_file(options[:taskfile])
+ else
+ tasks = config['plugins']
+ end
+ config['server'] = File.basename(options[:configfile],'.yml')
+ config['taskfile'] = File.basename(options[:taskfile],'.yml')
+ zrc = ZabbixRubyClient::Runner.new(config, tasks)
zrc.collect
zrc.show
end
desc "upload", "Collects and sends data to the zabbix server"
def upload
- zrc = ZabbixRubyClient.new(options[:configfile],options[:taskfile])
+ config = YAML::load_file(options[:configfile])
+ if File.exists? options[:taskfile]
+ tasks = YAML::load_file(options[:taskfile])
+ else
+ tasks = config['plugins']
+ end
+ config['server'] = File.basename(options[:configfile],'.yml')
+ config['taskfile'] = File.basename(options[:taskfile],'.yml')
+ zrc = ZabbixRubyClient::Runner.new(config, tasks)
zrc.collect
zrc.upload
end
end