zabbix_send 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +6 -0
- data/LICENSE +22 -0
- data/README.md +30 -0
- data/Rakefile +2 -0
- data/lib/zabbix_send/version.rb +3 -0
- data/lib/zabbix_send.rb +45 -0
- data/zabbix_send.gemspec +17 -0
- metadata +59 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Mike English
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# ZabbixSend
|
2
|
+
|
3
|
+
A Ruby implementation of Zabbix sender protocol.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'zabbix_send'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install zabbix_send
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
sender = ZabbixSend::Sender.new
|
22
|
+
sender.send("zabbixserver","zabbixhost","zabbixitem.key","value")
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
1. Fork it
|
27
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
28
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
29
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
30
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/zabbix_send.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require "zabbix_send/version"
|
2
|
+
require 'json'
|
3
|
+
require 'socket'
|
4
|
+
|
5
|
+
module ZabbixSend
|
6
|
+
class Sender
|
7
|
+
def self.build_message(zhost,zkey,zvalue)
|
8
|
+
msg = {
|
9
|
+
"request" => "sender data",
|
10
|
+
"data" => [
|
11
|
+
{
|
12
|
+
"host" => zhost,
|
13
|
+
"key" => zkey,
|
14
|
+
"value" => zvalue,
|
15
|
+
}]
|
16
|
+
}
|
17
|
+
body = JSON.generate msg
|
18
|
+
data_length = body.bytesize
|
19
|
+
data_header = "ZBXD\1".encode("ascii") + \
|
20
|
+
[data_length].pack("i") + \
|
21
|
+
"\x00\x00\x00\x00"
|
22
|
+
data_to_send = data_header + body
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.send_message(message, server, port)
|
26
|
+
s = TCPSocket.new(server, port)
|
27
|
+
s.write message
|
28
|
+
response_header = s.recv(5)
|
29
|
+
if not response_header == "ZBXD\1"
|
30
|
+
puts "response: #{response_header}"
|
31
|
+
raise 'Got invalid response'
|
32
|
+
end
|
33
|
+
response_data_header = s.recv(8)
|
34
|
+
response_length = response_data_header[0,4].unpack("i")[0]
|
35
|
+
response_raw = s.recv(response_length)
|
36
|
+
s.close
|
37
|
+
response = JSON.load response_raw
|
38
|
+
end
|
39
|
+
|
40
|
+
def zabbix_send(zserver, zhost,zkey,zvalue)
|
41
|
+
z_send = Sender.build_message zhost, zkey, zvalue
|
42
|
+
Sender.send_message z_send, zserver, 10051
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/zabbix_send.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/zabbix_send/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Mike English"]
|
6
|
+
gem.email = ["mike.english@atomicobject.com"]
|
7
|
+
gem.description = %q{Send data to Zabbix trappers from Ruby}
|
8
|
+
gem.summary = %q{Ruby implementation of Zabbix sender protocol}
|
9
|
+
gem.homepage = "https://github.com/englishm/zabbbix_send"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "zabbix_send"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = ZabbixSend::VERSION
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zabbix_send
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mike English
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-10 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Send data to Zabbix trappers from Ruby
|
15
|
+
email:
|
16
|
+
- mike.english@atomicobject.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/zabbix_send.rb
|
27
|
+
- lib/zabbix_send/version.rb
|
28
|
+
- zabbix_send.gemspec
|
29
|
+
homepage: https://github.com/englishm/zabbbix_send
|
30
|
+
licenses: []
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
hash: 776411990839959046
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
segments:
|
51
|
+
- 0
|
52
|
+
hash: 776411990839959046
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.8.24
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: Ruby implementation of Zabbix sender protocol
|
59
|
+
test_files: []
|