From f67282e83a9641c84e75b9a9b6b9c27dd57f4562 Mon Sep 17 00:00:00 2001 From: Scott Mackensen Date: Fri, 9 Nov 2018 11:40:49 -0600 Subject: [PATCH] zabbixapi gem cleanup --- .codeclimate.yml | 16 ---- .rubocop.yml | 14 ++- .rubocop_todo.yml | 26 ------ .yardopts | 9 -- Gemfile | 9 +- Gemfile.lock | 100 +++++++------------- Jenkinsfile | 5 + examples/Usergroups.md | 2 +- lib/zabbixapi.rb | 2 +- lib/zabbixapi/basic/basic_func.rb | 25 ++--- lib/zabbixapi/basic/basic_logic.rb | 41 +++++---- lib/zabbixapi/classes/applications.rb | 6 +- lib/zabbixapi/classes/configurations.rb | 4 +- lib/zabbixapi/classes/errors.rb | 7 +- lib/zabbixapi/classes/graphs.rb | 34 +++---- lib/zabbixapi/classes/hosts.rb | 36 ++++---- lib/zabbixapi/classes/httptests.rb | 12 +-- lib/zabbixapi/classes/items.rb | 70 +++++++------- lib/zabbixapi/classes/mediatypes.rb | 18 ++-- lib/zabbixapi/classes/proxies.rb | 6 +- lib/zabbixapi/classes/screens.rb | 32 +++---- lib/zabbixapi/classes/scripts.rb | 26 ++++-- lib/zabbixapi/classes/server.rb | 2 +- lib/zabbixapi/classes/templates.rb | 34 +++---- lib/zabbixapi/classes/triggers.rb | 22 ++--- lib/zabbixapi/classes/usergroups.rb | 26 +++--- lib/zabbixapi/classes/usermacros.rb | 18 ++-- lib/zabbixapi/classes/users.rb | 34 +++++++ lib/zabbixapi/classes/valuemaps.rb | 6 +- lib/zabbixapi/client.rb | 39 ++++---- spec/action.rb | 82 ++++++++--------- spec/application.rb | 30 +++--- spec/configuration.rb | 100 ++++++++++---------- spec/graph.rb | 72 +++++++-------- spec/host.rb | 116 ++++++++++++------------ spec/hostgroup.rb | 14 ++- spec/httptest.rb | 86 ++++++++++++------ spec/item.rb | 74 ++++++++------- spec/maintenance.rb | 34 ++++--- spec/mediatype.rb | 28 +++--- spec/query.rb | 6 +- spec/screen.rb | 54 ++++++----- spec/script.rb | 76 ++++++++-------- spec/server.rb | 2 - spec/spec_helper.rb | 8 +- spec/template.rb | 64 +++++++------ spec/trigger.rb | 76 ++++++++-------- spec/user.rb | 82 +++++++++-------- spec/usergroup.rb | 54 +++++------ spec/usermacro.rb | 74 ++++++++------- spec/valuemap.rb | 26 +++--- zabbixapi.gemspec | 18 ++-- 52 files changed, 907 insertions(+), 950 deletions(-) delete mode 100644 .codeclimate.yml delete mode 100644 .rubocop_todo.yml delete mode 100644 .yardopts create mode 100644 Jenkinsfile diff --git a/.codeclimate.yml b/.codeclimate.yml deleted file mode 100644 index 412aff0..0000000 --- a/.codeclimate.yml +++ /dev/null @@ -1,16 +0,0 @@ -engines: - rubocop: - enabled: true - duplication: - enabled: true - config: - languages: - - ruby - -ratings: - paths: - - "**.rb" - -exclude_paths: - - examples/**/* - - spec/**/* \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml index f56fe56..fa93b09 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,5 @@ -inherit_from: .rubocop_todo.yml +AllCops: + DisplayCopNames: true Metrics/AbcSize: Max: 58 # TODO: Lower to 15 @@ -32,9 +33,12 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 10 -Style/AccessModifierIndentation: +Layout/AccessModifierIndentation: EnforcedStyle: outdent +Layout/SpaceInsideHashLiteralBraces: + EnforcedStyle: no_space + Style/Documentation: Enabled: false @@ -50,11 +54,5 @@ Style/HashSyntax: Style/RaiseArgs: EnforcedStyle: compact -Style/SpaceInsideHashLiteralBraces: - EnforcedStyle: no_space - Style/SymbolArray: EnforcedStyle: brackets - -Style/TrailingCommaInLiteral: - EnforcedStyleForMultiline: 'comma' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index 3d184fa..0000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,26 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2017-04-19 15:47:43 -0500 using RuboCop version 0.48.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 1 -Style/AccessorMethodName: - Exclude: - - 'lib/zabbixapi/classes/usergroups.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly, IncludeTernaryExpressions. -# SupportedStyles: assign_to_condition, assign_inside_condition -Style/ConditionalAssignment: - Exclude: - - 'lib/zabbixapi/client.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/RescueModifier: - Exclude: - - 'lib/zabbixapi/classes/errors.rb' diff --git a/.yardopts b/.yardopts deleted file mode 100644 index e758f7a..0000000 --- a/.yardopts +++ /dev/null @@ -1,9 +0,0 @@ ---no-private ---protected ---tag authentication:"Authentication" ---markup markdown -- -CHANGELOG.md -LICENSE.md -README.md -examples/*.md diff --git a/Gemfile b/Gemfile index f8f1275..8bfdece 100644 --- a/Gemfile +++ b/Gemfile @@ -9,13 +9,8 @@ group :development do end group :test do - gem 'coveralls' - gem 'rspec', '>= 3.4.4' - gem 'rubocop', '>= 0.38' - gem 'simplecov', '>= 0.9' - gem 'timecop' - gem 'webmock', '>= 2.0.3' - gem 'yardstick' + gem 'rspec', '>= 3.8' + gem 'rubocop', '>= 0.60' end gemspec diff --git a/Gemfile.lock b/Gemfile.lock index 1a20abf..929e9bf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,34 +1,20 @@ PATH remote: . specs: -<<<<<<< HEAD - zabbixapi (4.1.0) -======= - zabbixapi (3.2.1) ->>>>>>> 5e890f5... ETSOE-415 Update Gem Compatibility + ets_zabbixapi (4.1.0) http (~> 2.0) json (~> 2.0) GEM remote: https://rubygems.org/ specs: - addressable (2.5.1) - public_suffix (~> 2.0, >= 2.0.2) - ast (2.3.0) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + ast (2.4.0) coderay (1.1.1) - coveralls (0.8.20) - json (>= 1.8, < 3) - simplecov (~> 0.14.1) - term-ansicolor (~> 1.3) - thor (~> 0.19.4) - tins (~> 1.6) - crack (0.4.3) - safe_yaml (~> 1.0.0) - diff-lcs (1.2.5) - docile (1.1.5) + diff-lcs (1.3) domain_name (0.5.20180417) unf (>= 0.0.5, < 1.0.0) - hashdiff (0.3.2) http (2.2.2) addressable (~> 2.3) http-cookie (~> 1.0) @@ -38,79 +24,61 @@ GEM domain_name (~> 0.5) http-form_data (1.0.3) http_parser.rb (0.6.0) + jaro_winkler (1.5.2) json (2.1.0) method_source (0.8.2) - parser (2.4.0.0) - ast (~> 2.2) - powerpack (0.1.1) + parallel (1.12.1) + parser (2.5.3.0) + ast (~> 2.4.0) + powerpack (0.1.2) pry (0.10.4) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) - public_suffix (2.0.5) - rainbow (2.2.1) + public_suffix (3.0.3) + rainbow (3.0.0) rake (11.3.0) - rspec (3.5.0) - rspec-core (~> 3.5.0) - rspec-expectations (~> 3.5.0) - rspec-mocks (~> 3.5.0) - rspec-core (3.5.4) - rspec-support (~> 3.5.0) - rspec-expectations (3.5.0) + rspec (3.8.0) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-core (3.8.0) + rspec-support (~> 3.8.0) + rspec-expectations (3.8.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.5.0) - rspec-mocks (3.5.0) + rspec-support (~> 3.8.0) + rspec-mocks (3.8.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.5.0) - rspec-support (3.5.0) - rubocop (0.48.1) - parser (>= 2.3.3.1, < 3.0) + rspec-support (~> 3.8.0) + rspec-support (3.8.0) + rubocop (0.62.0) + jaro_winkler (~> 1.5.1) + parallel (~> 1.10) + parser (>= 2.5, != 2.5.1.1) powerpack (~> 0.1) - rainbow (>= 1.99.1, < 3.0) + rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.0, >= 1.0.1) - ruby-progressbar (1.8.1) - safe_yaml (1.0.4) - simplecov (0.14.1) - docile (~> 1.1.0) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.0) + unicode-display_width (~> 1.4.0) + ruby-progressbar (1.10.0) slop (3.6.0) - term-ansicolor (1.6.0) - tins (~> 1.0) - thor (0.19.4) - timecop (0.8.1) - tins (1.13.2) unf (0.1.4) unf_ext unf_ext (0.0.7.5) - unicode-display_width (1.2.1) - webmock (3.0.1) - addressable (>= 2.3.6) - crack (>= 0.3.2) - hashdiff + unicode-display_width (1.4.1) yard (0.9.8) - yardstick (0.9.9) - yard (~> 0.8, >= 0.8.7.2) PLATFORMS ruby DEPENDENCIES bundler (~> 1.0) - coveralls + ets_zabbixapi! jruby-openssl pry rake (~> 11.1) - rspec (>= 3.4.4) - rubocop (>= 0.38) - simplecov (>= 0.9) - timecop - webmock (>= 2.0.3) + rspec (>= 3.8) + rubocop (>= 0.60) yard (>= 0.9) - yardstick - zabbixapi! BUNDLED WITH 1.16.5 diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..be30d8a --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,5 @@ +#!groovy + +library 'ets_shared' + +etsTestRubyUnit() diff --git a/examples/Usergroups.md b/examples/Usergroups.md index ab05d7f..67b9ac3 100644 --- a/examples/Usergroups.md +++ b/examples/Usergroups.md @@ -15,7 +15,7 @@ zbx.usergroups.add_user( ) # set write and read permissions for UserGroup on all Hostgroups -zbx.usergroups.set_perms( +zbx.usergroups.permissions( :usrgrpid => zbx.usergroups.get_or_create(:name => "Some user group"), :hostgroupids => zbx.hostgroups.all.values, # kind_of Array :permission => 3 # 2- read (by default) and 3 - write and read diff --git a/lib/zabbixapi.rb b/lib/zabbixapi.rb index e1a6871..ced0e8b 100644 --- a/lib/zabbixapi.rb +++ b/lib/zabbixapi.rb @@ -52,7 +52,7 @@ def self.current # @param data [Hash] # @return [Hash] def query(data) - @client.api_request(:method => data[:method], :params => data[:params]) + @client.api_request(method: data[:method], params: data[:params]) end # Invalidate current authentication token diff --git a/lib/zabbixapi/basic/basic_func.rb b/lib/zabbixapi/basic/basic_func.rb index b61adb9..6f6f729 100644 --- a/lib/zabbixapi/basic/basic_func.rb +++ b/lib/zabbixapi/basic/basic_func.rb @@ -9,14 +9,15 @@ def log(message) # Compare two hashes for equality # - # @param a [Hash] - # @param b [Hash] + # @param first_hash [Hash] + # @param second_hash [Hash] # @return [Boolean] - def hash_equals?(a, b) - a_new = normalize_hash(a) - b_new = normalize_hash(b) - hash1 = a_new.merge(b_new) - hash2 = b_new.merge(a_new) + def hash_equals?(first_hash, second_hash) + normalized_first_hash = normalize_hash(first_hash) + normalized_second_hash = normalize_hash(second_hash) + + hash1 = normalized_first_hash.merge(normalized_second_hash) + hash2 = normalized_second_hash.merge(normalized_first_hash) hash1 == hash2 end @@ -91,12 +92,12 @@ def parse_keys(data) # Merge two hashes into a single new hash # - # @param a [Hash] - # @param b [Hash] + # @param first_hash [Hash] + # @param second_hash [Hash] # @return [Hash] - def merge_params(a, b) - new = a.dup - new.merge(b) + def merge_params(first_hash, second_hash) + new = first_hash.dup + new.merge(second_hash) end end end diff --git a/lib/zabbixapi/basic/basic_logic.rb b/lib/zabbixapi/basic/basic_logic.rb index 7e309d4..5a10408 100644 --- a/lib/zabbixapi/basic/basic_logic.rb +++ b/lib/zabbixapi/basic/basic_logic.rb @@ -12,7 +12,7 @@ def create(data) data_with_default = default_options.empty? ? data : merge_params(default_options, data) data_create = [data_with_default] - result = @client.api_request(:method => "#{method_name}.create", :params => data_create) + result = @client.api_request(method: "#{method_name}.create", params: data_create) parse_keys result end @@ -27,7 +27,7 @@ def delete(data) log "[DEBUG] Call delete with parameters: #{data.inspect}" data_delete = [data] - result = @client.api_request(:method => "#{method_name}.delete", :params => data_delete) + result = @client.api_request(method: "#{method_name}.delete", params: data_delete) parse_keys result end @@ -64,7 +64,7 @@ def update(data, force = false) data[key.to_sym].to_i else data_update = [data] - result = @client.api_request(:method => "#{method_name}.update", :params => data_update) + result = @client.api_request(method: "#{method_name}.update", params: data_update) parse_keys result end end @@ -79,12 +79,12 @@ def get_full_data(data) log "[DEBUG] Call get_full_data with parameters: #{data.inspect}" @client.api_request( - :method => "#{method_name}.get", - :params => { - :filter => { - indentify.to_sym => data[indentify.to_sym], + method: "#{method_name}.get", + params: { + filter: { + indentify.to_sym => data[indentify.to_sym] }, - :output => 'extend', + output: 'extend' } ) end @@ -99,8 +99,8 @@ def get_raw(data) log "[DEBUG] Call get_raw with parameters: #{data.inspect}" @client.api_request( - :method => "#{method_name}.get", - :params => data + method: "#{method_name}.get", + params: data ) end @@ -114,12 +114,12 @@ def dump_by_id(data) log "[DEBUG] Call dump_by_id with parameters: #{data.inspect}" @client.api_request( - :method => "#{method_name}.get", - :params => { - :filter => { - key.to_sym => data[key.to_sym], + method: "#{method_name}.get", + params: { + filter: { + key.to_sym => data[key.to_sym] }, - :output => 'extend', + output: 'extend' } ) end @@ -131,7 +131,7 @@ def dump_by_id(data) # @return [Array] Array of matching objects def all result = {} - @client.api_request(:method => "#{method_name}.get", :params => {:output => 'extend'}).each do |item| + @client.api_request(method: "#{method_name}.get", params: {output: 'extend'}).each do |item| result[item[indentify]] = item[key] end result @@ -150,11 +150,12 @@ def get_id(data) # raise an error if indentify name was not supplied name = data[indentify.to_sym] raise ApiError.new("#{indentify} not supplied in call to get_id") if name.nil? + result = @client.api_request( - :method => "#{method_name}.get", - :params => { - :filter => data, - :output => [key, indentify], + method: "#{method_name}.get", + params: { + filter: data, + output: [key, indentify] } ) id = nil diff --git a/lib/zabbixapi/classes/applications.rb b/lib/zabbixapi/classes/applications.rb index 673df6f..902c32f 100644 --- a/lib/zabbixapi/classes/applications.rb +++ b/lib/zabbixapi/classes/applications.rb @@ -23,7 +23,7 @@ def indentify def get_or_create(data) log "[DEBUG] Call get_or_create with parameters: #{data.inspect}" - unless (id = get_id(:name => data[:name], :hostid => data[:hostid])) + unless (id = get_id(name: data[:name], hostid: data[:hostid])) id = create(data) end id @@ -36,8 +36,8 @@ def get_or_create(data) # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK. # @return [Integer] Zabbix object id def create_or_update(data) - applicationid = get_id(:name => data[:name], :hostid => data[:hostid]) - applicationid ? update(data.merge(:applicationid => applicationid)) : create(data) + applicationid = get_id(name: data[:name], hostid: data[:hostid]) + applicationid ? update(data.merge(applicationid: applicationid)) : create(data) end end end diff --git a/lib/zabbixapi/classes/configurations.rb b/lib/zabbixapi/classes/configurations.rb index 7a4c4ee..8d36add 100644 --- a/lib/zabbixapi/classes/configurations.rb +++ b/lib/zabbixapi/classes/configurations.rb @@ -26,7 +26,7 @@ def indentify # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK. # @return [Hash] def export(data) - @client.api_request(:method => 'configuration.export', :params => data) + @client.api_request(method: 'configuration.export', params: data) end # Import configuration data using Zabbix API @@ -36,7 +36,7 @@ def export(data) # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK. # @return [Hash] def import(data) - @client.api_request(:method => 'configuration.import', :params => data) + @client.api_request(method: 'configuration.import', params: data) end end end diff --git a/lib/zabbixapi/classes/errors.rb b/lib/zabbixapi/classes/errors.rb index d39b870..da3aa8a 100644 --- a/lib/zabbixapi/classes/errors.rb +++ b/lib/zabbixapi/classes/errors.rb @@ -12,8 +12,11 @@ def initialize(message, response = nil) private def set_error! - @error = @response['error'] rescue nil - @error_message = "#{@error['message']}: #{@error['data']}" rescue nil + @error = @response['error'] + @error_message = "#{@error['message']}: #{@error['data']}" + rescue StandardError + @error = nil + @error_message = nil end end diff --git a/lib/zabbixapi/classes/graphs.rb b/lib/zabbixapi/classes/graphs.rb index 398b5e9..47f4e1f 100644 --- a/lib/zabbixapi/classes/graphs.rb +++ b/lib/zabbixapi/classes/graphs.rb @@ -24,12 +24,12 @@ def get_full_data(data) log "[DEBUG] Call get_full_data with parametrs: #{data.inspect}" @client.api_request( - :method => "#{method_name}.get", - :params => { - :search => { - indentify.to_sym => data[indentify.to_sym], + method: "#{method_name}.get", + params: { + search: { + indentify.to_sym => data[indentify.to_sym] }, - :output => 'extend', + output: 'extend' } ) end @@ -45,12 +45,12 @@ def get_ids_by_host(data) graphs = {} result = @client.api_request( - :method => 'graph.get', - :params => { - :filter => { - :host => data[:host], + method: 'graph.get', + params: { + filter: { + host: data[:host] }, - :output => 'extend', + output: 'extend' } ) @@ -78,10 +78,10 @@ def get_ids_by_host(data) # @return [Hash] def get_items(data) @client.api_request( - :method => 'graphitem.get', - :params => { - :graphids => [data], - :output => 'extend', + method: 'graphitem.get', + params: { + graphids: [data], + output: 'extend' } ) end @@ -95,7 +95,7 @@ def get_items(data) def get_or_create(data) log "[DEBUG] Call get_or_create with parameters: #{data.inspect}" - unless (id = get_id(:name => data[:name], :templateid => data[:templateid])) + unless (id = get_id(name: data[:name], templateid: data[:templateid])) id = create(data) end @@ -109,8 +109,8 @@ def get_or_create(data) # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK. # @return [Integer] Zabbix object id def create_or_update(data) - graphid = get_id(:name => data[:name], :templateid => data[:templateid]) - graphid ? _update(data.merge(:graphid => graphid)) : create(data) + graphid = get_id(name: data[:name], templateid: data[:templateid]) + graphid ? _update(data.merge(graphid: graphid)) : create(data) end def _update(data) diff --git a/lib/zabbixapi/classes/hosts.rb b/lib/zabbixapi/classes/hosts.rb index 07db74f..d237a69 100644 --- a/lib/zabbixapi/classes/hosts.rb +++ b/lib/zabbixapi/classes/hosts.rb @@ -24,13 +24,13 @@ def dump_by_id(data) log "[DEBUG] Call dump_by_id with parametrs: #{data.inspect}" @client.api_request( - :method => 'host.get', - :params => { - :filter => { - key.to_sym => data[key.to_sym], + method: 'host.get', + params: { + filter: { + key.to_sym => data[key.to_sym] }, - :output => 'extend', - :selectGroups => 'shorten', + output: 'extend', + selectGroups: 'shorten' } ) end @@ -40,12 +40,12 @@ def dump_by_id(data) # @return [Hash] def default_options { - :host => nil, - :interfaces => [], - :status => 0, - :available => 1, - :groups => [], - :proxy_hostid => nil, + host: nil, + interfaces: [], + status: 0, + available: 1, + groups: [], + proxy_hostid: nil } end @@ -57,10 +57,10 @@ def default_options # @return [Boolean] def unlink_templates(data) result = @client.api_request( - :method => 'host.massRemove', - :params => { - :hostids => data[:hosts_id], - :templates => data[:templates_id], + method: 'host.massRemove', + params: { + hostids: data[:hosts_id], + templates: data[:templates_id] } ) result.empty? ? false : true @@ -73,8 +73,8 @@ def unlink_templates(data) # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK. # @return [Integer] Zabbix object id def create_or_update(data) - hostid = get_id(:host => data[:host]) - hostid ? update(data.merge(:hostid => hostid)) : create(data) + hostid = get_id(host: data[:host]) + hostid ? update(data.merge(hostid: hostid)) : create(data) end end end diff --git a/lib/zabbixapi/classes/httptests.rb b/lib/zabbixapi/classes/httptests.rb index 001509f..4450e86 100644 --- a/lib/zabbixapi/classes/httptests.rb +++ b/lib/zabbixapi/classes/httptests.rb @@ -19,9 +19,9 @@ def indentify # @return [Hash] def default_options { - :hostid => nil, - :name => nil, - :steps => [], + hostid: nil, + name: nil, + steps: [] } end @@ -34,7 +34,7 @@ def default_options def get_or_create(data) log "[DEBUG] Call get_or_create with parameters: #{data.inspect}" - unless (id = get_id(:name => data[:name], :hostid => data[:hostid])) + unless (id = get_id(name: data[:name], hostid: data[:hostid])) id = create(data) end id @@ -47,8 +47,8 @@ def get_or_create(data) # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK. # @return [Integer] Zabbix object id def create_or_update(data) - httptestid = get_id(:name => data[:name], :hostid => data[:hostid]) - httptestid ? update(data.merge(:httptestid => httptestid)) : create(data) + httptestid = get_id(name: data[:name], hostid: data[:hostid]) + httptestid ? update(data.merge(httptestid: httptestid)) : create(data) end end end diff --git a/lib/zabbixapi/classes/items.rb b/lib/zabbixapi/classes/items.rb index 65b8841..f776f2b 100644 --- a/lib/zabbixapi/classes/items.rb +++ b/lib/zabbixapi/classes/items.rb @@ -19,38 +19,38 @@ def indentify # @return [Hash] def default_options { - :name => nil, - :key_ => nil, - :hostid => nil, - :delay => 60, - :history => 3600, - :status => 0, - :type => 7, - :snmp_community => '', - :snmp_oid => '', - :value_type => 3, - :data_type => 0, - :trapper_hosts => 'localhost', - :snmp_port => 161, - :units => '', - :multiplier => 0, - :delta => 0, - :snmpv3_securityname => '', - :snmpv3_securitylevel => 0, - :snmpv3_authpassphrase => '', - :snmpv3_privpassphrase => '', - :formula => 0, - :trends => 86400, - :logtimefmt => '', - :valuemapid => 0, - :delay_flex => '', - :authtype => 0, - :username => '', - :password => '', - :publickey => '', - :privatekey => '', - :params => '', - :ipmi_sensor => '', + name: nil, + key_: nil, + hostid: nil, + delay: 60, + history: 60, + status: 0, + type: 7, + snmp_community: '', + snmp_oid: '', + value_type: 3, + data_type: 0, + trapper_hosts: 'localhost', + snmp_port: 161, + units: '', + multiplier: 0, + delta: 0, + snmpv3_securityname: '', + snmpv3_securitylevel: 0, + snmpv3_authpassphrase: '', + snmpv3_privpassphrase: '', + formula: 0, + trends: 365, + logtimefmt: '', + valuemapid: 0, + delay_flex: '', + authtype: 0, + username: '', + password: '', + publickey: '', + privatekey: '', + params: '', + ipmi_sensor: '' } end @@ -63,7 +63,7 @@ def default_options def get_or_create(data) log "[DEBUG] Call get_or_create with parameters: #{data.inspect}" - unless (id = get_id(:name => data[:name], :hostid => data[:hostid])) + unless (id = get_id(name: data[:name], hostid: data[:hostid])) id = create(data) end id @@ -76,8 +76,8 @@ def get_or_create(data) # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK. # @return [Integer] Zabbix object id def create_or_update(data) - itemid = get_id(:name => data[:name], :hostid => data[:hostid]) - itemid ? update(data.merge(:itemid => itemid)) : create(data) + itemid = get_id(name: data[:name], hostid: data[:hostid]) + itemid ? update(data.merge(itemid: itemid)) : create(data) end end end diff --git a/lib/zabbixapi/classes/mediatypes.rb b/lib/zabbixapi/classes/mediatypes.rb index e7cfec3..64fa979 100644 --- a/lib/zabbixapi/classes/mediatypes.rb +++ b/lib/zabbixapi/classes/mediatypes.rb @@ -19,15 +19,15 @@ def indentify # @return [Hash] def default_options { - :description => '', # Name - :type => 0, # 0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting - :smtp_server => '', - :smtp_helo => '', - :smtp_email => '', # Email address of Zabbix server - :exec_path => '', # Name of external script - :gsm_modem => '', # Serial device name of GSM modem - :username => '', # Jabber user name used by Zabbix server - :passwd => '' # Jabber password used by Zabbix server + description: '', # Name + type: 0, # 0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting + smtp_server: '', + smtp_helo: '', + smtp_email: '', # Email address of Zabbix server + exec_path: '', # Name of external script + gsm_modem: '', # Serial device name of GSM modem + username: '', # Jabber user name used by Zabbix server + passwd: '' # Jabber password used by Zabbix server } end end diff --git a/lib/zabbixapi/classes/proxies.rb b/lib/zabbixapi/classes/proxies.rb index 62e1b88..d5e5f97 100644 --- a/lib/zabbixapi/classes/proxies.rb +++ b/lib/zabbixapi/classes/proxies.rb @@ -21,7 +21,7 @@ def indentify # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK. # @return [Integer] The Proxy object id that was deleted def delete(data) - result = @client.api_request(:method => 'proxy.delete', :params => data) + result = @client.api_request(method: 'proxy.delete', params: data) result.empty? ? nil : result['proxyids'][0].to_i end @@ -32,7 +32,7 @@ def delete(data) # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK. # @return [Boolean] Returns true if the given proxies are readable def isreadable(data) - @client.api_request(:method => 'proxy.isreadable', :params => data) + @client.api_request(method: 'proxy.isreadable', params: data) end # Check if a Proxy object is writable using Zabbix API @@ -42,7 +42,7 @@ def isreadable(data) # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK. # @return [Boolean] Returns true if the given proxies are writable def iswritable(data) - @client.api_request(:method => 'proxy.iswritable', :params => data) + @client.api_request(method: 'proxy.iswritable', params: data) end end end diff --git a/lib/zabbixapi/classes/screens.rb b/lib/zabbixapi/classes/screens.rb index 7a5a78f..1ef685c 100644 --- a/lib/zabbixapi/classes/screens.rb +++ b/lib/zabbixapi/classes/screens.rb @@ -40,7 +40,7 @@ def indentify # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK. # @return [Integer] Zabbix object id def delete(data) - result = @client.api_request(:method => 'screen.delete', :params => [data]) + result = @client.api_request(method: 'screen.delete', params: [data]) result.empty? ? nil : result['screenids'][0].to_i end @@ -62,29 +62,29 @@ def get_or_create_for_host(data) height = data[:height] || 320 # default 320 width = data[:width] || 200 # default 200 vsize = data[:vsize] || [1, (graphids.size / hsize).to_i].max - screenid = get_id(:name => screen_name) + screenid = get_id(name: screen_name) unless screenid # Create screen graphids.each_with_index do |graphid, index| screenitems << { - :resourcetype => 0, - :resourceid => graphid, - :x => (index % hsize).to_i, - :y => (index % graphids.size / hsize).to_i, - :valign => valign, - :halign => halign, - :rowspan => rowspan, - :colspan => colspan, - :height => height, - :width => width, + resourcetype: 0, + resourceid: graphid, + x: (index % hsize).to_i, + y: (index % graphids.size / hsize).to_i, + valign: valign, + halign: halign, + rowspan: rowspan, + colspan: colspan, + height: height, + width: width } end screenid = create( - :name => screen_name, - :hsize => hsize, - :vsize => vsize, - :screenitems => screenitems + name: screen_name, + hsize: hsize, + vsize: vsize, + screenitems: screenitems ) end screenid diff --git a/lib/zabbixapi/classes/scripts.rb b/lib/zabbixapi/classes/scripts.rb index fbb6090..da9fe85 100644 --- a/lib/zabbixapi/classes/scripts.rb +++ b/lib/zabbixapi/classes/scripts.rb @@ -1,27 +1,35 @@ class ZabbixApi class Scripts < Basic - def method_name - "script" + 'script' end + # The id field name used for identifying specific Screen objects via Zabbix API + # + # @return [String] def indentify - "name" + 'name' end + # Submits a request to the zabbix api + # data - A Hash containing the scriptid and hostid + # + # Example: + # execute({ scriptid: '12', hostid: '32 }) + # + # Returns nothing def execute(data) @client.api_request( - :method => "script.execute", - :params => { - :scriptid => data[:scriptid], - :hostid => data[:hostid] + method: 'script.execute', + params: { + scriptid: data[:scriptid], + hostid: data[:hostid] } ) end def getscriptsbyhost(data) - @client.api_request(:method => "script.getscriptsbyhosts", :params => data) + @client.api_request(method: 'script.getscriptsbyhosts', params: data) end - end end diff --git a/lib/zabbixapi/classes/server.rb b/lib/zabbixapi/classes/server.rb index 1ec817f..6ee9eef 100644 --- a/lib/zabbixapi/classes/server.rb +++ b/lib/zabbixapi/classes/server.rb @@ -10,7 +10,7 @@ class Server # @return [String] Zabbix API version number def initialize(client) @client = client - @version = @client.api_request(:method => 'apiinfo.version', :params => {}) + @api_version = @client.api_request(method: 'apiinfo.version', params: {}) end end end diff --git a/lib/zabbixapi/classes/templates.rb b/lib/zabbixapi/classes/templates.rb index d7b0676..f0fb61a 100644 --- a/lib/zabbixapi/classes/templates.rb +++ b/lib/zabbixapi/classes/templates.rb @@ -21,7 +21,7 @@ def indentify # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK. # @return [Integer] The Template object id that was deleted def delete(data) - result = @client.api_request(:method => 'template.delete', :params => [data]) + result = @client.api_request(method: 'template.delete', params: [data]) result.empty? ? nil : result['templateids'][0].to_i end @@ -33,7 +33,7 @@ def delete(data) # @return [Array] Returns array of Template ids def get_ids_by_host(data) result = [] - @client.api_request(:method => 'template.get', :params => data).each do |tmpl| + @client.api_request(method: 'template.get', params: data).each do |tmpl| result << tmpl['templateid'] end result @@ -46,7 +46,7 @@ def get_ids_by_host(data) # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK. # @return [Integer] Zabbix object id def get_or_create(data) - unless (templateid = get_id(:host => data[:host])) + unless (templateid = get_id(host: data[:host])) templateid = create(data) end templateid @@ -60,10 +60,10 @@ def get_or_create(data) # @return [Boolean] def mass_update(data) result = @client.api_request( - :method => 'template.massUpdate', - :params => { - :hosts => data[:hosts_id].map { |t| {:hostid => t} }, - :templates => data[:templates_id].map { |t| {:templateid => t} }, + method: 'template.massUpdate', + params: { + hosts: data[:hosts_id].map { |t| {hostid: t} }, + templates: data[:templates_id].map { |t| {templateid: t} } } ) result.empty? ? false : true @@ -77,10 +77,10 @@ def mass_update(data) # @return [Boolean] def mass_add(data) result = @client.api_request( - :method => 'template.massAdd', - :params => { - :hosts => data[:hosts_id].map { |t| {:hostid => t} }, - :templates => data[:templates_id].map { |t| {:templateid => t} }, + method: 'template.massAdd', + params: { + hosts: data[:hosts_id].map { |t| {hostid: t} }, + templates: data[:templates_id].map { |t| {templateid: t} } } ) result.empty? ? false : true @@ -94,12 +94,12 @@ def mass_add(data) # @return [Boolean] def mass_remove(data) result = @client.api_request( - :method => 'template.massRemove', - :params => { - :hostids => data[:hosts_id], - :templateids => data[:templates_id], - :groupids => data[:group_id], - :force => 1, + method: 'template.massRemove', + params: { + hostids: data[:hosts_id], + templateids: data[:templates_id], + groupids: data[:group_id], + force: 1 } ) result.empty? ? false : true diff --git a/lib/zabbixapi/classes/triggers.rb b/lib/zabbixapi/classes/triggers.rb index ee54691..11a9691 100644 --- a/lib/zabbixapi/classes/triggers.rb +++ b/lib/zabbixapi/classes/triggers.rb @@ -24,14 +24,14 @@ def dump_by_id(data) log "[DEBUG] Call dump_by_id with parametrs: #{data.inspect}" @client.api_request( - :method => 'trigger.get', - :params => { - :filter => { - key.to_sym => data[key.to_sym], + method: 'trigger.get', + params: { + filter: { + key.to_sym => data[key.to_sym] }, - :output => 'extend', - :select_items => 'extend', - :select_functions => 'extend', + output: 'extend', + select_items: 'extend', + select_functions: 'extend' } ) end @@ -68,7 +68,7 @@ def safe_update(data) else data[:expression] = old_expression # disable old trigger - log '[DEBUG] disable :' + @client.api_request(:method => "#{method_name}.update", :params => [{:triggerid => data[:triggerid], :status => '1'}]).inspect + log '[DEBUG] disable :' + @client.api_request(method: "#{method_name}.update", params: [{triggerid: data[:triggerid], status: '1'}]).inspect # create new trigger data.delete(:triggerid) create(data) @@ -84,7 +84,7 @@ def safe_update(data) def get_or_create(data) log "[DEBUG] Call get_or_create with parameters: #{data.inspect}" - unless (id = get_id(:description => data[:description], :hostid => data[:hostid])) + unless (id = get_id(description: data[:description], hostid: data[:hostid])) id = create(data) end id @@ -97,8 +97,8 @@ def get_or_create(data) # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK. # @return [Integer] Zabbix object id def create_or_update(data) - triggerid = get_id(:description => data[:description], :hostid => data[:hostid]) - triggerid ? update(data.merge(:triggerid => triggerid)) : create(data) + triggerid = get_id(description: data[:description], hostid: data[:hostid]) + triggerid ? update(data.merge(triggerid: triggerid)) : create(data) end end end diff --git a/lib/zabbixapi/classes/usergroups.rb b/lib/zabbixapi/classes/usergroups.rb index 6770773..40fedcc 100644 --- a/lib/zabbixapi/classes/usergroups.rb +++ b/lib/zabbixapi/classes/usergroups.rb @@ -27,13 +27,13 @@ def indentify # @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 set_perms(data) + def permissions(data) permission = data[:permission] || 2 result = @client.api_request( - :method => 'usergroup.massAdd', - :params => { - :usrgrpids => [data[:usrgrpid]], - :rights => data[:hostgroupids].map { |t| {:permission => permission, :id => t} }, + method: 'usergroup.massAdd', + params: { + usrgrpids: [data[:usrgrpid]], + rights: data[:hostgroupids].map { |t| {permission: permission, id: t} } } ) result ? result['usrgrpids'][0].to_i : nil @@ -47,10 +47,10 @@ def set_perms(data) # @return [Integer] Zabbix object id (usergroup) def add_user(data) result = @client.api_request( - :method => 'usergroup.massAdd', - :params => { - :usrgrpids => data[:usrgrpids], - :userids => data[:userids], + method: 'usergroup.massAdd', + params: { + usrgrpids: data[:usrgrpids], + userids: data[:userids] } ) result ? result['usrgrpids'][0].to_i : nil @@ -64,10 +64,10 @@ def add_user(data) # @return [Integer] Zabbix object id (usergroup) def update_users(data) result = @client.api_request( - :method => 'usergroup.massUpdate', - :params => { - :usrgrpids => data[:usrgrpids], - :userids => data[:userids], + method: 'usergroup.massUpdate', + params: { + usrgrpids: data[:usrgrpids], + userids: data[:userids] } ) result ? result['usrgrpids'][0].to_i : nil diff --git a/lib/zabbixapi/classes/usermacros.rb b/lib/zabbixapi/classes/usermacros.rb index e5dabae..b569ef8 100644 --- a/lib/zabbixapi/classes/usermacros.rb +++ b/lib/zabbixapi/classes/usermacros.rb @@ -157,7 +157,7 @@ def update_global(data) def get_or_create(data) log "[DEBUG] Call get_or_create with parameters: #{data.inspect}" - unless (id = get_id(:macro => data[:macro], :hostid => data[:hostid])) + unless (id = get_id(macro: data[:macro], hostid: data[:hostid])) id = create(data) end id @@ -172,7 +172,7 @@ def get_or_create(data) def get_or_create_global(data) log "[DEBUG] Call get_or_create_global with parameters: #{data.inspect}" - unless (id = get_id_global(:macro => data[:macro], :hostid => data[:hostid])) + unless (id = get_id_global(macro: data[:macro], hostid: data[:hostid])) id = create_global(data) end id @@ -185,8 +185,8 @@ def get_or_create_global(data) # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK. # @return [Integer] Zabbix object id def create_or_update(data) - hostmacroid = get_id(:macro => data[:macro], :hostid => data[:hostid]) - hostmacroid ? update(data.merge(:hostmacroid => hostmacroid)) : create(data) + hostmacroid = get_id(macro: data[:macro], hostid: data[:hostid]) + hostmacroid ? update(data.merge(hostmacroid: hostmacroid)) : create(data) end # Create or update Global macro object using Zabbix API @@ -196,8 +196,8 @@ def create_or_update(data) # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK. # @return [Integer] Zabbix object id def create_or_update_global(data) - globalmacroid = get_id_global(:macro => data[:macro], :hostid => data[:hostid]) - globalmacroid ? update_global(data.merge(:globalmacroid => globalmacroid)) : create_global(data) + hostmacroid = get_id_global(macro: data[:macro], hostid: data[:hostid]) + hostmacroid ? update_global(data.merge(globalmacroid: globalmacroid)) : create_global(data) end private @@ -214,12 +214,12 @@ def request(data, method, result_key) # Zabbix has different result formats for gets vs updates if method.include?('.get') if result_key.include?('global') - @client.api_request(:method => method, :params => {:globalmacro => true, :filter => data}) + @client.api_request(method: method, params: {globalmacro: true, filter: data}) else - @client.api_request(:method => method, :params => {:filter => data}) + @client.api_request(method: method, params: {filter: data}) end else - result = @client.api_request(:method => method, :params => data) + result = @client.api_request(method: method, params: data) result.key?(result_key) && !result[result_key].empty? ? result[result_key][0].to_i : nil end diff --git a/lib/zabbixapi/classes/users.rb b/lib/zabbixapi/classes/users.rb index b807d54..87060b6 100644 --- a/lib/zabbixapi/classes/users.rb +++ b/lib/zabbixapi/classes/users.rb @@ -27,5 +27,39 @@ def key def indentify 'alias' end + + # Add media to users using Zabbix API + # + # @param data [Hash] Needs to include userids and media to mass add media to users + # @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 (media) + def add_medias(data) + result = @client.api_request( + method: 'user.addMedia', + params: { + users: data[:userids].map { |t| {userid: t} }, + medias: data[:media] + } + ) + result ? result['mediaids'][0].to_i : nil + end + + # Update media for users using Zabbix API + # + # @param data [Hash] Needs to include userids and media to mass update media for users + # @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 (user) + def update_medias(data) + result = @client.api_request( + method: 'user.updateMedia', + params: { + users: data[:userids].map { |t| {userid: t} }, + medias: data[:media] + } + ) + result ? result['userids'][0].to_i : nil + end end end diff --git a/lib/zabbixapi/classes/valuemaps.rb b/lib/zabbixapi/classes/valuemaps.rb index 4cf1f5e..7574272 100644 --- a/lib/zabbixapi/classes/valuemaps.rb +++ b/lib/zabbixapi/classes/valuemaps.rb @@ -30,7 +30,7 @@ def indentify def get_or_create(data) log "[DEBUG] Call get_or_create with parameters: #{data.inspect}" - unless (id = get_id(:valuemapids => data[:valuemapids])) + unless (id = get_id(valuemapids: data[:valuemapids])) id = create(data) end id @@ -43,8 +43,8 @@ def get_or_create(data) # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK. # @return [Integer] Zabbix object id def create_or_update(data) - valuemapid = get_id(:name => data[:name]) - valuemapid ? update(data.merge(:valuemapids => [:valuemapid])) : create(data) + valuemapid = get_id(name: data[:name]) + valuemapid ? update(data.merge(valuemapids: [:valuemapid])) : create(data) end end end diff --git a/lib/zabbixapi/client.rb b/lib/zabbixapi/client.rb index 6fcba55..a5d5e64 100644 --- a/lib/zabbixapi/client.rb +++ b/lib/zabbixapi/client.rb @@ -17,7 +17,7 @@ def id # # @return [String] def api_version - @version ||= api_request(:method => 'apiinfo.version', :params => {}) + @api_version ||= api_request(method: 'apiinfo.version', params: {}) end # Log in to the Zabbix Server and generate an auth token using the API @@ -25,10 +25,10 @@ def api_version # @return [Hash] def auth api_request( - :method => 'user.login', - :params => { - :user => @options[:user], - :password => @options[:password], + method: 'user.login', + params: { + user: @options[:user], + password: @options[:password] } ) end @@ -52,16 +52,11 @@ def initialize(options = {}) @proxy_port = @proxy_uri.port @proxy_user, @proxy_pass = @proxy_uri.userinfo.split(/:/) if @proxy_uri.userinfo end -<<<<<<< HEAD + unless api_version =~ /(2\.4|3\.[024]|4\.0)\.\d+/ raise ApiError.new("Zabbix API version: #{api_version} is not support by this version of zabbixapi") end -======= - end - - raise ApiError.new("Zabbix API version: #{api_version} is not support by this version of zabbixapi") unless api_version =~ /4\.\d\.\d+/ - end ->>>>>>> c12efab... updated version and Readme to explicitly only work on Zabbix 4 + @auth_hash = auth end @@ -71,10 +66,10 @@ def initialize(options = {}) # @return [String] def message_json(body) message = { - :method => body[:method], - :params => body[:params], - :id => id, - :jsonrpc => '2.0', + method: body[:method], + params: body[:params], + id: id, + jsonrpc: '2.0' } message[:auth] = @auth_hash unless body[:method] == 'apiinfo.version' || body[:method] == 'user.login' @@ -91,11 +86,12 @@ def http_request(body) timeout = @options[:timeout].nil? ? 60 : @options[:timeout] puts "[DEBUG] Timeout for request set to #{timeout} seconds" if @options[:debug] - if @proxy_uri - http = Net::HTTP.Proxy(@proxy_host, @proxy_port, @proxy_user, @proxy_pass).new(uri.host, uri.port) - else - http = Net::HTTP.new(uri.host, uri.port) - end + http = + if @proxy_uri + Net::HTTP.Proxy(@proxy_host, @proxy_port, @proxy_user, @proxy_pass).new(uri.host, uri.port) + else + Net::HTTP.new(uri.host, uri.port) + end if uri.scheme == 'https' http.use_ssl = true @@ -123,6 +119,7 @@ def _request(body) puts "[DEBUG] Send request: #{body}" if @options[:debug] result = JSON.parse(http_request(body)) raise ApiError.new("Server answer API error\n #{JSON.pretty_unparse(result['error'])}\n on request:\n #{pretty_body(body)}", result) if result['error'] + result['result'] end diff --git a/spec/action.rb b/spec/action.rb index a26629f..ba4f18a 100644 --- a/spec/action.rb +++ b/spec/action.rb @@ -1,62 +1,60 @@ -# encoding: utf-8 - require 'spec_helper' describe 'action' do before do @actionname = gen_name 'action' - @usergroupid = zbx.usergroups.create(:name => gen_name('usergroup')) + @usergroupid = zbx.usergroups.create(name: gen_name('usergroup')) @actiondata = { - :name => @actionname, - :eventsource => '0', # event source is a triggerid - :status => '0', # action is enabled - :esc_period => '120', # how long each step should take - :def_shortdata => 'Email header', - :def_longdata => 'Email content', - :maintenance_mode => '1', - :filter => { - :evaltype => '1', # perform 'and' between the conditions - :conditions => [ + name: @actionname, + eventsource: '0', # event source is a triggerid + status: '0', # action is enabled + esc_period: '120', # how long each step should take + def_shortdata: 'Email header', + def_longdata: 'Email content', + maintenance_mode: '1', + filter: { + evaltype: '1', # perform 'and' between the conditions + conditions: [ { - :conditiontype => '3', # trigger name - :operator => '2', # like - :value => 'pattern' # the pattern + conditiontype: '3', # trigger name + operator: '2', # like + value: 'pattern' # the pattern }, { - :conditiontype => '4', # trigger severity - :operator => '5', # >= - :value => '3' # average - }, - ], + conditiontype: '4', # trigger severity + operator: '5', # >= + value: '3' # average + } + ] }, - :operations => [ + operations: [ { - :operationtype => '0', # send message - :opmessage_grp => [ # who the message will be sent to + operationtype: '0', # send message + opmessage_grp: [ # who the message will be sent to { - :usrgrpid => @usergroupid, - }, + usrgrpid: @usergroupid + } ], - :opmessage => { - :default_msg => '0', # use default message - :mediatypeid => '1' # email id - }, - }, + opmessage: { + default_msg: '0', # use default message + mediatypeid: '1' # email id + } + } ], - :recovery_operations => [ + recovery_operations: [ { - :operationtype => '11', # send recovery message - :opmessage_grp => [ # who the message will be sent to + operationtype: '11', # send recovery message + opmessage_grp: [ # who the message will be sent to { - :usrgrpid => @usergroupid, - }, + usrgrpid: @usergroupid + } ], - :opmessage => { - :default_msg => '0', # use default message - :mediatypeid => '1' # email id - }, - }, - ], + opmessage: { + default_msg: '0', # use default message + mediatypeid: '1' # email id + } + } + ] } end diff --git a/spec/application.rb b/spec/application.rb index ab8cbfa..28fc80d 100644 --- a/spec/application.rb +++ b/spec/application.rb @@ -1,15 +1,13 @@ -# encoding: utf-8 - require 'spec_helper' describe 'application' do before :all do @hostgroup = gen_name 'hostgroup' - @hostgroupid = zbx.hostgroups.create(:name => @hostgroup) + @hostgroupid = zbx.hostgroups.create(name: @hostgroup) @template = gen_name 'template' @templateid = zbx.templates.create( - :host => @template, - :groups => [:groupid => @hostgroupid] + host: @template, + groups: [groupid: @hostgroupid] ) end @@ -21,8 +19,8 @@ describe 'create' do it 'should return integer id' do applicationid = zbx.applications.create( - :name => @application, - :hostid => @templateid + name: @application, + hostid: @templateid ) expect(applicationid).to be_kind_of(Integer) end @@ -30,7 +28,7 @@ describe 'get_id' do it 'should return nil' do - expect(zbx.applications.get_id(:name => @application)).to be_kind_of(NilClass) + expect(zbx.applications.get_id(name: @application)).to be_kind_of(NilClass) end end end @@ -39,8 +37,8 @@ before :all do @application = gen_name 'application' @applicationid = zbx.applications.create( - :name => @application, - :hostid => @templateid + name: @application, + hostid: @templateid ) end @@ -48,8 +46,8 @@ it 'should return id of application' do expect( zbx.applications.get_or_create( - :name => @application, - :hostid => @templateid + name: @application, + hostid: @templateid ) ).to eq @applicationid end @@ -57,13 +55,13 @@ describe 'get_full_data' do it 'should contains created application' do - expect(zbx.applications.get_full_data(:name => @application)[0]).to include('name' => @application) + expect(zbx.applications.get_full_data(name: @application)[0]).to include('name' => @application) end end describe 'get_id' do it 'should return id of application' do - expect(zbx.applications.get_id(:name => @application)).to eq @applicationid + expect(zbx.applications.get_id(name: @application)).to eq @applicationid end end @@ -71,8 +69,8 @@ it 'should return id of updated application' do expect( zbx.applications.create_or_update( - :name => @application, - :hostid => @templateid + name: @application, + hostid: @templateid ) ).to eq @applicationid end diff --git a/spec/configuration.rb b/spec/configuration.rb index 17d8ad0..eeac8dc 100644 --- a/spec/configuration.rb +++ b/spec/configuration.rb @@ -1,37 +1,35 @@ -# encoding: utf-8 - require 'spec_helper' describe 'configuration' do before :all do @hostgroup = gen_name 'hostgroup' - @hostgroup_id = zbx.hostgroups.create(:name => @hostgroup) + @hostgroup_id = zbx.hostgroups.create(name: @hostgroup) @template = gen_name 'template' @template_id = zbx.templates.create( - :host => @template, - :groups => [:groupid => @hostgroup_id] + host: @template, + groups: [groupid: @hostgroup_id] ) @source = zbx.configurations.export( - :format => 'xml', - :options => { - :templates => [@template_id], + format: 'xml', + options: { + templates: [@template_id] } ) @item = gen_name 'item' @item_id = zbx.items.create( - :name => @item, - :description => 'item', - :key_ => 'proc.num[aaa]', - :type => 0, - :value_type => 3, - :hostid => zbx.templates.get_id(:host => @template) + name: @item, + description: 'item', + key_: 'proc.num[aaa]', + type: 0, + value_type: 3, + hostid: zbx.templates.get_id(host: @template) ) end after :all do - zbx.items.delete(zbx.items.get_id(:name => @item)) - zbx.templates.delete(zbx.templates.get_id(:host => @template)) - zbx.hostgroups.delete(zbx.hostgroups.get_id(:name => @hostgroup)) + zbx.items.delete(zbx.items.get_id(name: @item)) + zbx.templates.delete(zbx.templates.get_id(host: @template)) + zbx.hostgroups.delete(zbx.hostgroups.get_id(name: @hostgroup)) end context 'when object not exists' do @@ -41,22 +39,22 @@ zbx.templates.delete(@template_id) zbx.hostgroups.delete(@hostgroup_id) zbx.configurations.import( - :format => 'xml', - :rules => { - :groups => { - :createMissing => true, - }, - :templates => { - :createMissing => true, + format: 'xml', + rules: { + groups: { + createMissing: true }, + templates: { + createMissing: true + } }, - :source => @source + source: @source ) end it 'should create object' do - expect(zbx.hostgroups.get_id(:name => @hostgroup)).to be_kind_of(Integer) - expect(zbx.templates.get_id(:host => @template)).to be_kind_of(Integer) + expect(zbx.hostgroups.get_id(name: @hostgroup)).to be_kind_of(Integer) + expect(zbx.templates.get_id(host: @template)).to be_kind_of(Integer) end end end @@ -65,21 +63,21 @@ describe 'export' do before do zbx.items.create( - :name => @item, - :description => 'item', - :key_ => 'proc.num[aaa]', - :type => 0, - :value_type => 3, - :hostid => zbx.templates.get_id(:host => @template) + name: @item, + description: 'item', + key_: 'proc.num[aaa]', + type: 0, + value_type: 3, + hostid: zbx.templates.get_id(host: @template) ) end it 'should export updated object' do expect( zbx.configurations.export( - :format => 'xml', - :options => { - :templates => [zbx.templates.get_id(:host => @template)], + format: 'xml', + options: { + templates: [zbx.templates.get_id(host: @template)] } ) ).to match(/#{@item}/) @@ -89,32 +87,32 @@ describe 'import with updateExisting' do before do @source_updated = zbx.configurations.export( - :format => 'xml', - :options => { - :templates => [zbx.templates.get_id(:host => @template)], + format: 'xml', + options: { + templates: [zbx.templates.get_id(host: @template)] } ) - zbx.items.delete(zbx.items.get_id(:name => @item)) + zbx.items.delete(zbx.items.get_id(name: @item)) zbx.configurations.import( - :format => 'xml', - :rules => { - :templates => { - :updateExisting => true, - }, - :items => { - :createMissing => true, + format: 'xml', + rules: { + templates: { + updateExisting: true }, + items: { + createMissing: true + } }, - :source => @source_updated + source: @source_updated ) end it 'should update object' do expect( zbx.configurations.export( - :format => 'xml', - :options => { - :templates => [zbx.templates.get_id(:host => @template)], + format: 'xml', + options: { + templates: [zbx.templates.get_id(host: @template)] } ) ).to match(/#{@item}/) diff --git a/spec/graph.rb b/spec/graph.rb index 28e393e..05f32cd 100644 --- a/spec/graph.rb +++ b/spec/graph.rb @@ -1,28 +1,26 @@ -# encoding: utf-8 - require 'spec_helper' describe 'graph' do before :all do @hostgroup = gen_name 'hostgroup' - @hostgroupid = zbx.hostgroups.create(:name => @hostgroup) + @hostgroupid = zbx.hostgroups.create(name: @hostgroup) @template = gen_name 'template' @templateid = zbx.templates.create( - :host => @template, - :groups => [:groupid => @hostgroupid] + host: @template, + groups: [groupid: @hostgroupid] ) @application = gen_name 'application' @applicationid = zbx.applications.create( - :name => @application, - :hostid => @templateid + name: @application, + hostid: @templateid ) @item = gen_name 'item' @itemid = zbx.items.create( - :name => @item, - :key_ => "proc.num[#{gen_name 'proc'}]", - :status => 0, - :hostid => @templateid, - :applications => [@applicationid] + name: @item, + key_: "proc.num[#{gen_name 'proc'}]", + status: 0, + hostid: @templateid, + applications: [@applicationid] ) @color = '123456' @@ -30,21 +28,21 @@ def gitems { - :itemid => @itemid, - :calc_fnc => '3', - :color => @color, - :type => '0', - :periods_cnt => '5', + itemid: @itemid, + calc_fnc: '3', + color: @color, + type: '0', + periods_cnt: '5' } end def create_graph(graph, _itemid) zbx.graphs.create( - :gitems => [gitems], - :show_triggers => '0', - :name => graph, - :width => '900', - :height => '200' + gitems: [gitems], + show_triggers: '0', + name: graph, + width: '900', + height: '200' ) end @@ -67,11 +65,11 @@ def create_graph(graph, _itemid) it 'should return id of existing graph' do expect( zbx.graphs.get_or_create( - :gitems => [gitems], - :show_triggers => '0', - :name => @graph, - :width => '900', - :height => '200' + gitems: [gitems], + show_triggers: '0', + name: @graph, + width: '900', + height: '200' ) ).to eq @graphid end @@ -93,13 +91,13 @@ def create_graph(graph, _itemid) describe 'get_id' do it 'should return id' do - expect(zbx.graphs.get_id(:name => @graph)).to eq @graphid + expect(zbx.graphs.get_id(name: @graph)).to eq @graphid end end describe 'get_ids_by_host' do it 'should contains id of graph' do - graph_array = zbx.graphs.get_ids_by_host(:host => @host) + graph_array = zbx.graphs.get_ids_by_host(host: @host) expect(graph_array).to be_kind_of(Array) expect(graph_array).to include(@graphid.to_s) end @@ -109,9 +107,9 @@ def create_graph(graph, _itemid) it 'should return id' do expect( zbx.graphs.update( - :graphid => @graphid, - :gitems => [gitems], - :ymax_type => 1 + graphid: @graphid, + gitems: [gitems], + ymax_type: 1 ) ).to eq @graphid end @@ -121,11 +119,11 @@ def create_graph(graph, _itemid) it 'should return existing id' do expect( zbx.graphs.create_or_update( - :gitems => [gitems], - :show_triggers => '1', - :name => @graph, - :width => '900', - :height => '200' + gitems: [gitems], + show_triggers: '1', + name: @graph, + width: '900', + height: '200' ) ).to eq @graphid end diff --git a/spec/host.rb b/spec/host.rb index 689188c..62d601b 100644 --- a/spec/host.rb +++ b/spec/host.rb @@ -1,11 +1,9 @@ -# encoding: utf-8 - require 'spec_helper' describe 'host' do before :all do @hostgroup = gen_name 'hostgroup' - @hostgroupid = zbx.hostgroups.create(:name => @hostgroup) + @hostgroupid = zbx.hostgroups.create(name: @hostgroup) end context 'when name not exists' do @@ -16,24 +14,24 @@ describe 'create' do it 'should return integer id' do hostid = zbx.hosts.create( - :host => @host, - :interfaces => [ + host: @host, + interfaces: [ { - :type => 1, - :main => 1, - :ip => '10.20.48.88', - :dns => '', - :port => '10050', - :useip => 1, - }, + type: 1, + main: 1, + ip: '10.20.48.88', + dns: '', + port: '10050', + useip: 1 + } ], - :groups => [:groupid => @hostgroupid] + groups: [groupid: @hostgroupid] ) expect(hostid).to be_kind_of(Integer) end it 'should create host in multiple groups' do - @hostgroupid2 = zbx.hostgroups.create(:name => gen_name('hostgroup')) + @hostgroupid2 = zbx.hostgroups.create(name: gen_name('hostgroup')) host = gen_name('host') hostid = zbx.hosts.create( host: host, @@ -44,12 +42,12 @@ ip: '192.168.0.1', dns: 'server.example.org', port: '10050', - useip: 0, - }, + useip: 0 + } ], groups: [ {groupid: @hostgroupid}, - {groupid: @hostgroupid2}, + {groupid: @hostgroupid2} ] ) @@ -63,7 +61,7 @@ describe 'get_id' do it 'should return nil' do - expect(zbx.hosts.get_id(:host => @host)).to be_kind_of(NilClass) + expect(zbx.hosts.get_id(host: @host)).to be_kind_of(NilClass) expect(zbx.hosts.get_id('host' => @host)).to be_kind_of(NilClass) end end @@ -73,18 +71,18 @@ before :all do @host = gen_name 'host' @hostid = zbx.hosts.create( - :host => @host, - :interfaces => [ + host: @host, + interfaces: [ { - :type => 1, - :main => 1, - :ip => '10.20.48.88', - :dns => '', - :port => '10050', - :useip => 1, - }, + type: 1, + main: 1, + ip: '10.20.48.88', + dns: '', + port: '10050', + useip: 1 + } ], - :groups => [:groupid => @hostgroupid] + groups: [groupid: @hostgroupid] ) end @@ -92,8 +90,8 @@ it 'should return id of host' do expect( zbx.hosts.get_or_create( - :host => @host, - :groups => [:groupid => @hostgroupid] + host: @host, + groups: [groupid: @hostgroupid] ) ).to eq @hostid end @@ -101,13 +99,13 @@ describe 'get_full_data' do it 'should contains created host' do - expect(zbx.hosts.get_full_data(:host => @host)[0]).to include('host' => @host) + expect(zbx.hosts.get_full_data(host: @host)[0]).to include('host' => @host) end end describe 'get_id' do it 'should return id of host' do - expect(zbx.hosts.get_id(:host => @host)).to eq @hostid + expect(zbx.hosts.get_id(host: @host)).to eq @hostid expect(zbx.hosts.get_id('host' => @host)).to eq @hostid end end @@ -116,18 +114,18 @@ it 'should return id of updated host' do expect( zbx.hosts.create_or_update( - :host => @host, - :interfaces => [ + host: @host, + interfaces: [ { - :type => 1, - :main => 1, - :ip => '10.20.48.89', - :port => '10050', - :useip => 1, - :dns => '', - }, + type: 1, + main: 1, + ip: '10.20.48.89', + port: '10050', + useip: 1, + dns: '' + } ], - :groups => [:groupid => @hostgroupid] + groups: [groupid: @hostgroupid] ) ).to eq @hostid end @@ -137,40 +135,40 @@ it 'should return id' do expect( zbx.hosts.update( - :hostid => @hostid, - :status => 0 + hostid: @hostid, + status: 0 ) ).to eq @hostid end it 'should update groups' do - @hostgroupid2 = zbx.hostgroups.create(:name => gen_name('hostgroup')) + @hostgroupid2 = zbx.hostgroups.create(name: gen_name('hostgroup')) expect( zbx.hosts.update( - :hostid => @hostid, - :groups => [:groupid => @hostgroupid2] + hostid: @hostid, + groups: [groupid: @hostgroupid2] ) ).to eq @hostid - expect(zbx.hosts.dump_by_id(:hostid => @hostid).first['groups'].first['groupid']).to eq @hostgroupid2.to_s + expect(zbx.hosts.dump_by_id(hostid: @hostid).first['groups'].first['groupid']).to eq @hostgroupid2.to_s end it 'should update interfaces when use with force: true' do new_ip = '1.2.3.4' zbx.hosts.update( { - :hostid => @hostid, - :interfaces => [ + hostid: @hostid, + interfaces: [ { - :type => 1, - :main => 1, - :ip => new_ip, - :port => '10050', - :useip => 1, - :dns => '', - }, - ], + type: 1, + main: 1, + ip: new_ip, + port: '10050', + useip: 1, + dns: '' + } + ] }, true ) @@ -179,7 +177,7 @@ method: 'host.get', params: { hostids: @hostid, - selectInterfaces: 'extend', + selectInterfaces: 'extend' } ).first diff --git a/spec/hostgroup.rb b/spec/hostgroup.rb index 0e867c0..ec5010e 100644 --- a/spec/hostgroup.rb +++ b/spec/hostgroup.rb @@ -1,12 +1,10 @@ -# encoding: utf-8 - require 'spec_helper' describe 'hostgroup' do context 'when not exists' do describe 'create' do it 'should return integer id after creation' do - hostgroupid = zbx.hostgroups.create(:name => "hostgroup_#{rand(1_000_000)}") + hostgroupid = zbx.hostgroups.create(name: "hostgroup_#{rand(1_000_000)}") expect(hostgroupid).to be_kind_of(Integer) end end @@ -15,28 +13,28 @@ context 'when exists' do before :all do @hostgroup = gen_name('hostgroup') - @hostgroupid = zbx.hostgroups.create(:name => @hostgroup) + @hostgroupid = zbx.hostgroups.create(name: @hostgroup) end describe 'get_id' do it 'should return id' do - expect(zbx.hostgroups.get_id(:name => @hostgroup)).to eq @hostgroupid + expect(zbx.hostgroups.get_id(name: @hostgroup)).to eq @hostgroupid end it 'should return nil for not existing group' do - expect(zbx.hostgroups.get_id(:name => "#{@hostgroup}______")).to be_kind_of(NilClass) + expect(zbx.hostgroups.get_id(name: "#{@hostgroup}______")).to be_kind_of(NilClass) end end describe 'get_or_create' do it 'should return id of existing hostgroup' do - expect(zbx.hostgroups.get_or_create(:name => @hostgroup)).to eq @hostgroupid + expect(zbx.hostgroups.get_or_create(name: @hostgroup)).to eq @hostgroupid end end describe 'create_or_update' do it 'should return id of hostgroup' do - expect(zbx.hostgroups.create_or_update(:name => @hostgroup)).to eq @hostgroupid + expect(zbx.hostgroups.create_or_update(name: @hostgroup)).to eq @hostgroupid end end diff --git a/spec/httptest.rb b/spec/httptest.rb index 0bf0157..7372761 100644 --- a/spec/httptest.rb +++ b/spec/httptest.rb @@ -1,15 +1,13 @@ -# encoding: utf-8 - require 'spec_helper' describe 'httptest' do before :all do @hostgroup = gen_name 'hostgroup' - @hostgroupid = zbx.hostgroups.create(:name => @hostgroup) + @hostgroupid = zbx.hostgroups.create(name: @hostgroup) @template = gen_name 'template' @templateid = zbx.templates.create( - :host => @template, - :groups => [:groupid => @hostgroupid] + host: @template, + groups: [groupid: @hostgroupid] ) end @@ -22,15 +20,15 @@ describe 'create' do it 'should return integer id' do httptestid = zbx.httptests.create( - :name => @httptest_name, - :hostid => @templateid, - :steps => [ + name: @httptest_name, + hostid: @templateid, + steps: [ { - :name => @step_name, - :url => 'http://localhost/zabbix/', - :status_codes => '200', - :no => 1, - }, + name: @step_name, + url: 'http://localhost/zabbix/', + status_codes: 200, + no: 1 + } ] ) expect(httptestid).to be_kind_of(Integer) @@ -39,7 +37,7 @@ describe 'get_id' do it 'should return nil' do - expect(zbx.httptests.get_id(:name => @httptest_name)).to be_kind_of(NilClass) + expect(zbx.httptests.get_id(name: @httptest_name)).to be_kind_of(NilClass) expect(zbx.httptests.get_id('name' => @httptest_name)).to be_kind_of(NilClass) end end @@ -50,15 +48,23 @@ @httptest_name = gen_name 'httptest_name' @step_name = gen_name 'step_name' @httptestid = zbx.httptests.create( - :name => @httptest_name, - :hostid => @templateid, - :steps => [ + name: @httptest_name, + hostid: @templateid, + steps: [ { +<<<<<<< HEAD :name => @step_name, :url => 'http://localhost/zabbix/', :status_codes => '200', :no => 1, }, +======= + name: @step_name, + url: 'http://localhost/zabbix/', + status_codes: 200, + no: 1 + } +>>>>>>> 17e60e3... ETSOE-413 ets_zabbixapi gem cleanup ] ) end @@ -67,15 +73,23 @@ it 'should return id of httptest' do expect( zbx.httptests.get_or_create( - :name => @httptest_name, - :hostid => @templateid, - :steps => [ + name: @httptest_name, + hostid: @templateid, + steps: [ { +<<<<<<< HEAD :name => @step_name, :url => 'http://localhost/zabbix/', :status_codes => '200', :no => 1, }, +======= + name: @step_name, + url: 'http://localhost/zabbix/', + status_codes: 200, + no: 1 + } +>>>>>>> 17e60e3... ETSOE-413 ets_zabbixapi gem cleanup ] ) ).to eq @httptestid @@ -84,13 +98,13 @@ describe 'get_full_data' do it 'should contain created httptest' do - expect(zbx.httptests.get_full_data(:name => @httptest_name)[0]).to include('name' => @httptest_name) + expect(zbx.httptests.get_full_data(name: @httptest_name)[0]).to include('name' => @httptest_name) end end describe 'get_id' do it 'should return id of httptest' do - expect(zbx.httptests.get_id(:name => @httptest_name)).to eq @httptestid + expect(zbx.httptests.get_id(name: @httptest_name)).to eq @httptestid expect(zbx.httptests.get_id('name' => @httptest_name)).to eq @httptestid end end @@ -99,15 +113,23 @@ it 'should return id of updated httptest' do expect( zbx.httptests.create_or_update( - :name => @httptest_name, - :hostid => @templateid, - :steps => [ + name: @httptest_name, + hostid: @templateid, + steps: [ { +<<<<<<< HEAD :name => @step_name, :url => 'http://localhost/zabbix/', :status_codes => '200', :no => 1, }, +======= + name: @step_name, + url: 'http://localhost/zabbix/', + status_codes: 200, + no: 1 + } +>>>>>>> 17e60e3... ETSOE-413 ets_zabbixapi gem cleanup ] ) ).to eq @httptestid @@ -118,15 +140,23 @@ it 'should return id' do expect( zbx.httptests.update( - :httptestid => @httptestid, - :status => 0, - :steps => [ + httptestid: @httptestid, + status: 0, + steps: [ { +<<<<<<< HEAD :name => @step_name, :url => 'http://localhost/zabbix/', :status_codes => '200', :no => 1, }, +======= + name: @step_name, + url: 'http://localhost/zabbix/', + status_codes: 200, + no: 1 + } +>>>>>>> 17e60e3... ETSOE-413 ets_zabbixapi gem cleanup ] ) ).to eq @httptestid diff --git a/spec/item.rb b/spec/item.rb index 3d71a5b..b1f9a5f 100644 --- a/spec/item.rb +++ b/spec/item.rb @@ -1,20 +1,18 @@ -# encoding: utf-8 - require 'spec_helper' describe 'item' do before :all do @hostgroup = gen_name 'hostgroup' - @hostgroupid = zbx.hostgroups.create(:name => @hostgroup) + @hostgroupid = zbx.hostgroups.create(name: @hostgroup) @template = gen_name 'template' @templateid = zbx.templates.create( - :host => @template, - :groups => [:groupid => @hostgroupid] + host: @template, + groups: [groupid: @hostgroupid] ) @application = gen_name 'application' @applicationid = zbx.applications.create( - :name => @application, - :hostid => @templateid + name: @application, + hostid: @templateid ) end @@ -26,11 +24,11 @@ describe 'create' do it 'should return integer id' do itemid = zbx.items.create( - :name => @item, - :key_ => "proc.num[#{gen_name 'proc'}]", - :status => 0, - :hostid => @templateid, - :applications => [@applicationid] + name: @item, + key_: "proc.num[#{gen_name 'proc'}]", + status: 0, + hostid: @templateid, + applications: [@applicationid] ) expect(itemid).to be_kind_of(Integer) end @@ -38,7 +36,7 @@ describe 'get_id' do it 'should return nil' do - expect(zbx.items.get_id(:name => @item)).to be_kind_of(NilClass) + expect(zbx.items.get_id(name: @item)).to be_kind_of(NilClass) end end end @@ -47,11 +45,11 @@ before :all do @item = gen_name 'item' @itemid = zbx.items.create( - :name => @item, - :key_ => 'proc.num[aaa]', - :status => 0, - :hostid => @templateid, - :applications => [@applicationid] + name: @item, + key_: 'proc.num[aaa]', + status: 0, + hostid: @templateid, + applications: [@applicationid] ) end @@ -59,11 +57,11 @@ it 'should return id of item' do expect( zbx.items.get_or_create( - :name => @item, - :key_ => "proc.num[#{gen_name 'proc'}]", - :status => 0, - :hostid => @templateid, - :applications => [@applicationid] + name: @item, + key_: "proc.num[#{gen_name 'proc'}]", + status: 0, + hostid: @templateid, + applications: [@applicationid] ) ).to eq @itemid end @@ -71,13 +69,13 @@ describe 'get_full_data' do it 'should contains created item' do - expect(zbx.items.get_full_data(:name => @item)[0]).to include('name' => @item) + expect(zbx.items.get_full_data(name: @item)[0]).to include('name' => @item) end end describe 'get_id' do it 'should return id of item' do - expect(zbx.items.get_id(:name => @item)).to eq @itemid + expect(zbx.items.get_id(name: @item)).to eq @itemid end end @@ -89,8 +87,8 @@ it 'should return id' do expect( zbx.items.update( - :itemid => zbx.items.get_id(:name => @item), - :status => 1 + itemid: zbx.items.get_id(name: @item), + status: 1 ) ).to eq @itemid end @@ -100,22 +98,22 @@ it 'should update existing item' do expect( zbx.items.create_or_update( - :name => @item, - :key_ => "proc.num[#{gen_name 'proc'}]", - :status => 0, - :hostid => @templateid, - :applications => [@applicationid] + name: @item, + key_: "proc.num[#{gen_name 'proc'}]", + status: 0, + hostid: @templateid, + applications: [@applicationid] ) ).to eq @itemid end it 'should create item' do new_item_id = zbx.items.create_or_update( - :name => @item + '____1', - :key_ => "proc.num[#{gen_name 'proc'}]", - :status => 0, - :hostid => @templateid, - :applications => [@applicationid] + name: @item + '____1', + key_: "proc.num[#{gen_name 'proc'}]", + status: 0, + hostid: @templateid, + applications: [@applicationid] ) expect(new_item_id).to be_kind_of(Integer) @@ -133,7 +131,7 @@ end it 'should delete item from zabbix' do - expect(zbx.items.get_id(:name => @item)).to be_nil + expect(zbx.items.get_id(name: @item)).to be_nil end end end diff --git a/spec/maintenance.rb b/spec/maintenance.rb index 0c2b981..781d1f1 100644 --- a/spec/maintenance.rb +++ b/spec/maintenance.rb @@ -1,21 +1,19 @@ -# encoding: utf-8 - require 'spec_helper' describe 'maintenance' do context 'when not exists' do before :all do - @hostgroupid = zbx.hostgroups.create(:name => "hostgroup_#{rand(1_000_000)}") + @hostgroupid = zbx.hostgroups.create(name: "hostgroup_#{rand(1_000_000)}") end describe 'create' do it 'should return integer id after creation' do maintenanceid = zbx.maintenance.create( - :name => "maintenance_#{rand(1_000_000)}", - :groupids => [@hostgroupid], - :active_since => '1358844540', - :active_till => '1390466940', - :timeperiods => [:timeperiod_type => 3, :every => 1, :dayofweek => 64, :start_time => 64_800, :period => 3_600] + name: "maintenance_#{rand(1_000_000)}", + groupids: [@hostgroupid], + active_since: '1358844540', + active_till: '1390466940', + timeperiods: [timeperiod_type: 3, every: 1, dayofweek: 64, start_time: 64_800, period: 3_600] ) expect(maintenanceid).to be_kind_of(Integer) zbx.maintenance.delete(maintenanceid) @@ -29,36 +27,36 @@ context 'when exists' do before :all do - @hostgroupid_when_exists = zbx.hostgroups.create(:name => "hostgroup_#{rand(1_000_000)}") + @hostgroupid_when_exists = zbx.hostgroups.create(name: "hostgroup_#{rand(1_000_000)}") @maintenance = gen_name('maintenance') @maintenanceid = zbx.maintenance.create( - :name => @maintenance, - :groupids => [@hostgroupid_when_exists], - :active_since => '1358844540', - :active_till => '1390466940', - :timeperiods => [:timeperiod_type => 3, :every => 1, :dayofweek => 64, :start_time => 64_800, :period => 3_600] + name: @maintenance, + groupids: [@hostgroupid_when_exists], + active_since: '1358844540', + active_till: '1390466940', + timeperiods: [timeperiod_type: 3, every: 1, dayofweek: 64, start_time: 64_800, period: 3_600] ) end describe 'get_id' do it 'should return id' do - expect(zbx.maintenance.get_id(:name => @maintenance)).to eq @maintenanceid + expect(zbx.maintenance.get_id(name: @maintenance)).to eq @maintenanceid end it 'should return nil for not existing group' do - expect(zbx.maintenance.get_id(:name => "#{@maintenance}______")).to be_kind_of(NilClass) + expect(zbx.maintenance.get_id(name: "#{@maintenance}______")).to be_kind_of(NilClass) end end describe 'get_or_create' do it 'should return id of existing maintenance' do - expect(zbx.maintenance.get_or_create(:name => @maintenance)).to eq @maintenanceid + expect(zbx.maintenance.get_or_create(name: @maintenance)).to eq @maintenanceid end end describe 'create_or_update' do it 'should return id of maintenance' do - expect(zbx.maintenance.create_or_update(:name => @maintenance)).to eq @maintenanceid + expect(zbx.maintenance.create_or_update(name: @maintenance)).to eq @maintenanceid end end diff --git a/spec/mediatype.rb b/spec/mediatype.rb index d9dad6c..055141a 100644 --- a/spec/mediatype.rb +++ b/spec/mediatype.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'spec_helper' describe 'mediatype' do @@ -11,11 +9,11 @@ describe 'create' do it 'should return integer id' do mediatypeid = zbx.mediatypes.create( - :description => @mediatype, - :type => 0, - :smtp_server => '127.0.0.1', - :smtp_email => 'zabbix@test.com', - :smtp_helo => 'test.com' + description: @mediatype, + type: 0, + smtp_server: '127.0.0.1', + smtp_email: 'zabbix@test.com', + smtp_helo: 'test.com' ) expect(mediatypeid).to be_kind_of(Integer) end @@ -25,11 +23,11 @@ context 'when exists' do before do @mediatypeid = zbx.mediatypes.create( - :description => @mediatype, - :type => 0, - :smtp_server => '127.0.0.1', - :smtp_email => 'zabbix@test.com', - :smtp_helo => 'test.com' + description: @mediatype, + type: 0, + smtp_server: '127.0.0.1', + smtp_email: 'zabbix@test.com', + smtp_helo: 'test.com' ) end @@ -37,9 +35,9 @@ it 'should return id' do expect( zbx.mediatypes.create_or_update( - :description => @mediatype, - :smtp_email => 'zabbix2@test.com', - :smtp_helo => 'test.com' + description: @mediatype, + smtp_email: 'zabbix2@test.com', + smtp_helo: 'test.com' ) ).to eq @mediatypeid end diff --git a/spec/query.rb b/spec/query.rb index 26809e9..c875010 100644 --- a/spec/query.rb +++ b/spec/query.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'spec_helper' describe 'query' do @@ -9,9 +7,9 @@ method: 'host.get', params: { filter: { - host: 'asdf', + host: 'asdf' }, - selectInterfaces: 'refer', + selectInterfaces: 'refer' } ) ).to be_kind_of(Array) diff --git a/spec/screen.rb b/spec/screen.rb index 59d1fd7..5120e7a 100644 --- a/spec/screen.rb +++ b/spec/screen.rb @@ -1,48 +1,46 @@ -# encoding: utf-8 - require 'spec_helper' describe 'screen' do before :all do @hostgroup = gen_name 'hostgroup' - @hostgroupid = zbx.hostgroups.create(:name => @hostgroup) + @hostgroupid = zbx.hostgroups.create(name: @hostgroup) @template = gen_name 'template' @templateid = zbx.templates.create( - :host => @template, - :groups => [:groupid => @hostgroupid] + host: @template, + groups: [groupid: @hostgroupid] ) @application = gen_name 'application' @applicationid = zbx.applications.create( - :name => @application, - :hostid => @templateid + name: @application, + hostid: @templateid ) @item = gen_name 'item' @itemid = zbx.items.create( - :name => @item, - :key_ => "proc.num[#{gen_name 'proc'}]", - :status => 0, - :hostid => @templateid, - :applications => [@applicationid] + name: @item, + key_: "proc.num[#{gen_name 'proc'}]", + status: 0, + hostid: @templateid, + applications: [@applicationid] ) @color = '123456' @gitems = { - :itemid => @itemid, - :calc_fnc => '3', - :color => @color, - :type => '0', - :periods_cnt => '5', + itemid: @itemid, + calc_fnc: '3', + color: @color, + type: '0', + periods_cnt: '5' } @graph = gen_name 'graph' @graphid = zbx.graphs.create( - :gitems => [@gitems], - :show_triggers => '0', - :name => @graph, - :width => '900', - :height => '200' + gitems: [@gitems], + show_triggers: '0', + name: @graph, + width: '900', + height: '200' ) @screen_name = gen_name 'screen' @@ -52,8 +50,8 @@ describe 'get_or_create_for_host' do it 'should return id' do screenid = zbx.screens.get_or_create_for_host( - :screen_name => @screen_name, - :graphids => [@graphid] + screen_name: @screen_name, + graphids: [@graphid] ) expect(screenid).to be_kind_of(Integer) end @@ -64,16 +62,16 @@ before do @screen_name = gen_name 'screen' @screenid = zbx.screens.get_or_create_for_host( - :screen_name => @screen_name, - :graphids => [@graphid] + screen_name: @screen_name, + graphids: [@graphid] ) end describe 'get_or_create_for_host' do it 'should return id' do screenid = zbx.screens.get_or_create_for_host( - :screen_name => @screen_name, - :graphids => [@graphid] + screen_name: @screen_name, + graphids: [@graphid] ) expect(screenid).to eq @screenid end diff --git a/spec/script.rb b/spec/script.rb index 206a6b5..37dd8a7 100644 --- a/spec/script.rb +++ b/spec/script.rb @@ -1,10 +1,8 @@ -#encoding: utf-8 - require 'spec_helper' describe 'script' do before :all do - @hostid = zbx.hosts.get_id(:host => 'Zabbix server') + @hostid = zbx.hosts.get_id(host: 'Zabbix server') end context 'when name not exists' do @@ -13,18 +11,18 @@ end describe 'create' do - it "should return integer id" do + it 'should return integer id' do scriptid = zbx.scripts.create( - :name => @script, - :command => 'hostname', + name: @script, + command: 'hostname' ) expect(scriptid).to be_kind_of(Integer) end end describe 'get_id' do - it "should return nil" do - expect(zbx.scripts.get_id(:name => @script)).to be_kind_of(NilClass) + it 'should return nil' do + expect(zbx.scripts.get_id(name: @script)).to be_kind_of(NilClass) end end end @@ -33,57 +31,58 @@ before :all do @script = gen_name 'script' @scriptid = zbx.scripts.create( - :name => @script, - :command => 'hostname', + name: @script, + command: 'hostname' ) end describe 'get_or_create' do - it "should return id of script" do + it 'should return id of script' do expect(zbx.scripts.get_or_create( - :name => @script, - :command => 'hostname', - )).to eq @scriptid + name: @script, + command: 'hostname' + )).to eq @scriptid end end describe 'get_full_data' do - it "should contains created script" do - expect(zbx.scripts.get_full_data(:name => @script)[0]).to include("name" => @script) + it 'should contains created script' do + expect(zbx.scripts.get_full_data(name: @script)[0]).to include('name' => @script) end end describe 'get_id' do - it "should return id of script" do - expect(zbx.scripts.get_id(:name => @script)).to eq @scriptid + it 'should return id of script' do + expect(zbx.scripts.get_id(name: @script)).to eq @scriptid end end - it "should raise error on no identity given" do - expect { zbx.scripts.get_id({}) }.to raise_error(ZabbixApi::ApiError) + it 'should raise error on no identity given' do + expect { zbx.scripts.get_id({}) }.to raise_error(ZabbixApi::ApiError) end describe 'update' do - it "should return id" do + it 'should return id' do expect(zbx.scripts.update( - :scriptid => zbx.scripts.get_id(:name => @script), - :confirmation => 'Are you sure you would like to show the system hostname?' - )).to eq @scriptid + scriptid: zbx.scripts.get_id(name: @script), + enable_confirmation: 1, + confirmation: 'Are you sure you would like to show the system hostname?' + )).to eq @scriptid end end describe 'create_or_update' do - it "should update existing script" do + it 'should update existing script' do expect(zbx.scripts.get_or_create( - :name => @script, - :command => 'hostname', - )).to eq @scriptid + name: @script, + command: 'hostname' + )).to eq @scriptid end - it "should create script" do + it 'should create script' do new_script_id = zbx.scripts.get_or_create( - :name => @script + "____1", - :command => 'hostname', + name: @script + '____1', + command: 'hostname' ) expect(new_script_id).to be_kind_of(Integer) @@ -92,15 +91,15 @@ end # TODO: see if we can get this test working with travis ci (passes on standalone zabbix server) - #describe 'execute' do + # describe 'execute' do # it "should return success response" do # expect(zbx.scripts.execute(:scriptid => @scriptid, :hostid => @hostid)).to include("response" => "success") # end - #end + # end describe 'getscriptsbyhost' do - it "should return object with hostid and script" do - expect(zbx.scripts.getscriptsbyhost([@hostid])[@hostid.to_s].select { |script| script[:name] == @script}).to_not be_nil + it 'should return object with hostid and script' do + expect(zbx.scripts.getscriptsbyhost([@hostid])[@hostid.to_s].select { |script| script[:name] == @script }).to_not be_nil end end @@ -109,14 +108,13 @@ @result = zbx.scripts.delete(@scriptid) end - it "should return deleted id" do + it 'should return deleted id' do expect(@result).to eq @scriptid end - it "should delete script from zabbix" do - expect(zbx.scripts.get_id(:name => @script)).to be_nil + it 'should delete script from zabbix' do + expect(zbx.scripts.get_id(name: @script)).to be_nil end end - end end diff --git a/spec/server.rb b/spec/server.rb index a622e50..b7d9821 100644 --- a/spec/server.rb +++ b/spec/server.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'spec_helper' describe 'server' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6143226..f457034 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,10 +7,10 @@ def zbx @api_password = ENV['ZABBIX_PASSWORD'] || 'zabbix' @zbx ||= ZabbixApi.connect( - :url => @api_url, - :user => @api_login, - :password => @api_password, - :debug => ENV['ZABBIX_DEBUG'] ? true : false + url: @api_url, + user: @api_login, + password: @api_password, + debug: ENV['ZABBIX_DEBUG'] ? true : false ) end diff --git a/spec/template.rb b/spec/template.rb index 3569879..29ddecd 100644 --- a/spec/template.rb +++ b/spec/template.rb @@ -1,11 +1,9 @@ -# encoding: utf-8 - require 'spec_helper' describe 'template' do before :all do @hostgroup = gen_name 'hostgroup' - @hostgroupid = zbx.hostgroups.create(:name => @hostgroup) + @hostgroupid = zbx.hostgroups.create(name: @hostgroup) end context 'when name not exists' do @@ -16,8 +14,8 @@ describe 'create' do it 'should return integer id' do templateid = zbx.templates.create( - :host => @template, - :groups => [:groupid => @hostgroupid] + host: @template, + groups: [groupid: @hostgroupid] ) expect(templateid).to be_kind_of(Integer) end @@ -25,7 +23,7 @@ describe 'get_id' do it 'should return nil' do - expect(zbx.templates.get_id(:host => @template)).to be_kind_of(NilClass) + expect(zbx.templates.get_id(host: @template)).to be_kind_of(NilClass) end end end @@ -34,8 +32,8 @@ before :all do @template = gen_name 'template' @templateid = zbx.templates.create( - :host => @template, - :groups => [:groupid => @hostgroupid] + host: @template, + groups: [groupid: @hostgroupid] ) end @@ -43,8 +41,8 @@ it 'should return id of template' do expect( zbx.templates.get_or_create( - :host => @template, - :groups => [:groupid => @hostgroupid] + host: @template, + groups: [groupid: @hostgroupid] ) ).to eq @templateid end @@ -52,13 +50,13 @@ describe 'get_full_data' do it 'should contains created template' do - expect(zbx.templates.get_full_data(:host => @template)[0]).to include('host' => @template) + expect(zbx.templates.get_full_data(host: @template)[0]).to include('host' => @template) end end describe 'get_id' do it 'should return id of template' do - expect(zbx.templates.get_id(:host => @template)).to eq @templateid + expect(zbx.templates.get_id(host: @template)).to eq @templateid end end @@ -72,8 +70,8 @@ it 'should return id' do template = gen_name 'template' templateid = zbx.templates.create( - :host => template, - :groups => [:groupid => @hostgroupid] + host: template, + groups: [groupid: @hostgroupid] ) expect(zbx.templates.delete(templateid)).to eq templateid end @@ -83,18 +81,18 @@ before :all do @host = gen_name 'host' @hostid = zbx.hosts.create( - :host => @host, - :interfaces => [ + host: @host, + interfaces: [ { - :type => 1, - :main => 1, - :ip => '10.20.48.88', - :dns => '', - :port => '10050', - :useip => 1, - }, + type: 1, + main: 1, + ip: '10.20.48.88', + dns: '', + port: '10050', + useip: 1 + } ], - :groups => [:groupid => @hostgroupid] + groups: [groupid: @hostgroupid] ) end @@ -103,8 +101,8 @@ it 'should return true' do expect( zbx.templates.mass_update( - :hosts_id => [@hostid], - :templates_id => [@templateid] + hosts_id: [@hostid], + templates_id: [@templateid] ) ).to be true end @@ -114,15 +112,15 @@ context 'linked with host' do before :all do zbx.templates.mass_update( - :hosts_id => [@hostid], - :templates_id => [@templateid] + hosts_id: [@hostid], + templates_id: [@templateid] ) end describe 'get_ids_by_host' do it 'should contains id of linked template' do tmpl_array = zbx.templates.get_ids_by_host( - :hostids => [@hostid] + hostids: [@hostid] ) expect(tmpl_array).to be_kind_of(Array) expect(tmpl_array).to include @templateid.to_s @@ -133,8 +131,8 @@ it 'should return true' do expect( zbx.templates.mass_add( - :hosts_id => [@hostid], - :templates_id => [@templateid] + hosts_id: [@hostid], + templates_id: [@templateid] ) ).to be_kind_of(TrueClass) end @@ -144,8 +142,8 @@ it 'should return true' do expect( zbx.templates.mass_remove( - :hosts_id => [@hostid], - :templates_id => [@templateid] + hosts_id: [@hostid], + templates_id: [@templateid] ) ).to be true end diff --git a/spec/trigger.rb b/spec/trigger.rb index bdbccbd..8493dae 100644 --- a/spec/trigger.rb +++ b/spec/trigger.rb @@ -1,29 +1,27 @@ -# encoding: utf-8 - require 'spec_helper' describe 'trigger' do before :all do @hostgroup = gen_name 'hostgroup' - @hostgroupid = zbx.hostgroups.create(:name => @hostgroup) + @hostgroupid = zbx.hostgroups.create(name: @hostgroup) @template = gen_name 'template' @templateid = zbx.templates.create( - :host => @template, - :groups => [:groupid => @hostgroupid] + host: @template, + groups: [groupid: @hostgroupid] ) @application = gen_name 'application' @applicationid = zbx.applications.create( - :name => @application, - :hostid => @templateid + name: @application, + hostid: @templateid ) @item = gen_name 'item' @proc = "proc.num[#{gen_name 'proc'}]" @itemid = zbx.items.create( - :name => @item, - :key_ => @proc, - :status => 0, - :hostid => @templateid, - :applications => [@applicationid] + name: @item, + key_: @proc, + status: 0, + hostid: @templateid, + applications: [@applicationid] ) end @@ -32,21 +30,21 @@ it 'should return integer id' do @trigger = gen_name 'trigger' triggerid = zbx.triggers.create( - :description => @trigger, - :expression => "{#{@template}:#{@proc}.last(0)}<1", - :comments => 'Bla-bla is faulty (disaster)', - :priority => 5, - :status => 0, - :type => 0, - :tags => [ + description: @trigger, + expression: "{#{@template}:#{@proc}.last(0)}<1", + comments: 'Bla-bla is faulty (disaster)', + priority: 5, + status: 0, + type: 0, + tags: [ { - :tag => 'proc', - :value => @proc.to_s, + tag: 'proc', + value: @proc.to_s }, { - :tag => 'error', - :value => '', - }, + tag: 'error', + value: '' + } ] ) expect(triggerid).to be_kind_of(Integer) @@ -58,28 +56,28 @@ before :all do @trigger = gen_name 'trigger' @triggerid = zbx.triggers.create( - :description => @trigger, - :expression => "{#{@template}:#{@proc}.last(0)}<1", - :comments => 'Bla-bla is faulty (disaster)', - :priority => 5, - :status => 0, - :type => 0, - :tags => [ + description: @trigger, + expression: "{#{@template}:#{@proc}.last(0)}<1", + comments: 'Bla-bla is faulty (disaster)', + priority: 5, + status: 0, + type: 0, + tags: [ { - :tag => 'proc', - :value => @proc.to_s, + tag: 'proc', + value: @proc.to_s }, { - :tag => 'error', - :value => '', - }, + tag: 'error', + value: '' + } ] ) end describe 'get_id' do it 'should return id' do - expect(zbx.triggers.get_id(:description => @trigger)).to eq @triggerid + expect(zbx.triggers.get_id(description: @trigger)).to eq @triggerid end end @@ -87,8 +85,8 @@ it 'should return id of updated trigger' do expect( zbx.triggers.create_or_update( - :description => @trigger, - :hostid => @templateid + description: @trigger, + hostid: @templateid ) ).to eq @triggerid end diff --git a/spec/user.rb b/spec/user.rb index a863c57..6948c9a 100644 --- a/spec/user.rb +++ b/spec/user.rb @@ -1,29 +1,27 @@ -# encoding: utf-8 - require 'spec_helper' describe 'user' do before :all do @usergroup = gen_name 'usergroup' - @usergroupid = zbx.usergroups.create(:name => @usergroup) + @usergroupid = zbx.usergroups.create(name: @usergroup) @mediatype = gen_name 'mediatype' @mediatypeid = zbx.mediatypes.create( - :description => @mediatype, - :type => 0, - :smtp_server => '127.0.0.1', - :smtp_email => 'zabbix@test.com', - :smtp_helo => 'test.com' + description: @mediatype, + type: 0, + smtp_server: '127.0.0.1', + smtp_email: 'zabbix@test.com', + smtp_helo: 'test.com' ) end def media { - :mediatypeid => @mediatypeid, - :sendto => 'test@test', - :active => 0, - :period => '1-7,00:00-24:00', - :severity => '56', + mediatypeid: @mediatypeid, + sendto: 'test@test', + active: 0, + period: '1-7,00:00-24:00', + severity: '56' } end @@ -32,11 +30,11 @@ def media it 'should return integer id' do user = gen_name 'user' userid = zbx.users.create( - :alias => user, - :name => user, - :surname => user, - :passwd => user, - :usrgrps => [@usergroupid] + alias: user, + name: user, + surname: user, + passwd: user, + usrgrps: [@usergroupid] ) expect(userid).to be_kind_of(Integer) end @@ -44,7 +42,7 @@ def media describe 'get_id' do it 'should return nil' do - expect(zbx.users.get_id(:alias => 'name_____')).to be_nil + expect(zbx.users.get_id(alias: 'name_____')).to be_nil end end end @@ -53,11 +51,11 @@ def media before :all do @user = gen_name 'user' @userid = zbx.users.create( - :alias => @user, - :name => @user, - :surname => @user, - :passwd => @user, - :usrgrps => [@usergroupid] + alias: @user, + name: @user, + surname: @user, + passwd: @user, + usrgrps: [@usergroupid] ) end @@ -65,10 +63,10 @@ def media it 'should return id' do expect( zbx.users.create_or_update( - :alias => @user, - :name => @user, - :surname => @user, - :passwd => @user + alias: @user, + name: @user, + surname: @user, + passwd: @user ) ).to eq @userid end @@ -76,26 +74,38 @@ def media describe 'get_full_data' do it 'should return string name' do - expect(zbx.users.get_full_data(:alias => @user)[0]['name']).to be_kind_of(String) + expect(zbx.users.get_full_data(alias: @user)[0]['name']).to be_kind_of(String) end end describe 'update' do it 'should return id' do - expect(zbx.users.update(:userid => @userid, :name => gen_name('user'))).to eq @userid + expect(zbx.users.update(userid: @userid, name: gen_name('user'))).to eq @userid end end describe 'update by adding media' do it 'should return id' do expect( - zbx.users.update( - :userid => @userid, - :user_medias => [ - media, - ] + zbx.users.add_medias( + userids: [@userid], + media: [media] ) - ).to eq @userid + ).to be_kind_of(Integer) + end + end + + describe 'update_medias' do + it 'should return the user id' do + # Call twice to ensure update_medias first successfully creates the media, then updates it + 2.times do + returned_userid = zbx.users.update_medias( + userids: [@userid], + media: [media] + ) + + expect(returned_userid).to eq @userid + end end end diff --git a/spec/usergroup.rb b/spec/usergroup.rb index 6d7f39b..9e0a314 100644 --- a/spec/usergroup.rb +++ b/spec/usergroup.rb @@ -1,11 +1,9 @@ -# encoding: utf-8 - require 'spec_helper' describe 'usergroup' do context 'when not exists' do it 'should be integer id' do - usergroupid = zbx.usergroups.create(:name => gen_name('usergroup')) + usergroupid = zbx.usergroups.create(name: gen_name('usergroup')) expect(usergroupid).to be_kind_of(Integer) end end @@ -13,35 +11,31 @@ context 'when exists' do before do @usergroup = gen_name 'usergroup' - @usergroupid = zbx.usergroups.create(:name => @usergroup) + @usergroupid = zbx.usergroups.create(name: @usergroup) @user = gen_name 'user' @userid = zbx.users.create( - :alias => @user, - :name => @user, - :surname => @user, - :passwd => @user, - :usrgrps => [ - :usrgrpid => @usergroupid, - ] + alias: @user, + name: @user, + surname: @user, + passwd: @user, + usrgrps: [@usergroupid] ) @usergroup2 = gen_name 'usergroup' - @usergroupid2 = zbx.usergroups.create(:name => @usergroup2) + @usergroupid2 = zbx.usergroups.create(name: @usergroup2) @user2 = gen_name 'user' @userid2 = zbx.users.create( - :alias => @user2, - :name => @user2, - :surname => @user2, - :passwd => @user2, - :usrgrps => [ - :usrgrpid => @usergroupid2, - ] + alias: @user2, + name: @user2, + surname: @user2, + passwd: @user2, + usrgrps: [@usergroupid2] ) end describe 'get_or_create' do it 'should return id' do - expect(zbx.usergroups.get_or_create(:name => @usergroup)).to eq @usergroupid + expect(zbx.usergroups.get_or_create(name: @usergroup)).to eq @usergroupid end end @@ -49,8 +43,8 @@ it 'should return id' do expect( zbx.usergroups.add_user( - :usrgrpids => [@usergroupid], - :userids => [@userid2] + usrgrpids: [@usergroupid], + userids: [@userid2] ) ).to eq @usergroupid end @@ -60,20 +54,20 @@ it 'should return id' do expect( zbx.usergroups.update_users( - :usrgrpids => [@usergroupid2], - :userids => [@userid2] + usrgrpids: [@usergroupid2], + userids: [@userid2] ) ).to eq @usergroupid2 end end - describe 'set_perms' do + describe 'set_permissions' do it 'should return id' do expect( - zbx.usergroups.set_perms( - :usrgrpid => @usergroupid, - :hostgroupids => zbx.hostgroups.all.values, - :permission => 3 + zbx.usergroups.permissions( + usrgrpid: @usergroupid, + hostgroupids: zbx.hostgroups.all.values, + permission: 3 ) ).to eq @usergroupid end @@ -85,7 +79,7 @@ end it 'should return id of deleted group' do - usergroupid = zbx.usergroups.create(:name => gen_name('usergroup')) + usergroupid = zbx.usergroups.create(name: gen_name('usergroup')) expect(zbx.usergroups.delete(usergroupid)).to eq usergroupid end diff --git a/spec/usermacro.rb b/spec/usermacro.rb index ae0a68c..e5a705e 100644 --- a/spec/usermacro.rb +++ b/spec/usermacro.rb @@ -1,15 +1,13 @@ -# encoding: utf-8 - require 'spec_helper' describe 'usermacro' do before :all do @hostgroup = gen_name 'hostgroup' - @hostgroupid = zbx.hostgroups.create(:name => @hostgroup) + @hostgroupid = zbx.hostgroups.create(name: @hostgroup) @template = gen_name 'template' @templateid = zbx.templates.create( - :host => @template, - :groups => [:groupid => @hostgroupid] + host: @template, + groups: [groupid: @hostgroupid] ) end @@ -21,9 +19,9 @@ describe 'create' do it 'should return integer id' do hostmacroid = zbx.usermacros.create( - :macro => @hostmacro, - :value => 'public', - :hostid => @templateid + macro: @hostmacro, + value: 'public', + hostid: @templateid ) expect(hostmacroid).to be_kind_of(Integer) end @@ -31,7 +29,7 @@ describe 'get_id' do it 'should return nil' do - expect(zbx.usermacros.get_id(:macro => @hostmacro)).to be_kind_of(NilClass) + expect(zbx.usermacros.get_id(macro: @hostmacro)).to be_kind_of(NilClass) end end end @@ -40,9 +38,9 @@ before :all do @hostmacro = '{$' + gen_name('HOSTMACRO') + '}' @hostmacroid = zbx.usermacros.create( - :macro => @hostmacro, - :value => 'public', - :hostid => @templateid + macro: @hostmacro, + value: 'public', + hostid: @templateid ) end @@ -50,9 +48,9 @@ it 'should return id of hostmacro' do expect( zbx.usermacros.get_or_create( - :macro => @hostmacro, - :value => 'public', - :hostid => @templateid + macro: @hostmacro, + value: 'public', + hostid: @templateid ) ).to eq @hostmacroid end @@ -60,13 +58,13 @@ describe 'get_full_data' do it 'should contains created hostmacro' do - expect(zbx.usermacros.get_full_data(:macro => @hostmacro)[0]).to include('macro' => @hostmacro) + expect(zbx.usermacros.get_full_data(macro: @hostmacro)[0]).to include('macro' => @hostmacro) end end describe 'get_id' do it 'should return id of hostmacro' do - expect(zbx.usermacros.get_id(:macro => @hostmacro)).to eq @hostmacroid + expect(zbx.usermacros.get_id(macro: @hostmacro)).to eq @hostmacroid end end @@ -78,10 +76,10 @@ it 'should return id' do expect( zbx.usermacros.update( - :hostmacroid => zbx.usermacros.get_id( - :macro => @hostmacro + hostmacroid: zbx.usermacros.get_id( + macro: @hostmacro ), - :value => 'private' + value: 'private' ) ).to eq @hostmacroid end @@ -91,18 +89,18 @@ it 'should update existing usermacro' do expect( zbx.usermacros.create_or_update( - :macro => @hostmacro, - :value => 'public', - :hostid => @templateid + macro: @hostmacro, + value: 'public', + hostid: @templateid ) ).to eq @hostmacroid end it 'should create usermacro' do new_hostmacro_id = zbx.usermacros.create_or_update( - :macro => @hostmacro.gsub(/}/, '____1}'), - :value => 'public', - :hostid => @templateid + macro: @hostmacro.gsub(/}/, '____1}'), + value: 'public', + hostid: @templateid ) expect(new_hostmacro_id).to be_kind_of(Integer) @@ -120,7 +118,7 @@ end it 'should delete item from zabbix' do - expect(zbx.usermacros.get_id(:macro => @hostmacro)).to be_nil + expect(zbx.usermacros.get_id(macro: @hostmacro)).to be_nil end end end @@ -133,8 +131,8 @@ describe 'create_global' do it 'should return integer id' do globalmacroid = zbx.usermacros.create_global( - :macro => @globalmacro, - :value => 'public' + macro: @globalmacro, + value: 'public' ) expect(globalmacroid).to be_kind_of(Integer) end @@ -142,7 +140,7 @@ describe 'get_id_global' do it 'should return nil' do - expect(zbx.usermacros.get_id_global(:macro => @globalmacro)).to be_kind_of(NilClass) + expect(zbx.usermacros.get_id_global(macro: @globalmacro)).to be_kind_of(NilClass) end end end @@ -151,20 +149,20 @@ before :all do @globalmacro = '{$' + gen_name('GLOBALMACRO') + '}' @globalmacroid = zbx.usermacros.create_global( - :macro => @globalmacro, - :value => 'public' + macro: @globalmacro, + value: 'public' ) end describe 'get_full_data_global' do it 'should contains created globalmacro' do - expect(zbx.usermacros.get_full_data_global(:macro => @globalmacro)[0]).to include('macro' => @globalmacro) + expect(zbx.usermacros.get_full_data_global(macro: @globalmacro)[0]).to include('macro' => @globalmacro) end end describe 'get_id_global' do it 'should return id of globalmacro' do - expect(zbx.usermacros.get_id_global(:macro => @globalmacro)).to eq @globalmacroid + expect(zbx.usermacros.get_id_global(macro: @globalmacro)).to eq @globalmacroid end end @@ -176,10 +174,10 @@ it 'should return id' do expect( zbx.usermacros.update_global( - :globalmacroid => zbx.usermacros.get_id_global( - :macro => @globalmacro + globalmacroid: zbx.usermacros.get_id_global( + macro: @globalmacro ), - :value => 'private' + value: 'private' ) ).to eq @globalmacroid end @@ -195,7 +193,7 @@ end it 'should delete item from zabbix' do - expect(zbx.usermacros.get_id_global(:macro => @globalmacro)).to be_nil + expect(zbx.usermacros.get_id_global(macro: @globalmacro)).to be_nil end end end diff --git a/spec/valuemap.rb b/spec/valuemap.rb index 905fc34..d4c5323 100644 --- a/spec/valuemap.rb +++ b/spec/valuemap.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'spec_helper' describe 'valuemap' do @@ -11,10 +9,10 @@ describe 'create' do it 'should return an integer id' do valuemapid = zbx.valuemaps.create_or_update( - :name => @valuemap, - :mappings => [ - 'newvalue' => 'test', - 'value' => 'test' + name: @valuemap, + mappings: [ + 'newvalue' => 'test', + 'value' => 'test' ] ) expect(valuemapid).to be_kind_of(Integer) @@ -25,10 +23,10 @@ context 'when exists' do before do @valuemapid = zbx.valuemaps.create_or_update( - :name => @valuemap, - :mappings => [ - 'newvalue' => 'test', - 'value' => 'test' + name: @valuemap, + mappings: [ + 'newvalue' => 'test', + 'value' => 'test' ] ) end @@ -37,10 +35,10 @@ it 'should return id' do expect( zbx.valuemaps.create_or_update( - :name => @valuemap, - :mappings => [ - 'newvalue' => 'test', - 'value' => 'test' + name: @valuemap, + mappings: [ + 'newvalue' => 'test', + 'value' => 'test' ] ) ).to eq @valuemapid diff --git a/zabbixapi.gemspec b/zabbixapi.gemspec index f4daa23..998fafb 100644 --- a/zabbixapi.gemspec +++ b/zabbixapi.gemspec @@ -1,6 +1,4 @@ -# coding: utf-8 - -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) @@ -11,19 +9,19 @@ Gem::Specification.new do |spec| spec.add_dependency 'json', '~> 2.0' spec.add_development_dependency 'bundler', '~> 1.0' - spec.name = 'zabbixapi' + spec.name = 'ets_zabbixapi' spec.version = ZabbixApi::VERSION - spec.authors = ['Vasiliev D.V.', 'Ivan Evtuhovich'] - spec.email = ['vadv.mkn@gmail.com', 'evtuhovich@gmail.com'] + spec.authors = ['Scott Mackensen'] + spec.email = ['scott.mackensen@cerner.com'] - spec.summary = 'Simple and lightweight ruby module for working with the Zabbix API' - spec.description = 'Allows you to work with zabbix api from ruby.' - spec.homepage = 'https://github.com/express42/zabbixapi' + spec.summary = 'Internal Fork of the Zabbixapi Gem located here:https://github.com/express42/zabbixapi' + spec.description = 'Simple and lightweight ruby module for working with the Zabbix API' + spec.homepage = 'https://github.cerner.com/ETS/ets_zabbixapi' spec.licenses = 'MIT' spec.rubyforge_project = 'zabbixapi' spec.files = ['.yardopts', 'CHANGELOG.md', 'LICENSE.md', 'README.md', 'zabbixapi.gemspec'] + Dir['lib/**/*.rb'] spec.require_paths = 'lib' - spec.required_ruby_version = '>= 2.0.0' + spec.required_ruby_version = '>= 2.2.0' end