sky_zabbix 2.4.0.1.1 → 2.4.0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fb647d368370fcae96f40b4bec79c2c8ac12df2
4
- data.tar.gz: 609a93e458e73c4722ae198b1057b17ab346f1b5
3
+ metadata.gz: 88126fe264f9f23743b4070832f3488d3c133b94
4
+ data.tar.gz: c0fb42cfd106f0cafd9a83c3b70fbd7fb099c674
5
5
  SHA512:
6
- metadata.gz: 49b47e355888f9778153849432a4616b676b2c7417262ae9533a19f7d7d77de807d98a84147096ac84e426b113cb443e2b8488335706a98be27b0de82ef480e1
7
- data.tar.gz: 7bfea44310ff870fadc04bb8f05b59576a709a1b92f6f81468a25555203fe5c5e588de5cc2969f872f55f84ec5400d465d68e38dad6c0bf0d093fd3af7627459
6
+ metadata.gz: bd187bc00c8411decdae5a3ce5145a88ad4edb40489000a470e0feca7c3cd5a79157ffba5783262234c0fca078ea5ccc0daa4867892b6452dac654653a69d936
7
+ data.tar.gz: c0936ecee108baed4826554888390e126401d972dd0120abb0366d1c4a7eacca06617838742b0f0933dd8df93ce5481910eb1886d293bd303e06c3f1b5328d1b
data/README.md CHANGED
@@ -89,7 +89,21 @@ requests = []
89
89
  requests.push client.host.build_get()
90
90
  requests.push client.user.build_get()
91
91
  requests.push client.hostgroup.build_get()
