zabbixapi 4.0.0 → 5.0.0.pre.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +20 -0
  3. data/LICENSE.md +1 -1
  4. data/README.md +30 -17
  5. data/lib/zabbixapi.rb +31 -1
  6. data/lib/zabbixapi/basic/basic_alias.rb +2 -2
  7. data/lib/zabbixapi/basic/basic_func.rb +13 -12
  8. data/lib/zabbixapi/basic/basic_init.rb +5 -5
  9. data/lib/zabbixapi/basic/basic_logic.rb +35 -34
  10. data/lib/zabbixapi/classes/actions.rb +25 -1
  11. data/lib/zabbixapi/classes/applications.rb +4 -4
  12. data/lib/zabbixapi/classes/configurations.rb +3 -3
  13. data/lib/zabbixapi/classes/drules.rb +55 -0
  14. data/lib/zabbixapi/classes/errors.rb +5 -2
  15. data/lib/zabbixapi/classes/events.rb +17 -0
  16. data/lib/zabbixapi/classes/graphs.rb +23 -33
  17. data/lib/zabbixapi/classes/hostgroups.rb +1 -1
  18. data/lib/zabbixapi/classes/hosts.rb +20 -20
  19. data/lib/zabbixapi/classes/httptests.rb +7 -7
  20. data/lib/zabbixapi/classes/items.rb +36 -36
  21. data/lib/zabbixapi/classes/maintenance.rb +1 -1
  22. data/lib/zabbixapi/classes/mediatypes.rb +86 -11
  23. data/lib/zabbixapi/classes/problems.rb +101 -0
  24. data/lib/zabbixapi/classes/proxies.rb +4 -4
  25. data/lib/zabbixapi/classes/roles.rb +114 -0
  26. data/lib/zabbixapi/classes/screens.rb +18 -17
  27. data/lib/zabbixapi/classes/scripts.rb +18 -10
  28. data/lib/zabbixapi/classes/server.rb +1 -1
  29. data/lib/zabbixapi/classes/templates.rb +19 -21
  30. data/lib/zabbixapi/classes/triggers.rb +14 -13
  31. data/lib/zabbixapi/classes/unusable.rb +1 -1
  32. data/lib/zabbixapi/classes/usergroups.rb +16 -19
  33. data/lib/zabbixapi/classes/usermacros.rb +24 -24
  34. data/lib/zabbixapi/classes/users.rb +16 -17
  35. data/lib/zabbixapi/classes/valuemaps.rb +4 -4
  36. data/lib/zabbixapi/client.rb +34 -16
  37. data/lib/zabbixapi/version.rb +1 -1
  38. data/zabbixapi.gemspec +2 -2
  39. metadata +16 -14
  40. data/.yardopts +0 -9
@@ -1,5 +1,6 @@
1
1
  require 'net/http'
2
2
  require 'json'
3
+ require 'openssl'
3
4
 
4
5
  class ZabbixApi
5
6
  class Client
@@ -16,7 +17,8 @@ class ZabbixApi
16
17
  #
17
18
  # @return [String]
18
19
  def api_version
19
- @version ||= api_request(:method => 'apiinfo.version', :params => {})
20
+ @api_version ||= api_request(method: 'apiinfo.version', params: {})
21
+ @api_version
20
22
  end
21
23
 
22
24
  # Log in to the Zabbix Server and generate an auth token using the API
@@ -24,14 +26,21 @@ class ZabbixApi
24
26
  # @return [Hash]
25
27
  def auth
