zabbix_api_gem 0.1.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6c8f297f2139a9f7c49a789f9e1ffd4600e5912d9e0b1a63330f761752fcd1e
4
- data.tar.gz: 50b8942c322c9875c94c28a75080feb1b72f93910511e2bfa10c3353740577d7
3
+ metadata.gz: 2931f6d3227276d1c3120dfc210eae257e5224898a6374964eeb54b7a3644b0d
4
+ data.tar.gz: 397ac9e648e3c451bbc3a3334a1672067fbfa4fc271e00dff774bdf103aa8af2
5
5
  SHA512:
6
- metadata.gz: ba97284983467df1d8b2ead9f52b04883f5978bf78c38d0d0c3fc229cbc5a07ce81cb3ec8d79c5332ec591e6c0f7943f60d7cea4c29a57d0650c8e6a764bfc08
7
- data.tar.gz: 28858aaa64c5fb2e9666949d83108e1751192d64042023afb6e7800ff037fe6e810f972692e8e5179c0fd89d0d5e506e03b56c762821a2162ab1f5a026f6a757
6
+ metadata.gz: f2daaeb129b09004f106f296cee34f9137ad856b02e60c862697ce66b424ea770b6572cbc169d0b1c46023947988ff38055eed9ee1a56fd723290b8e2809458e
7
+ data.tar.gz: 0ea22a6f6b11afa5fd5499aac69bc425bed70a23710a669878a44789ef82aaa8440835bb37254de0144dbdeccc3a337ddae8ee68a2268e08a8cb459102f4c3d9
data/CHANGELOG.md CHANGED
@@ -2,3 +2,10 @@
2
2
 
3
3
  ## [0.1.0] - 2024-02-09
4
4
  - Initial release
5
+
6
+ ## [0.2.0] - 2024-02-12
7
+ - Include events and method to get object by id
8
+
9
+ ## [0.3.0] - 2024-02-20
10
+ - ConfigurationError raised if not configured properly
11
+
data/Gemfile CHANGED
@@ -7,4 +7,5 @@ gemspec
7
7
 
8
8
  gem 'rake', '~> 13.0'
9
9
  gem 'rubocop', '~> 1.7'
