Class: ZabbixRubyClient
- Inherits:
-
Object
show all
- Defined in:
- lib/zabbix-ruby-client/plugins/cpu.rb,
lib/zabbix-ruby-client.rb,
lib/zabbix-ruby-client/cli.rb,
lib/zabbix-ruby-client/data.rb,
lib/zabbix-ruby-client/store.rb,
lib/zabbix-ruby-client/logger.rb,
lib/zabbix-ruby-client/plugins.rb,
lib/zabbix-ruby-client/version.rb,
lib/zabbix-ruby-client/plugins/apt.rb,
lib/zabbix-ruby-client/plugins/who.rb,
lib/zabbix-ruby-client/plugins/disk.rb,
lib/zabbix-ruby-client/plugins/load.rb,
lib/zabbix-ruby-client/plugins/mysql.rb,
lib/zabbix-ruby-client/plugins/nginx.rb,
lib/zabbix-ruby-client/plugins/redis.rb,
lib/zabbix-ruby-client/plugins/apache.rb,
lib/zabbix-ruby-client/plugins/memory.rb,
lib/zabbix-ruby-client/plugins/network.rb,
lib/zabbix-ruby-client/plugins/sysinfo.rb
Overview
this is a simple version for standalone redis server
Defined Under Namespace
Modules: Logger, Plugins
Classes: Cli, Data, Store
Instance Method Summary
collapse
Constructor Details
#initialize(config_file, task_file) ⇒ ZabbixRubyClient
Returns a new instance of ZabbixRubyClient.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/zabbix-ruby-client.rb', line 10
def initialize(config_file, task_file)
begin
@config ||= YAML::load_file(config_file)
if File.exists? task_file
@tasks ||= YAML::load_file(task_file)
else
@tasks = @config["plugins"]
end
rescue Exception => e
puts "Configuration file cannot be read"
puts e.message
return
end
@store = Store.new(
@config['datadir'],
@config['zabbix']['host'],
File.basename(task_file,'.yml'),
@config['keepdata']
)
@data = Data.new(@config['host'])
@config["server"] = File.basename(config_file,'.yml')
@logsdir = makedir(@config['logsdir'],'logs')
@plugindirs = [ File.expand_path("../zabbix-ruby-client/plugins", __FILE__) ]
if @config["plugindirs"]
@plugindirs = @plugindirs + @config["plugindirs"]
end
Plugins.load_dirs @plugindirs
logger.debug @config.inspect
end
|
Instance Method Details
#collect ⇒ Object
43
44
45
46
47
|
# File 'lib/zabbix-ruby-client.rb', line 43
def collect
@tasks.each do |plugin|
@data.run_plugin(plugin['name'], plugin['args'])
end
end
|
#logger ⇒ Object
69
70
71
|
# File 'lib/zabbix-ruby-client.rb', line 69
def logger
@logger ||= Logger.get_logger(@logsdir, @config["loglevel"])
end
|
#show ⇒ Object
49
50
51
52
53
|
# File 'lib/zabbix-ruby-client.rb', line 49
def show
@data.merge.each do |line|
puts line
end
end
|
#upload ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/zabbix-ruby-client.rb', line 55
def upload
file = @store.record(@data.merge)
begin
res = `#{@config['zabbix']['sender']} -z #{@config['zabbix']['host']} -p #{@config['zabbix']['port']} -T -i #{file}`
if $?.to_i != 0
@store.keepdata(file)
end
rescue Exception => e
@store.keepdata(file)
logger.error "Sending failed."
logger.error e.message
end
end
|