Skip to content

Commit

Permalink
Merge pull request #102 from kevin-j-smith/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Splyth authored Aug 31, 2020
2 parents b0cc985 + c1063ae commit 2cc72e0
Show file tree
Hide file tree
Showing 88 changed files with 229 additions and 172 deletions.
23 changes: 11 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ services:
- postgresql

rvm:
- 2.0
- 2.1
- 2.2
- 2.3
- 2.4
- 2.5
- 2.6
- 2.7
- ruby-head
- jruby-9.1.6.0
- jruby-9.2.10.0
- jruby-head
- rbx-2
- rbx-head

dist: trusty

Expand All @@ -34,9 +33,9 @@ sudo: required
bundler_args: --without development --retry=3 --jobs=3

before_install:
- gem i rubygems-update -v '<3' && update_rubygems
- gem update bundler
- gem install rspec
- gem install --no-document rubygems-update -v '<3' && update_rubygems
- gem update --no-document bundler
- gem install --no-document rspec

before_script:
- sudo sed -i "s,;date.timezone =,date.timezone = 'US/Eastern'," /etc/php5/apache2/php.ini
Expand All @@ -55,8 +54,8 @@ env:

matrix:
allow_failures:
- rvm: 2.7
- rvm: ruby-head
- rvm: jruby-head
- rvm: rbx-2
- rvm: rbx-head # Required rbx-head is not installed - installing
# curl: (22) The requested URL returned error: 404 Not Found
fast_finish: true

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#CHANGELOG

