zabbix_send 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.gem
2
2
  *.rbc
3
+ *.swp
3
4
  .bundle
4
5
  .config
5
6
  .yardoc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
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
@@ -1,6 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem "rake"
4
+ gem "rspec"
4
5
 
5
6
  # Specify your gem's dependencies in zabbix_send.gemspec
6
7
  gemspec
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. 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
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
@@ -1,2 +1,10 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ desc "Rull all specs"
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.pattern = "spec/**/*_spec.rb"
8
+ end
9
+ task :default => :spec
10
+
@@ -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[0,4].unpack("i")[0]
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, zhost,zkey,zvalue)
41
- z_send = Sender.build_message zhost, zkey, zvalue
42
- Sender.send_message z_send, zserver, 10051
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
@@ -1,3 +1,3 @@
1
1
  module ZabbixSend
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+
3
+ describe ZabbixSend do
4
+ it "should have a place for tests" do
5
+ # TODO: write tests
6
+ end
7
+ 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
- version: 0.0.2
5
- prerelease:
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
- date: 2012-10-10 00:00:00.000000000 Z
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
- files:
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
- require_paths:
49
+
50
+ require_paths:
34
51
  - 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:
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
42
57
  - 0
43
- hash: -1766732450666042547
44
- required_rubygems_version: !ruby/object:Gem::Requirement
45
- none: false
46
- requirements:
47
- - - ! '>='
48
- - !ruby/object:Gem::Version
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
- hash: -1766732450666042547
65
+ version: "0"
53
66
  requirements: []
67
+
54
68
  rubyforge_project:
55
- rubygems_version: 1.8.24
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