10
+ gem 'simplecov', require: false, group: :test
10
11
  gem 'wrapi'
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # Zabbix API
2
+ [![Version](https://img.shields.io/gem/v/zabbix_api_gem.svg)](https://rubygems.org/gems/zabbix_api_gem)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/de2999161abdc8179fde/maintainability)](https://codeclimate.com/github/jancotanis/zabbix/maintainability)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/de2999161abdc8179fde/test_coverage)](https://codeclimate.com/github/jancotanis/zabbix/test_coverage)
2
5
 
3
6
  This is a wrapper for the Zabix rest API. You can see the API endpoints here https://www.zabbix.com/documentation/current/en/manual/api/reference/
4
7
 
@@ -24,7 +27,7 @@ Or install it yourself as:
24
27
 
25
28
  Before you start making the requests to API provide the client id and client secret and email/password using the configuration wrapping.
26
29
 
27
- ```
30
+ ```ruby
28
31
  require 'zabbix_api_gem'
29
32
 
30
33
  # use do block
@@ -47,7 +50,7 @@ end
47
50
 
48
51
  ## Resources
49
52
  ### Authentication
50
- ```
53
+ ```ruby
51
54
  # setup configuration
52
55
  #
53
56
  client.login
@@ -59,7 +62,7 @@ client.login
59
62
 
60
63
  ### Server settings
61
64
  Return zabbix server settings
62
- ```
65
+ ```ruby
63
66
  puts client.settings.default_theme
64
67
  ```
65
68
 
@@ -84,15 +87,16 @@ end
84
87
 
85
88
  |Resource|API endpoint|
86
89
  |:--|:--|
87
- |.hostgroups|hostgroup.get|
88
- |.hosts|hosts.get|
89
- |.problems|problems.get|
90
+ |hostgroups, hostgroup(hostgroup_id)|hostgroup.get|
91
+ |.hosts, host(host_id)|hosts.get|
92
+ |.problems, problem(event_id)|problems.get|
93
+ |.events, event(event_id)|problems.get|
90
94
 
91
95
 
92
96
 
93
97
  ## Contributing
94
98
 
95
- Bug reports and pull requests are welcome on GitHub at https://github.com/jancotanis/veeam.
99
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jancotanis/zabbix.
96
100
 
97
101
  ## License
98
102
 
data/Rakefile CHANGED
@@ -1,12 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'bundler/gem_tasks'
4
+ require 'dotenv'
4
5
  require 'rake/testtask'
5
6
 
7
+ Dotenv.load
8
+
9
+ system './bin/cc-test-reporter before-build'
10
+
6
11
  Rake::TestTask.new(:test) do |t|
7
12
  t.libs << 'test'
8
13
  t.libs << 'lib'
9
14
  t.test_files = FileList['test/**/*_test.rb']
15
+ at_exit do
16
+ system './bin/cc-test-reporter after-build'
17
+ end
10
18
  end
11
19
 
12
20
  require 'rubocop/rake_task'
Binary file
@@ -3,12 +3,12 @@ module Zabbix
3
3
  # Deals with authentication flow and stores it within global configuration
4
4
  module Authentication
5
5
 
6
- # https://helpcenter.veeam.com/docs/vac/rest/reference/vspc-rest.html?ver=80#tag/Authentication
7
- # Authorize to the Veeam portal and return access_token
6
+ # Authorize to the Zabbix portal using the access_token
7
+ # @see https://www.zabbix.com/documentation/current/en/manual/api
8
8
  def login(options = {})
9
- raise ArgumentError, "Accesstoken/api-key not set" unless access_token
9
+ raise ConfigurationError, "Accesstoken/api-key not set" unless access_token
10
10
  # only bearer token needed
11
- # will do sanitty check if token if valid
11
+ # will do sanity check if token if valid
12
12
  rpc_call('settings.get')
13
13
  rescue RPCError => e
14
14
  raise AuthenticationError, e
data/lib/zabbix/client.rb CHANGED
@@ -6,18 +6,32 @@ module Zabbix
6
6
  # @note All methods have been separated into modules and follow the same grouping used in api docs
7
7
  # @see https://www.zabbix.com/documentation/current/en/manual/api
8
8
  class Client < API
9
-
10
- def self.def_rpc_call(method, rpc_method)
9
+ private
10
+ def self.def_rpc_call(method, rpc_method, id_field = nil)
11
11
  self.send(:define_method, method) do |params = nil|
12
12
  rpc_call(rpc_method, params)
13
13
  end
14
+ if id_field
15
+ # strip trailing 's'
16
+ singular = method.to_s.chop.to_sym
17
+ self.send(:define_method, singular) do |ids,params = nil|
18
+ if ids.is_a?(Array)
19
+ rpc_call(rpc_method, {"#{id_field}":ids}.merge(params || {}))
20
+ else
21
+ rpc_call(rpc_method, {"#{id_field}":[ids]}.merge(params || {})).first
22
+ end
23
+ end
24
+ end
14
25
  end
15
26
 
16
- def_rpc_call(:api_info, 'api.info')
17
- def_rpc_call(:settings, 'settings.get')
18
- def_rpc_call(:hostgroups, 'hostgroup.get')
19
- def_rpc_call(:hosts, 'host.get')
20
- def_rpc_call(:problems, 'problem.get')
27
+ public
28
+ def_rpc_call :api_info, 'api.info'
29
+ def_rpc_call :settings, 'settings.get'
30
+ def_rpc_call :hostgroups, 'hostgroup.get', 'groupids'
31
+ def_rpc_call :hosts, 'host.get', 'hostids'
32
+ def_rpc_call :problems, 'problem.get', 'problemids'
33
+ def_rpc_call :events, 'event.get', 'eventids'
34
+ def_rpc_call :acknowledge_events, 'event.acknowledge'
21
35
 
22
36
  end
23
37
  end
data/lib/zabbix/error.rb CHANGED
@@ -6,6 +6,9 @@ module Zabbix
6
6
  # Raised when Zabbix RPC protocol returns error object
7
7
  class RPCError < ZabbixError; end
8
8
 
9
+ # Raised when Zabbix not configured correctly
10
+ class ConfigurationError < ZabbixError; end
11
+
9
12
  # Error when authentication fails
10
13
  class AuthenticationError < ZabbixError; end
11
14
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zabbix
4
- VERSION = '0.1.0'
4
+ VERSION = '0.3.0'
5
5
  end
data/zabbix.gemspec CHANGED
@@ -33,4 +33,5 @@ Gem::Specification.new do |s|
33
33
  s.add_development_dependency 'dotenv'
34
34
  s.add_development_dependency 'minitest'
35
35
  s.add_development_dependency 'rubocop'
36
+ s.add_development_dependency 'simplecov'
36
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabbix_api_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janco Tanis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-12 00:00:00.000000000 Z
11
+ date: 2024-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description:
84
98
  email: gems@jancology.com
85
99
  executables: []
@@ -92,6 +106,7 @@ files:
92
106
  - Gemfile
93
107
  - README.md
94
108
  - Rakefile
109
+ - bin/cc-test-reporter.exe
95
110
  - lib/zabbix.rb
96
111
  - lib/zabbix/api.rb
97
112
  - lib/zabbix/authentication.rb