sky_zabbix 2.2.0.1.2 → 2.4.0.1.0
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.
- checksums.yaml +4 -4
- data/README.md +1 -18
- data/Rakefile +6 -33
- data/lib/sky_zabbix/client/target_base.rb +0 -9
- data/lib/sky_zabbix/client/target_gen.rb +0 -5
- data/lib/sky_zabbix/jsonrpc.rb +19 -22
- data/lib/sky_zabbix/jsonrpc/errors.rb +1 -4
- data/lib/sky_zabbix/version.rb +1 -1
- data/sky_zabbix.gemspec +0 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdac882c1ec3d242254cf9d78b53f6463d6a0c82
|
4
|
+
data.tar.gz: dfaabecd497386ec8356d13c14aed9b71acd3475
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b30adb1d063a50a7b23d45cab6347ad43958c90bad99b50545b34fdbd21583c0b6370db0baafc9bcb3163fe0085e67a70add6d705d67025f3bbfdb05b9e4494
|
7
|
+
data.tar.gz: d14d4562f206f73555e3a85fd6652063607a473b23e3c04c15a912e0d3177c1e23ffa3aad3e76c34b764572cfd9f042de62e8071487070e1c140e7c5b2f77c92
|
data/README.md
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
# SkyZabbix
|
2
2
|
|
3
|
-
[](http://badge.fury.io/rb/sky_zabbix)
|
4
|
-
[](http://inch-ci.org/github/skyarch-networks/sky_zabbix)
|
5
|
-
|
6
3
|
SkyZabbix is a Zabbix API Wrapper written by Ruby.
|
7
4
|
|
8
5
|
## Installation
|
@@ -89,21 +86,7 @@ requests = []
|
|
89
86
|
requests.push client.host.build_get()
|
90
87
|
requests.push client.user.build_get()
|
91
88
|
requests.push client.hostgroup.build_get()
|
92
|
-
host_resp, user_resp, hostgroup_resp =
|
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({})
|
89
|
+
host_resp, user_resp, hostgroup_resp = cleint.batch(*requests)
|
107
90
|
```
|
108
91
|
|
109
92
|
## Development
|
data/Rakefile
CHANGED
@@ -3,11 +3,14 @@ require "rspec/core/rake_task"
|
|
3
3
|
require 'open3'
|
4
4
|
require 'json'
|
5
5
|
|
6
|
+
require_relative 'lib/sky_zabbix/version'
|
7
|
+
|
6
8
|
RSpec::Core::RakeTask.new(:spec)
|
7
9
|
|
8
10
|
task :default => :spec
|
9
11
|
|
10
12
|
namespace :generate do
|
13
|
+
#TODO: clone zabbix/zabbix, version
|
11
14
|
desc "Generate list of method"
|
12
15
|
task :methods do |task, args|
|
13
16
|
out, err, status = Open3.capture3("php", "build.php")
|
@@ -24,40 +27,12 @@ namespace :release do
|
|
24
27
|
task :all do |task, args|
|
25
28
|
exec = -> (cmd) {
|
26
29
|
print '> '; puts cmd.join(' ')
|
27
|
-
|
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
|
30
|
+
system(*cmd)
|
37
31
|
}
|
38
32
|
|
39
33
|
versions = %w[2.2 2.4]
|
40
|
-
path
|
41
|
-
lib_version = get_env.('LIB_VERSION')
|
34
|
+
path = ENV['PATH_ZABBIX']
|
42
35
|
|
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
|
61
36
|
versions.each do |v|
|
62
37
|
Dir.chdir(path) do
|
63
38
|
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
|
@@ -66,9 +41,7 @@ namespace :release do
|
|
66
41
|
Rake::Task['generate:methods'].execute
|
67
42
|
Rake::Task['build'].execute
|
68
43
|
end
|
69
|
-
|
70
|
-
pkgs = Dir.glob(File.join(File.expand_path('../pkg/', __FILE__), "sky_zabbix-*#{lib_version}.gem"))
|
71
|
-
# Push gems
|
44
|
+
pkgs = Dir.glob(File.join(File.expand_path('../pkg/', __FILE__), "sky_zabbix-*#{SkyZabbix::LIB_VERSION}.gem"))
|
72
45
|
pkgs.each do |p|
|
73
46
|
exec.(%W[gem push #{p}])
|
74
47
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# TargetBase is a Base Class for target of Zabbix API method.
|
2
1
|
# @abstract
|
3
2
|
class SkyZabbix::Client::TargetBase
|
4
3
|
# @return [String]
|
@@ -15,7 +14,6 @@ class SkyZabbix::Client::TargetBase
|
|
15
14
|
@client = client
|
16
15
|
end
|
17
16
|
|
18
|
-
# Returns list of filtered primary key.
|
19
17
|
# @param [Hash] filter
|
20
18
|
# @return [Array<String>] List of ID
|
21
19
|
def get_ids(filter)
|
@@ -26,7 +24,6 @@ class SkyZabbix::Client::TargetBase
|
|
26
24
|
return _query('get', params).map{|x|x[pk]}
|
27
25
|
end
|
28
26
|
|
29
|
-
# Return filtered primary key of founded first.
|
30
27
|
# @param [Hash] filter
|
31
28
|
# @return [Array<String>] ID of founded first.
|
32
29
|
def get_id(filter)
|
@@ -43,7 +40,6 @@ class SkyZabbix::Client::TargetBase
|
|
43
40
|
|
44
41
|
# @param [String] method is method name. ex) get, create, delete ...
|
45
42
|
# @param [Any] params is parameters.
|
46
|
-
# @return [Hash{Symbol => Any}]
|
47
43
|
def _build(method, params)
|
48
44
|
raise "Should use method of sub class!" unless _zbx_class
|
49
45
|
@client.build("#{_zbx_class}.#{method}", params)
|
@@ -53,9 +49,4 @@ class SkyZabbix::Client::TargetBase
|
|
53
49
|
def _zbx_class
|
54
50
|
return self.class._zbx_class
|
55
51
|
end
|
56
|
-
|
57
|
-
# @abstract
|
58
|
-
def pk
|
59
|
-
raise 'Should override pk method!'
|
60
|
-
end
|
61
52
|
end
|
@@ -13,17 +13,12 @@ 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.
|
18
16
|
define_method(method) do |params={}|
|
19
17
|
_query(method, params)
|
20
18
|
end
|
21
19
|
|
22
20
|
# Generate build method. For batch request
|
23
21
|
# Example: user.build_login()
|
24
|
-
# @param [Any] params
|
25
|
-
# @return [Hash{}] return query response.
|
26
|
-
# @return [Hash{Symbol => Any}]
|
27
22
|
define_method("build_#{method}") do |params={}|
|
28
23
|
_build(method, params)
|
29
24
|
end
|
data/lib/sky_zabbix/jsonrpc.rb
CHANGED
@@ -12,7 +12,6 @@ class SkyZabbix::Jsonrpc
|
|
12
12
|
|
13
13
|
attr_accessor :token
|
14
14
|
|
15
|
-
# Send normal request.
|
16
15
|
# @param [String] method is json-rpc method name.
|
17
16
|
# @param [Any?] params is json-rpc parameters.
|
18
17
|
# @param [Boolean] notification
|
@@ -20,7 +19,23 @@ class SkyZabbix::Jsonrpc
|
|
20
19
|
request(build(method, params, notification: notification))
|
21
20
|
end
|
22
21
|
|
23
|
-
#
|
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: エラー処理はこれでいい?
|
24
39
|
# @example Return values.
|
25
40
|
# rpc.batch(
|
26
41
|
# rpc.build('a', 'A'),
|
@@ -35,8 +50,7 @@ class SkyZabbix::Jsonrpc
|
|
35
50
|
# ) # => Error::BatchError.
|
36
51
|
# # Can get response of 'a' from ex.result
|
37
52
|
# @param [Array<Hash>] buildeds is Array of result of 'build' method.
|
38
|
-
# @return [Array<Any|nil>]
|
39
|
-
# @raise [Error::BatchError]
|
53
|
+
# @return [Array<Any|Error|nil>]
|
40
54
|
def batch(buildeds)
|
41
55
|
uri = URI.parse(@uri)
|
42
56
|
resp = do_req(uri, buildeds)
|
@@ -69,7 +83,6 @@ class SkyZabbix::Jsonrpc
|
|
69
83
|
# @param [String] method is json-rpc method name.
|
70
84
|
# @param [Any?] params is json-rpc parameters.
|
71
85
|
# @param [Boolean] notification
|
72
|
-
# @return [Hash{Symbol => Any}]
|
73
86
|
def build(method, params, notification: false)
|
74
87
|
res = {
|
75
88
|
jsonrpc: VERSION,
|
@@ -85,22 +98,6 @@ class SkyZabbix::Jsonrpc
|
|
85
98
|
|
86
99
|
private
|
87
100
|
|
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
|
-
|
104
101
|
# @return [Integer] random ID.
|
105
102
|
def id_gen
|
106
103
|
return rand(10**12)
|
@@ -134,7 +131,7 @@ class SkyZabbix::Jsonrpc
|
|
134
131
|
# @param [Hash|Array] body is request body.
|
135
132
|
# @param [Net::HTTPResponse] resp
|
136
133
|
def logging_request(start_time, body, resp)
|
137
|
-
return unless @logger
|
134
|
+
return unless @logger
|
138
135
|
|
139
136
|
sec = Time.now - start_time
|
140
137
|
msg_body =
|
@@ -1,5 +1,4 @@
|
|
1
1
|
class SkyZabbix::Jsonrpc::Error < StandardError
|
2
|
-
# @param [Array<Hash{String => Any}>] body is response body.
|
3
2
|
def initialize(body)
|
4
3
|
@error = body['error']
|
5
4
|
msg = "#{@error['message']} #{@error['data']}"
|
@@ -14,8 +13,6 @@ class SkyZabbix::Jsonrpc::Error < StandardError
|
|
14
13
|
class InternalError < self; end # Internal JSON-RPC error.
|
15
14
|
class ServerError < self; end # Reserved for implementation-defined server-errors.
|
16
15
|
|
17
|
-
# @param [Array<Hash{String => Any}>] body is response body.
|
18
|
-
# @return [Error] A Error instance.
|
19
16
|
def self.create(body)
|
20
17
|
klass =
|
21
18
|
case body['code']
|
@@ -44,7 +41,7 @@ class SkyZabbix::Jsonrpc::Error < StandardError
|
|
44
41
|
return errors.map(&:message).join(', ')
|
45
42
|
end
|
46
43
|
|
47
|
-
# @param [Array<Hash
|
44
|
+
# @param [Array<Hash<String => Any>] body is response body.
|
48
45
|
# @return [Boolean]
|
49
46
|
def self.error?(body)
|
50
47
|
return body.any?{|x|x['error']}
|
data/lib/sky_zabbix/version.rb
CHANGED
data/sky_zabbix.gemspec
CHANGED
@@ -16,7 +16,6 @@ Gem::Specification.new do |spec|
|
|
16
16
|
|
17
17
|
|
18
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
-
spec.files.push('lib/sky_zabbix/methods.json')
|
20
19
|
spec.bindir = "exe"
|
21
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
21
|
spec.require_paths = ["lib"]
|
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
|
+
version: 2.4.0.1.0
|
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:
|
11
|
+
date: 2015-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -120,7 +120,6 @@ files:
|
|
120
120
|
- lib/sky_zabbix/client/target_gen.rb
|
121
121
|
- lib/sky_zabbix/jsonrpc.rb
|
122
122
|
- lib/sky_zabbix/jsonrpc/errors.rb
|
123
|
-
- lib/sky_zabbix/methods.json
|
124
123
|
- lib/sky_zabbix/version.rb
|
125
124
|
- sky_zabbix.gemspec
|
126
125
|
homepage: https://github.com/skyarch-networks/sky_zabbix
|
@@ -143,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
142
|
version: '0'
|
144
143
|
requirements: []
|
145
144
|
rubyforge_project:
|
146
|
-
rubygems_version: 2.4.5
|
145
|
+
rubygems_version: 2.4.5
|
147
146
|
signing_key:
|
148
147
|
specification_version: 4
|
149
148
|
summary: An API Wrapper of Zabbix
|