Sha256: fdd8a05945b7ee1ba649e6d48698dfd4366424c8cc53acd24b7ba18a7e500085

Contents?: true

Size: 1.47 KB

Versions: 4

Compression:

Stored size: 1.47 KB

Contents

require "thor"
require "zabbix-ruby-client"

module ZabbixRubyClient

  class Cli < Thor
    include Thor::Actions

    def self.source_root
      File.expand_path("../../../templates", __FILE__)
    end

    default_task :help
    class_option :configfile,
      aliases: "-c",
      banner: "PATH",
      default: File.expand_path("config.yml", Dir.pwd),
      desc: "Path to the configuration file to use"
    class_option :taskfile,
      aliases: "-t",
      banner: "PATH",
      default: File.expand_path("minutely.yml", Dir.pwd),
      desc: "Path to the list of plugins to execute"

    desc "init", "Initialize a new zabbix ruby client"
    def init(name = "zabbix-ruby-client")
      directory "client", name
    end

    desc "show", "Displays in console what are the collected data ready to be sent"
    def show
      collect(options).show
    end

    desc "upload", "Collects and sends data to the zabbix server"
    def upload
      collect(options).upload
    end

    no_commands do
      def collect(options)
        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
      end
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zabbix-ruby-client-0.1.3 lib/zabbix-ruby-client/cli.rb
zabbix-ruby-client-0.1.2 lib/zabbix-ruby-client/cli.rb
zabbix-ruby-client-0.1.1 lib/zabbix-ruby-client/cli.rb
zabbix-ruby-client-0.1.0 lib/zabbix-ruby-client/cli.rb