zabbix 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/zabbix/sender.rb +25 -23
- data/lib/zabbix/sender/buffer.rb +2 -6
- data/zabbix.gemspec +6 -11
- metadata +9 -10
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ begin
|
|
10
10
|
gem.email = "mknopp@yammer-inc.com"
|
11
11
|
gem.homepage = "http://github.com/mhat/zabbix"
|
12
12
|
gem.authors = ["Matthew Knopp"]
|
13
|
-
gem.add_development_dependency "
|
13
|
+
gem.add_development_dependency "shoulda", ">= 0"
|
14
14
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
15
|
end
|
16
16
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/zabbix/sender.rb
CHANGED
@@ -2,36 +2,38 @@ class Zabbix::Sender
|
|
2
2
|
|
3
3
|
DEFAULT_SERVER_PORT = 10051
|
4
4
|
|
5
|
-
attr_reader :configured
|
5
|
+
attr_reader :configured
|
6
6
|
|
7
7
|
def initialize(opts={})
|
8
|
+
@client_host = Socket.gethostbyname(Socket.gethostname)[0]
|
9
|
+
|
8
10
|
if opts[:config_file]
|
9
11
|
config = Zabbix::Agent::Configuration.read(opts[:config_file])
|
10
|
-
@
|
11
|
-
@
|
12
|
+
@server_host = config.server
|
13
|
+
@server_port = config.server_port || DEFAULT_SERVER_PORT
|
12
14
|
end
|
13
15
|
|
14
16
|
if opts[:host]
|
15
|
-
@
|
16
|
-
@
|
17
|
+
@server_host = opts[:host]
|
18
|
+
@server_port = opts[:port] || DEFAULT_SERVER_PORT
|
17
19
|
end
|
18
20
|
|
19
21
|
end
|
20
22
|
|
21
23
|
|
22
24
|
def configured?
|
23
|
-
@configured ||= !(@
|
25
|
+
@configured ||= !(@server_host.nil? and @server_port.nil?)
|
24
26
|
end
|
25
27
|
|
26
28
|
|
27
29
|
def connect
|
28
|
-
@socket ||= TCPSocket.new(@
|
30
|
+
@socket ||= TCPSocket.new(@server_host, @server_port)
|
29
31
|
end
|
30
32
|
|
31
33
|
def disconnect
|
32
34
|
if @socket
|
33
35
|
@socket.close unless @socket.closed?
|
34
|
-
@socket = nil
|
36
|
+
@socket = nil
|
35
37
|
end
|
36
38
|
return true
|
37
39
|
end
|
@@ -41,7 +43,7 @@ class Zabbix::Sender
|
|
41
43
|
end
|
42
44
|
|
43
45
|
|
44
|
-
def send_stop(key, opts={})
|
46
|
+
def send_stop(key, opts={})
|
45
47
|
send_data("#{key}.stop", 1, opts)
|
46
48
|
end
|
47
49
|
|
@@ -54,36 +56,36 @@ class Zabbix::Sender
|
|
54
56
|
end
|
55
57
|
|
56
58
|
def send_data(key, value, opts={})
|
57
|
-
return false unless configured?
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
59
|
+
return false unless configured?
|
60
|
+
return send_zabbix_request([
|
61
|
+
cons_zabbix_data_element(key, value, opts)
|
62
|
+
])
|
63
|
+
end
|
62
64
|
|
63
|
-
private
|
65
|
+
private
|
64
66
|
|
65
|
-
def cons_zabbix_data_element(
|
67
|
+
def cons_zabbix_data_element(key, value, opts={})
|
66
68
|
return {
|
67
|
-
:
|
68
|
-
:key => key,
|
69
|
+
:key => key,
|
69
70
|
:value => value,
|
70
|
-
:
|
71
|
+
:host => opts[:host] || @client_host,
|
72
|
+
:clock => opts[:ts ] || Time.now.to_i,
|
71
73
|
}
|
72
74
|
end
|
73
75
|
|
74
76
|
def send_zabbix_request(data)
|
75
77
|
status = false
|
76
78
|
request = Yajl::Encoder.encode({
|
77
|
-
:request => 'agent data' ,
|
79
|
+
:request => 'agent data' ,
|
78
80
|
:clock => Time.now.to_i,
|
79
81
|
:data => data
|
80
82
|
})
|
81
83
|
|
82
|
-
begin
|
84
|
+
begin
|
83
85
|
sock = connect
|
84
86
|
sock.write "ZBXD\x01"
|
85
87
|
sock.write [request.size].pack('q')
|
86
|
-
sock.write request
|
88
|
+
sock.write request
|
87
89
|
sock.flush
|
88
90
|
|
89
91
|
# FIXME: check header to make sure it's the message we expect?
|
@@ -96,7 +98,7 @@ class Zabbix::Sender
|
|
96
98
|
## FIXME
|
97
99
|
ensure
|
98
100
|
disconnect
|
99
|
-
end
|
101
|
+
end
|
100
102
|
|
101
103
|
return status
|
102
104
|
end
|
data/lib/zabbix/sender/buffer.rb
CHANGED
@@ -6,12 +6,7 @@ class Zabbix::Sender::Buffer < Zabbix::Sender
|
|
6
6
|
|
7
7
|
def append(key, value, opts={})
|
8
8
|
return false unless configured?
|
9
|
-
@buffer <<
|
10
|
-
:host => opts[:host] || Socket.gethostname,
|
11
|
-
:clock => opts[:ts ] || Time.now.to_i,
|
12
|
-
:key => key,
|
13
|
-
:value => value,
|
14
|
-
}
|
9
|
+
@buffer << cons_zabbix_data_element(key, value, opts)
|
15
10
|
end
|
16
11
|
|
17
12
|
def flush
|
@@ -20,5 +15,6 @@ class Zabbix::Sender::Buffer < Zabbix::Sender
|
|
20
15
|
@buffer.clear
|
21
16
|
return ret
|
22
17
|
end
|
18
|
+
alias send! flush
|
23
19
|
|
24
20
|
end
|
data/zabbix.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{zabbix}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Matthew Knopp"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-10-28}
|
13
13
|
s.description = %q{send data to zabbix from ruby}
|
14
14
|
s.email = %q{mknopp@yammer-inc.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -34,24 +34,19 @@ Gem::Specification.new do |s|
|
|
34
34
|
]
|
35
35
|
s.homepage = %q{http://github.com/mhat/zabbix}
|
36
36
|
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version = %q{1.
|
37
|
+
s.rubygems_version = %q{1.5.2}
|
38
38
|
s.summary = %q{send data to zabbix from ruby}
|
39
|
-
s.test_files = [
|
40
|
-
"test/helper.rb",
|
41
|
-
"test/test_zabbix.rb"
|
42
|
-
]
|
43
39
|
|
44
40
|
if s.respond_to? :specification_version then
|
45
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
41
|
s.specification_version = 3
|
47
42
|
|
48
43
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
-
s.add_development_dependency(%q<
|
44
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
50
45
|
else
|
51
|
-
s.add_dependency(%q<
|
46
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
52
47
|
end
|
53
48
|
else
|
54
|
-
s.add_dependency(%q<
|
49
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
55
50
|
end
|
56
51
|
end
|
57
52
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zabbix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matthew Knopp
|
@@ -15,11 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-28 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: shoulda
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
@@ -86,10 +86,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements: []
|
87
87
|
|
88
88
|
rubyforge_project:
|
89
|
-
rubygems_version: 1.
|
89
|
+
rubygems_version: 1.5.2
|
90
90
|
signing_key:
|
91
91
|
specification_version: 3
|
92
92
|
summary: send data to zabbix from ruby
|
93
|
-
test_files:
|
94
|
-
|
95
|
-
- test/test_zabbix.rb
|
93
|
+
test_files: []
|
94
|
+
|