92
- host_resp, user_resp, hostgroup_resp = cleint.batch(*requests)
92
+ host_resp, user_resp, hostgroup_resp = client.batch(*requests)
93
+ ```
94
+
95
+ ### Logger
96
+
97
+ Don't log on default.
98
+ If logger is received to constructor, SkyZabbix start logging.
99
+
100
+ ```ruby
101
+ require 'logger'
102
+ logger = Logger.new(STDOUT)
103
+ client = SkyZabbix::Client.new(zabbix_url, logger: logger)
104
+ client.login(zabbix_user, zabbix_pass)
105
+
106
+ client.host.get() # => I, [2015-06-29T17:35:19.609971 #3500] INFO -- : [SkyZabbix 200 5.296144592] host.get({})
93
107
  ```
94
108
 
95
109
  ## Development
data/Rakefile CHANGED
@@ -3,14 +3,11 @@ require "rspec/core/rake_task"
3
3
  require 'open3'
4
4
  require 'json'
5
5
 
6
- require_relative 'lib/sky_zabbix/version'
7
-
8
6
  RSpec::Core::RakeTask.new(:spec)
9
7
 
10
8
  task :default => :spec
11
9
 
12
10
  namespace :generate do
13
- #TODO: clone zabbix/zabbix, version
14
11
  desc "Generate list of method"
15
12
  task :methods do |task, args|
16
13
  out, err, status = Open3.capture3("php", "build.php")
@@ -27,12 +24,40 @@ namespace :release do
27
24
  task :all do |task, args|
28
25
  exec = -> (cmd) {
29
26
  print '> '; puts cmd.join(' ')
30
- system(*cmd)
27
+ r = system(*cmd)
28
+ unless r
29
+ raise "#{cmd} exit with #{$?}"
30
+ end
31
+ }
32
+
33
+ get_env = -> (name) {
34
+ v = ENV[name]
35
+ raise "#{name} environment variable should be set!" unless v
36
+ return v
31
37
  }
32
38
 
33
39
  versions = %w[2.2 2.4]
34
- path = ENV['PATH_ZABBIX']
40
+ path = get_env.('PATH_ZABBIX')
41
+ lib_version = get_env.('LIB_VERSION')
35
42
 
43
+ # check git status
44
+ unless `git status --short`.empty?
45
+ raise "Should commit some changes."
46
+ end
47
+
48
+ # Update version
49
+ v_path = File.expand_path('../lib/sky_zabbix/version.rb', __FILE__)
50
+ f = File.read(v_path)
51
+ f[/^\s+LIB_VERSION = "([\d.]+)"$/, 1] = lib_version
52
+ File.write(v_path, f)
53
+
54
+ # version up commit and add tag and push.
55
+ exec.(%W[git commit -am "Bump\ up\ version to #{lib_version}"])
56
+ exec.(%W[git tag v#{lib_version}])
57
+ exec.(%w[git push])
58
+ exec.(%W[git push origin v#{lib_version}])
59
+
60
+ # build gems
36
61
  versions.each do |v|
37
62
  Dir.chdir(path) do
38
63
  latest_tag = `git tag`.split("\n").select{|x|x =~ /^#{Regexp.escape(v)}/}.sort{|a, b|a[/\.(\d+)$/, 1].to_i <=> b[/\.(\d+)$/, 1].to_i}.last
@@ -41,7 +66,9 @@ namespace :release do
41
66
  Rake::Task['generate:methods'].execute
42
67
  Rake::Task['build'].execute
43
68
  end
44
- pkgs = Dir.glob(File.join(File.expand_path('../pkg/', __FILE__), "sky_zabbix-*#{SkyZabbix::LIB_VERSION}.gem"))
69
+
70
+ pkgs = Dir.glob(File.join(File.expand_path('../pkg/', __FILE__), "sky_zabbix-*#{lib_version}.gem"))
71
+ # Push gems
45
72
  pkgs.each do |p|
46
73
  exec.(%W[gem push #{p}])
47
74
  end
@@ -1,3 +1,4 @@
1
+ # TargetBase is a Base Class for target of Zabbix API method.
1
2
  # @abstract
2
3
  class SkyZabbix::Client::TargetBase
3
4
  # @return [String]
@@ -14,6 +15,7 @@ class SkyZabbix::Client::TargetBase
14
15
  @client = client
15
16
  end
16
17
 
18
+ # Returns list of filtered primary key.
17
19
  # @param [Hash] filter
18
20
  # @return [Array<String>] List of ID
19
21
  def get_ids(filter)
@@ -24,6 +26,7 @@ class SkyZabbix::Client::TargetBase
24
26
  return _query('get', params).map{|x|x[pk]}
25
27
  end
26
28
 
29
+ # Return filtered primary key of founded first.
27
30
  # @param [Hash] filter
28
31
  # @return [Array<String>] ID of founded first.
29
32
  def get_id(filter)
@@ -40,6 +43,7 @@ class SkyZabbix::Client::TargetBase
40
43
 
41
44
  # @param [String] method is method name. ex) get, create, delete ...
42
45
  # @param [Any] params is parameters.
46
+ # @return [Hash{Symbol => Any}]
43
47
  def _build(method, params)
44
48
  raise "Should use method of sub class!" unless _zbx_class
45
49
  @client.build("#{_zbx_class}.#{method}", params)
@@ -49,4 +53,9 @@ class SkyZabbix::Client::TargetBase
49
53
  def _zbx_class
50
54
  return self.class._zbx_class
51
55
  end
56
+
57
+ # @abstract
58
+ def pk
59
+ raise 'Should override pk method!'
60
+ end
52
61
  end
@@ -13,12 +13,17 @@ methods.each do |name, v|
13
13
  v[:methods].each do |method|
14
14
  # Generate query method.
15
15
  # Example: user.login()
16
+ # @param [Any] params
17
+ # @return [Any] return query response.
16
18
  define_method(method) do |params={}|
17
19
  _query(method, params)
18
20
  end
19
21
 
20
22
  # Generate build method. For batch request
21
23
  # Example: user.build_login()
24
+ # @param [Any] params
25
+ # @return [Hash{}] return query response.
26
+ # @return [Hash{Symbol => Any}]
22
27
  define_method("build_#{method}") do |params={}|
23
28
  _build(method, params)
24
29
  end
@@ -12,6 +12,7 @@ class SkyZabbix::Jsonrpc
12
12
 
13
13
  attr_accessor :token
14
14
 
15
+ # Send normal request.
15
16
  # @param [String] method is json-rpc method name.
16
17
  # @param [Any?] params is json-rpc parameters.
17
18
  # @param [Boolean] notification
@@ -19,23 +20,7 @@ class SkyZabbix::Jsonrpc
19
20
  request(build(method, params, notification: notification))
20
21
  end
21
22
 
22
- # @param [Hash{String => Any}] builded is result of 'build' method.
23
- # @return [Any?] return result of response
24
- def request(builded)
25
- uri = URI.parse(@uri)
26
-
27
- resp = do_req(uri, builded)
28
-
29
- return nil unless builded[:id] # when notification
30
-
31
- # Parse and error handling
32
- body = JSON.parse(resp.body)
33
- raise Error.create(body) if body['error']
34
-
35
- return body['result']
36
- end
37
-
38
- # XXX: エラー処理はこれでいい?
23
+ # Send batch request.
39
24
  # @example Return values.
40
25
  # rpc.batch(
41
26
  # rpc.build('a', 'A'),
@@ -50,7 +35,8 @@ class SkyZabbix::Jsonrpc
50
35
  # ) # => Error::BatchError.
51
36
  # # Can get response of 'a' from ex.result
52
37
  # @param [Array<Hash>] buildeds is Array of result of 'build' method.
53
- # @return [Array<Any|Error|nil>]
38
+ # @return [Array<Any|nil>]
39
+ # @raise [Error::BatchError]
54
40
  def batch(buildeds)
55
41
  uri = URI.parse(@uri)
56
42
  resp = do_req(uri, buildeds)
@@ -83,6 +69,7 @@ class SkyZabbix::Jsonrpc
83
69
  # @param [String] method is json-rpc method name.
84
70
  # @param [Any?] params is json-rpc parameters.
85
71
  # @param [Boolean] notification
72
+ # @return [Hash{Symbol => Any}]
86
73
  def build(method, params, notification: false)
87
74
  res = {
88
75
  jsonrpc: VERSION,
@@ -98,6 +85,22 @@ class SkyZabbix::Jsonrpc
98
85
 
99
86
  private
100
87
 
88
+ # @param [Hash{String => Any}] builded is result of 'build' method.
89
+ # @return [Any?] return result of response
90
+ def request(builded)
91
+ uri = URI.parse(@uri)
92
+
93
+ resp = do_req(uri, builded)
94
+
95
+ return nil unless builded[:id] # when notification
96
+
97
+ # Parse and error handling
98
+ body = JSON.parse(resp.body)
99
+ raise Error.create(body) if body['error']
100
+
101
+ return body['result']
102
+ end
103
+
101
104
  # @return [Integer] random ID.
102
105
  def id_gen
103
106
  return rand(10**12)
@@ -131,7 +134,7 @@ class SkyZabbix::Jsonrpc
131
134
  # @param [Hash|Array] body is request body.
132
135
  # @param [Net::HTTPResponse] resp
133
136
  def logging_request(start_time, body, resp)
134
- return unless @logger
137
+ return unless @logger && resp
135
138
 
136
139
  sec = Time.now - start_time
137
140
  msg_body =
@@ -1,4 +1,5 @@
1
1
  class SkyZabbix::Jsonrpc::Error < StandardError
2
+ # @param [Array<Hash{String => Any}>] body is response body.
2
3
  def initialize(body)
3
4
  @error = body['error']
4
5
  msg = "#{@error['message']} #{@error['data']}"
@@ -13,6 +14,8 @@ class SkyZabbix::Jsonrpc::Error < StandardError
13
14
  class InternalError < self; end # Internal JSON-RPC error.
14
15
  class ServerError < self; end # Reserved for implementation-defined server-errors.
15
16
 
17
+ # @param [Array<Hash{String => Any}>] body is response body.
18
+ # @return [Error] A Error instance.
16
19
  def self.create(body)
17
20
  klass =
18
21
  case body['code']
@@ -41,7 +44,7 @@ class SkyZabbix::Jsonrpc::Error < StandardError
41
44
  return errors.map(&:message).join(', ')
42
45
  end
43
46
 
44
- # @param [Array<Hash<String => Any>] body is response body.
47
+ # @param [Array<Hash{String => Any}>] body is response body.
45
48
  # @return [Boolean]
46
49
  def self.error?(body)
47
50
  return body.any?{|x|x['error']}
@@ -1,7 +1,7 @@
1
1
  require 'json'
2
2
 
3
3
  module SkyZabbix
4
- LIB_VERSION = "0.1.1"
4
+ LIB_VERSION = "0.1.2"
5
5
  ZABBIX_VERSION = JSON.parse(File.read(File.expand_path('../methods.json', __FILE__)), symbolize_names: true)[:version]
6
6
  VERSION = ZABBIX_VERSION + '.' + LIB_VERSION
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sky_zabbix
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0.1.1
4
+ version: 2.4.0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Skyarch Networks Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-29 00:00:00.000000000 Z
11
+ date: 2016-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  version: '0'
144
144
  requirements: []
145
145
  rubyforge_project:
146
- rubygems_version: 2.4.5
146
+ rubygems_version: 2.4.5.1
147
147
  signing_key:
148
148
  specification_version: 4
149
149
  summary: An API Wrapper of Zabbix