26
28
  api_request(
27
- :method => 'user.login',
28
- :params => {
29
- :user => @options[:user],
30
- :password => @options[:password],
29
+ method: 'user.login',
30
+ params: {
31
+ user: @options[:user],
32
+ password: @options[:password]
31
33
  }
32
34
  )
33
35
  end
34
36
 
37
+ # ZabbixApi::Basic.log does not like @client.options[:debug]
38
+ #
39
+ # @return [boolean]
40
+ def debug?
41
+ return ! @options || @options[:debug]
42
+ end
43
+
35
44
  # Initializes a new Client object
36
45
  #
37
46
  # @param options [Hash]
@@ -51,9 +60,15 @@ class ZabbixApi
51
60
  @proxy_port = @proxy_uri.port
52
61
  @proxy_user, @proxy_pass = @proxy_uri.userinfo.split(/:/) if @proxy_uri.userinfo
53
62
  end
54
- unless api_version =~ /(2\.4|3\.[024]|4\.0)\.\d+/
55
- raise ApiError.new("Zabbix API version: #{api_version} is not support by this version of zabbixapi")
63
+ unless api_version =~ %r{^5.[0|2]\.\d+$}
64
+ message = "Zabbix API version: #{api_version} is not supported by this version of zabbixapi"
65
+ if @options[:ignore_version]
66
+ puts "[WARNING] #{message}" if @options[:debug]
67
+ else
68
+ raise ZabbixApi::ApiError.new(message)
69
+ end
56
70
  end
71
+
57
72
  @auth_hash = auth
58
73
  end
59
74
 
@@ -63,10 +78,10 @@ class ZabbixApi
63
78
  # @return [String]
64
79
  def message_json(body)
65
80
  message = {
66
- :method => body[:method],
67
- :params => body[:params],
68
- :id => id,
69
- :jsonrpc => '2.0',
81
+ method: body[:method],
82
+ params: body[:params],
83
+ id: id,
84
+ jsonrpc: '2.0'
70
85
  }
71
86
 
72
87
  message[:auth] = @auth_hash unless body[:method] == 'apiinfo.version' || body[:method] == 'user.login'
@@ -83,11 +98,12 @@ class ZabbixApi
83
98
  timeout = @options[:timeout].nil? ? 60 : @options[:timeout]
84
99
  puts "[DEBUG] Timeout for request set to #{timeout} seconds" if @options[:debug]
85
100
 
86
- if @proxy_uri
87
- http = Net::HTTP.Proxy(@proxy_host, @proxy_port, @proxy_user, @proxy_pass).new(uri.host, uri.port)
88
- else
89
- http = Net::HTTP.new(uri.host, uri.port)
90
- end
101
+ http =
102
+ if @proxy_uri
103
+ Net::HTTP.Proxy(@proxy_host, @proxy_port, @proxy_user, @proxy_pass).new(uri.host, uri.port)
104
+ else
105
+ Net::HTTP.new(uri.host, uri.port)
106
+ end
91
107
 
92
108
  if uri.scheme == 'https'
93
109
  http.use_ssl = true
@@ -101,6 +117,7 @@ class ZabbixApi
101
117
  request.basic_auth @options[:http_user], @options[:http_password] if @options[:http_user]
102
118
  request.add_field('Content-Type', 'application/json-rpc')
103
119
  request.body = body
120
+
104
121
  response = http.request(request)
105
122
 
106
123
  raise HttpError.new("HTTP Error: #{response.code} on #{@options[:url]}", response) unless response.code == '200'
@@ -115,6 +132,7 @@ class ZabbixApi
115
132
  puts "[DEBUG] Send request: #{body}" if @options[:debug]
116
133
  result = JSON.parse(http_request(body))
117
134
  raise ApiError.new("Server answer API error\n #{JSON.pretty_unparse(result['error'])}\n on request:\n #{pretty_body(body)}", result) if result['error']
135
+
118
136
  result['result']
119
137
  end
120
138
 
@@ -1,3 +1,3 @@
1
1
  class ZabbixApi
2
- VERSION = '4.0.0'.freeze
2
+ VERSION = '5.0.0-alpha1'.freeze
3
3
  end
@@ -9,7 +9,7 @@ require 'zabbixapi/version'
9
9
  Gem::Specification.new do |spec|
10
10
  spec.add_dependency 'http', '~> 2.0'
11
11
  spec.add_dependency 'json', '~> 2.0'
12
- spec.add_development_dependency 'bundler', '~> 1.0'
12
+ spec.add_development_dependency 'bundler'
13
13
 
14
14
  spec.name = 'zabbixapi'
15
15
  spec.version = ZabbixApi::VERSION
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.rubyforge_project = 'zabbixapi'
25
25
 
26
- spec.files = ['.yardopts', 'CHANGELOG.md', 'LICENSE.md', 'README.md', 'zabbixapi.gemspec'] + Dir['lib/**/*.rb']
26
+ spec.files = ['CHANGELOG.md', 'LICENSE.md', 'README.md', 'zabbixapi.gemspec'] + Dir['lib/**/*.rb']
27
27
  spec.require_paths = 'lib'
28
28
  spec.required_ruby_version = '>= 2.0.0'
29
29
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabbixapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.0.0.pre.alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasiliev D.V.
8
8
  - Ivan Evtuhovich
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-12-20 00:00:00.000000000 Z
12
+ date: 2021-01-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: http
@@ -43,16 +43,16 @@ dependencies:
43
43
  name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: '1.0'
48
+ version: '0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - "~>"
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: '1.0'
55
+ version: '0'
56
56
  description: Allows you to work with zabbix api from ruby.
57
57
  email:
58
58
  - vadv.mkn@gmail.com
@@ -61,7 +61,6 @@ executables: []
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
- - ".yardopts"
65
64
  - CHANGELOG.md
66
65
  - LICENSE.md
67
66
  - README.md
@@ -73,7 +72,9 @@ files:
73
72
  - lib/zabbixapi/classes/actions.rb
74
73
  - lib/zabbixapi/classes/applications.rb
75
74
  - lib/zabbixapi/classes/configurations.rb
75
+ - lib/zabbixapi/classes/drules.rb
76
76
  - lib/zabbixapi/classes/errors.rb
77
+ - lib/zabbixapi/classes/events.rb
77
78
  - lib/zabbixapi/classes/graphs.rb
78
79
  - lib/zabbixapi/classes/hostgroups.rb
79
80
  - lib/zabbixapi/classes/hosts.rb
@@ -81,7 +82,9 @@ files:
81
82
  - lib/zabbixapi/classes/items.rb
82
83
  - lib/zabbixapi/classes/maintenance.rb
83
84
  - lib/zabbixapi/classes/mediatypes.rb
85
+ - lib/zabbixapi/classes/problems.rb
84
86
  - lib/zabbixapi/classes/proxies.rb
87
+ - lib/zabbixapi/classes/roles.rb
85
88
  - lib/zabbixapi/classes/screens.rb
86
89
  - lib/zabbixapi/classes/scripts.rb
87
90
  - lib/zabbixapi/classes/server.rb
@@ -99,7 +102,7 @@ homepage: https://github.com/express42/zabbixapi
99
102
  licenses:
100
103
  - MIT
101
104
  metadata: {}
102
- post_install_message:
105
+ post_install_message:
103
106
  rdoc_options: []
104
107
  require_paths:
105
108
  - lib
@@ -110,13 +113,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
113
  version: 2.0.0
111
114
  required_rubygems_version: !ruby/object:Gem::Requirement
112
115
  requirements:
113
- - - ">="
116
+ - - ">"
114
117
  - !ruby/object:Gem::Version
115
- version: '0'
118
+ version: 1.3.1
116
119
  requirements: []
117
- rubyforge_project: zabbixapi
118
- rubygems_version: 2.4.8
119
- signing_key:
120
+ rubygems_version: 3.0.1
121
+ signing_key:
120
122
  specification_version: 4
121
123
  summary: Simple and lightweight ruby module for working with the Zabbix API
122
124
  test_files: []
data/.yardopts DELETED
@@ -1,9 +0,0 @@
1
- --no-private
2
- --protected
3
- --tag authentication:"Authentication"
4
- --markup markdown
5
- -
6
- CHANGELOG.md
7
- LICENSE.md
8
- README.md
9
- examples/*.md