#!/usr/bin/env ruby RUBIX_ROOT = File.expand_path('../../lib', __FILE__) $: << RUBIX_ROOT unless $:.include?(RUBIX_ROOT) require 'rubix' require 'configliere' Settings.use :commandline Settings.use :env_var Settings.define 'verbose', :description => "Be verbose", :required => false, :type => :boolean, :default => false # # Configuration for talking with the Zabbix server # Settings.define 'server', :description => "Hostname/IP of the Zabbix server", :required => true, :default => 'localhost' Settings.define 'host', :description => "Name of the (possibly new) Zabbix host to write data to", :required => true Settings.define 'configuration_file', :description => "Path to the Zabbix agent configuration file", :required => true, :default => '/etc/zabbix/zabbix_agentd.conf' # # Configuration for talking with the Zabbix API # Settings.define 'url', :description => "URL of the Zabbix API", :required => true, :default => 'localhost/api_jsonrpc.php' Settings.define 'username', :description => "Username for the Zabbix API", :required => false, :env_var => "ZABBIX_API_USERNAME", :default => 'admin' Settings.define 'password', :description => "Password for the Zabbix API", :required => false, :env_var => "ZABBIX_API_PASSWORD", :default => 'zabbix' Settings.define 'server_error_sleep', :description => "Seconds to sleep after a 50x error from the server", :required => true, :type => Integer, :default => 1 Settings.define 'fast', :description => "Run *fast* by not bothering to auto-vivify objects via the API", :type => :boolean, :default => false # # Define parameters for dynamically creating a new host. # Settings.define 'host_groups', :description => "Comma-separated hostgroup names to use when creating a new host", :required => false Settings.define 'templates', :description => "Comma-separated template names to use when creating a new host", :required => false # # Define parameters for dynamically creating a new item. # Settings.define 'create_item_sleep', :description => "Number of seconds to sleep after creating a new Item", :required => true, :default => 0, :type => Integer Settings.define 'application', :description => "Name of the Application created Items will be scoped by", :required => false # # Define local paths will be used to read and send data. # Settings.define 'sender', :description => "Path to the zabbix_sender program", :required => true, :default => 'zabbix_sender' Settings.define 'pipe', :description => "Path to the named pipe to read from", :required => false Settings.define 'pipe_read_sleep', :description => "Seconds to sleep between reads from pipe", :required => true, :type => Float, :default => 0.1 begin Settings.resolve! rescue RuntimeError => e $stderr.puts e.message exit(1) end begin Rubix.connect((Settings[:url] || File.join(Settings[:server], 'api_jsonrpc.php')), Settings[:username], Settings[:password]) rescue Rubix::Error => e $stderr.puts e.message exit(1) end begin sender = Rubix::AutoSender.new(Settings) rescue Rubix::Error => e $stderr.puts e.message exit(1) end begin sender.run rescue => e $stderr.puts "#{e.class} -- #{e.message}" end