zabbix_send 0.0.2 → 0.0.3
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 +1 -0
- data/.rspec +2 -0
- data/.rvmrc +52 -0
- data/Gemfile +1 -0
- data/README.md +6 -3
- data/Rakefile +8 -0
- data/lib/zabbix_send.rb +9 -9
- data/lib/zabbix_send/version.rb +1 -1
- data/spec/spec_helper.rb +17 -0
- data/spec/zabbix_send_spec.rb +7 -0
- metadata +43 -27
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p194@zabbix_send"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.13.8 (stable)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
if [[ $- == *i* ]] # check for interactive shells
|
29
|
+
then echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
|
30
|
+
else echo "Using: $GEM_HOME" # don't use colors in non-interactive shells
|
31
|
+
fi
|
32
|
+
else
|
33
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
34
|
+
rvm --create use "$environment_id" || {
|
35
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
36
|
+
return 1
|
37
|
+
}
|
38
|
+
fi
|
39
|
+
|
40
|
+
# If you use bundler, this might be useful to you:
|
41
|
+
# if [[ -s Gemfile ]] && {
|
42
|
+
# ! builtin command -v bundle >/dev/null ||
|
43
|
+
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
44
|
+
# }
|
45
|
+
# then
|
46
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
47
|
+
# gem install bundler
|
48
|
+
# fi
|
49
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
50
|
+
# then
|
51
|
+
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
52
|
+
# fi
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -18,6 +18,7 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
+
require 'zabbix_send'
|
21
22
|
sender = ZabbixSend::Sender.new
|
22
23
|
sender.send("zabbixserver","zabbixhost","zabbixitem.key","value")
|
23
24
|
|
@@ -25,6 +26,8 @@ Or install it yourself as:
|
|
25
26
|
|
26
27
|
1. Fork it
|
27
28
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
28
|
-
3.
|
29
|
-
4.
|
30
|
-
5.
|
29
|
+
3. Write tests for the new feature. (cf. `spec/`)
|
30
|
+
4. Write the new feature.
|
31
|
+
5. Commit your changes (`git commit -am 'Added some feature'`)
|
32
|
+
6. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
7. Create new Pull Request
|
data/Rakefile
CHANGED
data/lib/zabbix_send.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require "zabbix_send/version"
|
2
2
|
require 'json'
|
3
3
|
require 'socket'
|
4
|
+
require 'time'
|
4
5
|
|
5
6
|
module ZabbixSend
|
6
7
|
class Sender
|
7
|
-
def self.build_message(zhost,zkey,zvalue)
|
8
|
+
def self.build_message(zhost,zkey,zvalue,ztime)
|
8
9
|
msg = {
|
9
10
|
"request" => "sender data",
|
10
11
|
"data" => [
|
@@ -12,13 +13,12 @@ module ZabbixSend
|
|
12
13
|
"host" => zhost,
|
13
14
|
"key" => zkey,
|
14
15
|
"value" => zvalue,
|
16
|
+
"clock" => ztime
|
15
17
|
}]
|
16
18
|
}
|
17
19
|
body = JSON.generate msg
|
18
20
|
data_length = body.bytesize
|
19
|
-
data_header = "ZBXD\1".encode("ascii") +
|
20
|
-
[data_length].pack("i") + \
|
21
|
-
"\x00\x00\x00\x00"
|
21
|
+
data_header = "ZBXD\1".encode("ascii") + [data_length].pack("Q")
|
22
22
|
data_to_send = data_header + body
|
23
23
|
end
|
24
24
|
|
@@ -31,15 +31,15 @@ module ZabbixSend
|
|
31
31
|
raise 'Got invalid response'
|
32
32
|
end
|
33
33
|
response_data_header = s.recv(8)
|
34
|
-
response_length = response_data_header
|
34
|
+
response_length = response_data_header.unpack("Q")[0]
|
35
35
|
response_raw = s.recv(response_length)
|
36
36
|
s.close
|
37
37
|
response = JSON.load response_raw
|
38
38
|
end
|
39
39
|
|
40
|
-
def zabbix_send(zserver,
|
41
|
-
z_send = Sender.build_message zhost, zkey, zvalue
|
42
|
-
Sender.send_message z_send, zserver,
|
40
|
+
def zabbix_send(zserver,zhost,zkey,zvalue,ztime=Time.now.to_i,zport=10051)
|
41
|
+
z_send = Sender.build_message zhost, zkey, zvalue, ztime
|
42
|
+
Sender.send_message z_send, zserver, zport
|
43
43
|
end
|
44
44
|
end
|
45
|
-
end
|
45
|
+
end
|
data/lib/zabbix_send/version.rb
CHANGED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
metadata
CHANGED
@@ -1,59 +1,75 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: zabbix_send
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Mike English
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
16
|
+
|
17
|
+
date: 2013-06-22 00:00:00 -04:00
|
18
|
+
default_executable:
|
13
19
|
dependencies: []
|
20
|
+
|
14
21
|
description: Send data to Zabbix trappers from Ruby
|
15
|
-
email:
|
22
|
+
email:
|
16
23
|
- mike.english@atomicobject.com
|
17
24
|
executables: []
|
25
|
+
|
18
26
|
extensions: []
|
27
|
+
|
19
28
|
extra_rdoc_files: []
|
20
|
-
|
29
|
+
|
30
|
+
files:
|
21
31
|
- .gitignore
|
32
|
+
- .rspec
|
33
|
+
- .rvmrc
|
22
34
|
- Gemfile
|
23
35
|
- LICENSE
|
24
36
|
- README.md
|
25
37
|
- Rakefile
|
26
38
|
- lib/zabbix_send.rb
|
27
39
|
- lib/zabbix_send/version.rb
|
40
|
+
- spec/spec_helper.rb
|
41
|
+
- spec/zabbix_send_spec.rb
|
28
42
|
- zabbix_send.gemspec
|
43
|
+
has_rdoc: true
|
29
44
|
homepage: https://github.com/englishm/zabbix_send
|
30
45
|
licenses: []
|
46
|
+
|
31
47
|
post_install_message:
|
32
48
|
rdoc_options: []
|
33
|
-
|
49
|
+
|
50
|
+
require_paths:
|
34
51
|
- lib
|
35
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
version: '0'
|
41
|
-
segments:
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
42
57
|
- 0
|
43
|
-
|
44
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
version: '0'
|
50
|
-
segments:
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
51
64
|
- 0
|
52
|
-
|
65
|
+
version: "0"
|
53
66
|
requirements: []
|
67
|
+
|
54
68
|
rubyforge_project:
|
55
|
-
rubygems_version: 1.
|
69
|
+
rubygems_version: 1.3.6
|
56
70
|
signing_key:
|
57
71
|
specification_version: 3
|
58
72
|
summary: Ruby implementation of the Zabbix sender protocol
|
59
|
-
test_files:
|
73
|
+
test_files:
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
- spec/zabbix_send_spec.rb
|