## 4.2.0
[PR #102](https://github.com/express42/zabbixapi/pull/102) Add events get method method. Fixed all testing failures. (Thanks @kevin-j-smith)

## 4.1.2
[PR #99](https://github.com/express42/zabbixapi/pull/99) Patch addressing log error function not found

Expand Down
80 changes: 0 additions & 80 deletions Gemfile.lock

This file was deleted.

8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ We support only two last versions of zabbix (4.0 and 4.2), so you should conside
This library aims to support and is [tested against][travis] the following Ruby
versions:

* Ruby 2.0
* Ruby 2.1
* Ruby 2.2
* Ruby 2.3
* Ruby 2.4
* JRuby 9.1.6.0
* Ruby 2.5
* Ruby 2.6
* JRuby 9.2.10.0

If something doesn't work on one of these versions, it's a bug.

Expand Down
6 changes: 6 additions & 0 deletions lib/zabbixapi.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require 'zabbixapi/classes/applications'
require 'zabbixapi/classes/configurations'
require 'zabbixapi/classes/errors'
require 'zabbixapi/classes/events'
require 'zabbixapi/classes/graphs'
require 'zabbixapi/classes/hostgroups'
require 'zabbixapi/classes/hosts'
Expand Down Expand Up @@ -84,6 +85,11 @@ def configurations
@configurations ||= Configurations.new(@client)
end

# @return [ZabbixApi::Events]
def events
@events ||= Events.new(@client)
end

# @return [ZabbixApi::Graphs]
def graphs
@graphs ||= Graphs.new(@client)
Expand Down
Empty file modified lib/zabbixapi/basic/basic_alias.rb
100644 → 100755
Empty file.
Empty file modified lib/zabbixapi/basic/basic_func.rb
100644 → 100755
Empty file.
Empty file modified lib/zabbixapi/basic/basic_init.rb
100644 → 100755
Empty file.
Empty file modified lib/zabbixapi/basic/basic_logic.rb
100644 → 100755
Empty file.
Empty file modified lib/zabbixapi/classes/actions.rb
100644 → 100755
Empty file.
Empty file modified lib/zabbixapi/classes/applications.rb
100644 → 100755
Empty file.
Empty file modified lib/zabbixapi/classes/configurations.rb
100644 → 100755
Empty file.
Empty file modified lib/zabbixapi/classes/drules.rb
100644 → 100755
Empty file.
Empty file modified lib/zabbixapi/classes/errors.rb
100644 → 100755
Empty file.
17 changes: 17 additions & 0 deletions lib/zabbixapi/classes/events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class ZabbixApi
class Events < Basic
# The method name used for interacting with Events via Zabbix API
#
# @return [String]
def method_name
'event'
end

# The id field name used for identifying specific Event objects via Zabbix API
#
# @return [String]
def indentify
'name'
end
end
end
Empty file modified lib/zabbixapi/classes/graphs.rb
100644 → 100755
Empty file.
Empty file modified lib/zabbixapi/classes/hostgroups.rb
100644 → 100755
Empty file.
Empty file modified lib/zabbixapi/classes/hosts.rb
100644 → 100755
Empty file.
Empty file modified lib/zabbixapi/classes/httptests.rb
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions lib/zabbixapi/classes/items.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def default_options
key_: nil,
hostid: nil,
delay: 60,
history: 60,
history: 3600,
status: 0,
type: 7,
snmp_community: '',
Expand All @@ -40,7 +40,7 @@ def default_options
snmpv3_authpassphrase: '',
snmpv3_privpassphrase: '',
formula: 0,
trends: 365,
trends: 86400,
logtimefmt: '',
valuemapid: 0,
delay_flex: '',
Expand Down
Empty file modified lib/zabbixapi/classes/maintenance.rb
100644 → 100755
Empty file.
Empty file modified lib/zabbixapi/classes/mediatypes.rb
100644 → 100755
Empty file.
Empty file modified lib/zabbixapi/classes/proxies.rb
100644 → 100755
Empty file.
Empty file modified lib/zabbixapi/classes/screens.rb
100644 → 100755
Empty file.
Empty file modified lib/zabbixapi/classes/scripts.rb
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion lib/zabbixapi/classes/server.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Server
# @return [String] Zabbix API version number
def initialize(client)
@client = client
@api_version = @client.api_request(method: 'apiinfo.version', params: {})
@version = @client.api_version()
end
end
end
Empty file modified lib/zabbixapi/classes/templates.rb
100644 → 100755
Empty file.
Empty file modified lib/zabbixapi/classes/triggers.rb
100644 → 100755
Empty file.
Empty file modified lib/zabbixapi/classes/unusable.rb
100644 → 100755
Empty file.
27 changes: 12 additions & 15 deletions lib/zabbixapi/classes/usergroups.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def indentify
def permissions(data)
permission = data[:permission] || 2
result = @client.api_request(
method: 'usergroup.massAdd',
method: 'usergroup.update',
params: {
usrgrpids: [data[:usrgrpid]],
usrgrpid: data[:usrgrpid],
rights: data[:hostgroupids].map { |t| { permission: permission, id: t } }
}
)
Expand All @@ -41,19 +41,13 @@ def permissions(data)

# Add users to usergroup using Zabbix API
#
# @deprecated Zabbix has removed massAdd in favor of update.
# @param data [Hash] Needs to include userids and usrgrpids to mass add users to groups
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
# @return [Integer] Zabbix object id (usergroup)
def add_user(data)
result = @client.api_request(
method: 'usergroup.massAdd',
params: {
usrgrpids: data[:usrgrpids],
userids: data[:userids]
}
)
result ? result['usrgrpids'][0].to_i : nil
update_users(data)
end

# Update users in usergroups using Zabbix API
Expand All @@ -63,12 +57,15 @@ def add_user(data)
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
# @return [Integer] Zabbix object id (usergroup)
def update_users(data)
result = @client.api_request(
method: 'usergroup.massUpdate',
params: {
usrgrpids: data[:usrgrpids],
userids: data[:userids]
user_groups = data[:usrgrpids].map do |t|
{
usrgrpid: t,
userids: data[:userids],
}
end
result = @client.api_request(
method: 'usergroup.update',
params: user_groups,
)
result ? result['usrgrpids'][0].to_i : nil
end
Expand Down
Empty file modified lib/zabbixapi/classes/usermacros.rb
100644 → 100755
Empty file.
16 changes: 9 additions & 7 deletions lib/zabbixapi/classes/users.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ def indentify
def medias_helper(data, action)
result = @client.api_request(
method: "user.#{action}",
params: {
users: data[:userids].map { |t| { userid: t } },
medias: data[:media]
}
params: data[:userids].map do |t|
{
userid: t,
user_medias: data[:media],
}
end,
)
result ? result['mediaids'][0].to_i : nil
result ? result['userids'][0].to_i : nil
end

# Add media to users using Zabbix API
Expand All @@ -46,7 +48,7 @@ def medias_helper(data, action)
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
# @return [Integer] Zabbix object id (media)
def add_medias(data)
medias_helper(data, 'addMedia')
medias_helper(data, 'update')
end

# Update media for users using Zabbix API
Expand All @@ -56,7 +58,7 @@ def add_medias(data)
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
# @return [Integer] Zabbix object id (user)
def update_medias(data)
medias_helper(data, 'updateMedia')
medias_helper(data, 'update')
end
end
end
Empty file modified lib/zabbixapi/classes/valuemaps.rb
100644 → 100755
Empty file.
11 changes: 10 additions & 1 deletion lib/zabbixapi/client.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def id
# @return [String]
def api_version
@api_version ||= api_request(method: 'apiinfo.version', params: {})
@api_version
end

# Log in to the Zabbix Server and generate an auth token using the API
Expand All @@ -33,6 +34,13 @@ def auth
)
end

# ZabbixApi::Basic.log does not like @client.options[:debug]
#
# @return [boolean]
def debug?
return ! @options || @options[:debug]
end

# Initializes a new Client object
#
# @param options [Hash]
Expand All @@ -53,7 +61,8 @@ def initialize(options = {})
@proxy_user, @proxy_pass = @proxy_uri.userinfo.split(/:/) if @proxy_uri.userinfo
end
unless api_version =~ %r{^4.[0|4]\.\d+$}
puts "[WARN] Zabbix API version: #{api_version} is not supported by this version of zabbixapi"
message = "Zabbix API version: #{api_version} is not supported by this version of zabbixapi"
raise ZabbixApi::ApiError.new(message)
end

@auth_hash = auth
Expand Down
2 changes: 1 addition & 1 deletion lib/zabbixapi/version.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class ZabbixApi
VERSION = '4.1.2'.freeze
VERSION = '4.2.0'.freeze
end
Empty file modified spec/action.rb
100644 → 100755
Empty file.
Empty file modified spec/application.rb
100644 → 100755
Empty file.
Empty file modified spec/basic_func.rb
100644 → 100755
Empty file.
Empty file modified spec/configuration.rb
100644 → 100755
Empty file.
Empty file modified spec/drule.rb
100644 → 100755
Empty file.
Loading

0 comments on commit 2cc72e0

Please sign in to comment.