opsview_rest 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5f07bb5d9579733ba504371dcdde50cd397c15d
4
- data.tar.gz: 15aaae864adbc403135c0af3cf6f3d88b794ae7c
3
+ metadata.gz: c47caceb6cf6996f1ada216cbb64020cd89e2bf7
4
+ data.tar.gz: e5e4436ee08118e4817fca3a22a7f3ce2c6dbe09
5
5
  SHA512:
6
- metadata.gz: 51e4191a36adb6bc5c5e260a7d458a3eb020384f231bde0a5cdda795ce59a2866e9a97a64ba4b387102e814553e92fcae1edae8cef3d8b6a43b76c6ec1c28439
7
- data.tar.gz: 1f599e2413800c55569bdc3f9b9343e22e3bb87526fc0eb7bad808a7845f64b3469410b392a519ceb6c975d1563c201b170aab1c6c42111c36227d6d801e8341
6
+ metadata.gz: c7c084a5bb41b5a44f3201d9de19d9ece0775dc6678a0adb73479eac5427026147436953273aa4b6ec5b4edc04158f4c887e6c9e9c2ec237f5c60a17347d6782
7
+ data.tar.gz: da10bb0f01385b8b2a19c9fb63ee067fc6439b607bbc7993bdda4404d1f523f4a252ea20b343cbb088d2d4d25640ae7008153e022e7e91585e5c62916a8d4e68
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
@@ -0,0 +1,67 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-11-05 11:16:12 +0000 using RuboCop version 0.39.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ Lint/UnreachableCode:
11
+ Exclude:
12
+ - 'lib/opsview_rest.rb'
13
+
14
+ # Offense count: 1
15
+ Lint/UselessAssignment:
16
+ Exclude:
17
+ - 'spec/opsview_rest_spec.rb'
18
+
19
+ # Offense count: 7
20
+ Metrics/AbcSize:
21
+ Max: 31
22
+
23
+ # Offense count: 1
24
+ # Configuration parameters: CountComments.
25
+ Metrics/ClassLength:
26
+ Max: 144
27
+
28
+ # Offense count: 3
29
+ Metrics/CyclomaticComplexity:
30
+ Max: 14
31
+
32
+ # Offense count: 39
33
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
34
+ # URISchemes: http, https
35
+ Metrics/LineLength:
36
+ Max: 190
37
+
38
+ # Offense count: 15
39
+ # Configuration parameters: CountComments.
40
+ Metrics/MethodLength:
41
+ Max: 57
42
+
43
+ # Offense count: 5
44
+ Metrics/PerceivedComplexity:
45
+ Max: 14
46
+
47
+ # Offense count: 15
48
+ Style/Documentation:
49
+ Exclude:
50
+ - 'spec/**/*'
51
+ - 'test/**/*'
52
+ - 'lib/opsview_rest.rb'
53
+ - 'lib/opsview_rest/attribute.rb'
54
+ - 'lib/opsview_rest/contact.rb'
55
+ - 'lib/opsview_rest/host.rb'
56
+ - 'lib/opsview_rest/hostcheckcommand.rb'
57
+ - 'lib/opsview_rest/hostgroup.rb'
58
+ - 'lib/opsview_rest/hosttemplate.rb'
59
+ - 'lib/opsview_rest/keyword.rb'
60
+ - 'lib/opsview_rest/mixin.rb'
61
+ - 'lib/opsview_rest/monitoringserver.rb'
62
+ - 'lib/opsview_rest/notificationmethod.rb'
63
+ - 'lib/opsview_rest/role.rb'
64
+ - 'lib/opsview_rest/servicecheck.rb'
65
+ - 'lib/opsview_rest/servicegroup.rb'
66
+ - 'lib/opsview_rest/timeperiod.rb'
67
+
@@ -1,10 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
3
+ - 2.3.1
5
4
  - ruby-head
6
5
  script: bundle exec rake
7
- matrix:
8
- allow_failures:
9
- - rvm: ruby-head
10
- - rvm: 1.8.7
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in opsview_rest.gemspec
4
4
  gemspec
5
-
6
-
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
 
4
- #encoding: utf-8
4
+ # encoding: utf-8
5
5
  require 'rubygems'
6
6
  require 'bundler'
7
7
  Bundler.setup
@@ -10,13 +10,13 @@ Bundler::GemHelper.install_tasks
10
10
  require 'rspec/core/rake_task'
11
11
  RSpec::Core::RakeTask.new(:spec)
12
12
 
13
- task :default => :spec
13
+ task default: :spec
14
14
 
15
15
  begin
16
16
  require 'yard'
17
17
  YARD::Rake::YardocTask.new
18
18
  rescue LoadError
19
19
  task :yardoc do
20
- abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
20
+ abort 'YARD is not available. In order to run yardoc, you must: sudo gem install yard'
21
21
  end
22
22
  end
@@ -2,26 +2,25 @@ require 'rest-client'
2
2
  require 'json'
3
3
 
4
4
  class OpsviewRest
5
-
6
5
  attr_accessor :url, :username, :password, :rest
7
6
 
8
7
  def initialize(url, options = {})
9
8
  options = {
10
- :username => "api",
11
- :password => "changeme",
12
- :connect => true
9
+ username: 'api',
10
+ password: 'changeme',
11
+ connect: true
13
12
  }.update options
14
13
 
15
14
  @url = url
16
15
  @username = options[:username]
17
16
  @password = options[:password]
18
- @rest = RestClient::Resource.new("#{@url}/rest/", :headers => { :content_type => 'application/json' })
17
+ @rest = RestClient::Resource.new("#{@url}/rest/", headers: { content_type: 'application/json' })
19
18
 
20
19
  login if options[:connect]
21
20
  end
22
21
 
23
22
  def login
24
- response = post('login', { 'username' => @username, 'password' => @password })
23
+ response = post('login', 'username' => @username, 'password' => @password)
25
24
  @rest.headers[:x_opsview_token] = response['token']
26
25
  @rest.headers[:x_opsview_username] = @username
27
26
  response
@@ -73,40 +72,38 @@ class OpsviewRest
73
72
  require 'opsview_rest/timeperiod'
74
73
  OpsviewRest::Timeperiod.new(self, options)
75
74
  else
76
- raise "Type not implemented yet."
75
+ raise 'Type not implemented yet.'
77
76
  end
78
77
  end
79
78
 
80
79
  def list(options = {})
81
80
  options = {
82
- :type => "host",
83
- :rows => "all"
81
+ type: 'host',
82
+ rows: 'all'
84
83
  }.update options
85
84
 
86
85
  get("config/#{options[:type]}?rows=#{options[:rows]}")
87
86
  end
88
87
 
89
88
  def reload
90
- get("reload")
89
+ get('reload')
91
90
  end
92
91
 
93
92
  def initiate_reload
94
- post("reload", {})
93
+ post('reload', {})
95
94
  end
96
95
 
97
96
  def find(options = {})
98
97
  options = {
99
- :type => nil,
100
- :rows => "all",
101
- :searchattribute => nil
98
+ type: nil,
99
+ rows: 'all',
100
+ searchattribute: nil
102
101
  }.update options
103
102
 
104
- if options[:searchattribute].nil?
105
- options[:searchattribute] = "name"
106
- end
107
-
103
+ options[:searchattribute] = 'name' if options[:searchattribute].nil?
104
+
108
105
  if options[:name].nil?
109
- raise ArgumentError, "Need to specify the name of the object."
106
+ raise ArgumentError, 'Need to specify the name of the object.'
110
107
  else
111
108
  get("config/#{options[:type]}?s.#{options[:searchattribute]}=#{options[:name]}&rows=#{options[:rows]}")
112
109
  end
@@ -114,14 +111,14 @@ class OpsviewRest
114
111
 
115
112
  def purge(options = {})
116
113
  options = {
117
- :type => "host",
118
- :name => nil
114
+ type: 'host',
115
+ name: nil
119
116
  }.update options
120
117
 
121
118
  if options[:name].nil?
122
- raise ArgumentError, "Need to specify the name of the object."
119
+ raise ArgumentError, 'Need to specify the name of the object.'
123
120
  else
124
- id = find(:type => options[:type], :name => options[:name])[0]["id"]
121
+ id = find(type: options[:type], name: options[:name])[0]['id']
125
122
  delete("config/#{options[:type]}/#{id}")
126
123
  end
127
124
  end
@@ -142,15 +139,13 @@ class OpsviewRest
142
139
  api_request { @rest[path_part].put(payload.to_json, additional_headers, &block) }
143
140
  end
144
141
 
145
- def api_request(&block)
142
+ def api_request
146
143
  response_body = begin
147
- response = block.call
144
+ response = yield
148
145
  response.body
149
146
  rescue RestClient::Exception => e
150
147
  raise "I have #{e.inspect} with #{e.http_code}"
151
- if e.http_code == 307
152
- get(e.response)
153
- end
148
+ get(e.response) if e.http_code == 307
154
149
  e.response
155
150
  end
156
151
  parse_response(JSON.parse(response_body))
@@ -159,16 +154,16 @@ class OpsviewRest
159
154
  def parse_response(response)
160
155
  # We've got an error if there's "message" and "detail" fields
161
156
  # in the response
162
- if response["message"] and response["detail"]
163
- raise Opsview::Exceptions::RequestFailed, "Request failed: #{response["message"]}, detail: #{response["detail"]}"
157
+ if response['message'] && response['detail']
158
+ raise Opsview::Exceptions::RequestFailed, "Request failed: #{response['message']}, detail: #{response['detail']}"
164
159
  # If we have a token, return that:
165
- elsif response["token"]
160
+ elsif response['token']
166
161
  response
167
162
  # If we have a list of objects, return the list:
168
- elsif response["list"]
169
- response["list"]
163
+ elsif response['list']
164
+ response['list']
170
165
  else
171
- response["object"]
166
+ response['object']
172
167
  end
173
168
  end
174
169
  end
@@ -2,31 +2,29 @@ require 'opsview_rest/mixin'
2
2
 
3
3
  class OpsviewRest
4
4
  class Attribute
5
-
6
5
  include OpsviewRest::Mixin
7
6
 
8
7
  attr_accessor :options, :opsview, :resource_type
9
8
 
10
9
  def initialize(opsview, options = {})
11
10
  @options = {
12
- :name => "PROCESSES",
13
- :arg1 => "",
14
- :arg2 => "",
15
- :arg3 => "",
16
- :arg4 => "",
17
- :value => "",
18
- :servicechecks => [],
19
- :save => true,
20
- :replace => false
11
+ name: 'PROCESSES',
12
+ arg1: '',
13
+ arg2: '',
14
+ arg3: '',
15
+ arg4: '',
16
+ value: '',
17
+ servicechecks: [],
18
+ save: true,
19
+ replace: false
21
20
  }.update options
22
21
 
23
22
  @opsview = opsview
24
23
  @resource_type = @options[:type]
25
24
 
26
- @options[:servicechecks] = @options[:servicechecks].map { |x| { "name" => x } }
25
+ @options[:servicechecks] = @options[:servicechecks].map { |x| { 'name' => x } }
27
26
 
28
27
  save(@options[:replace]) if @options[:save]
29
28
  end
30
-
31
29
  end
32
30
  end
@@ -2,70 +2,68 @@ require 'opsview_rest/mixin'
2
2
 
3
3
  class OpsviewRest
4
4
  class Contact
5
-
6
5
  include OpsviewRest::Mixin
7
6
 
8
7
  attr_accessor :options, :opsview, :resource_type
9
8
 
10
9
  def initialize(opsview, options = {})
11
10
  @options = {
12
- :name => "foobar",
13
- :fullname => "",
14
- :description => "",
15
- :encrypted_password => "$apr1$HTQogYE7$09TNcZWa/WzoBXdUF6Iyr1",
16
- :realm => "local",
17
- :language => "",
18
- :role => "View all, change none",
19
- :variables => [
20
- { :value => "", :name => "EMAIL" },
21
- { :value => 1, :name => "RSS_COLLAPSED" },
22
- { :value => 1440, :name => "RSS_MAXIMUM_AGE" },
23
- { :value => 30, :name => "RSS_MAXIMUM_ITEMS" }
11
+ name: 'foobar',
12
+ fullname: '',
13
+ description: '',
14
+ encrypted_password: '$apr1$HTQogYE7$09TNcZWa/WzoBXdUF6Iyr1',
15
+ realm: 'local',
16
+ language: '',
17
+ role: 'View all, change none',
18
+ variables: [
19
+ { value: '', name: 'EMAIL' },
20
+ { value: 1, name: 'RSS_COLLAPSED' },
21
+ { value: 1440, name: 'RSS_MAXIMUM_AGE' },
22
+ { value: 30, name: 'RSS_MAXIMUM_ITEMS' }
24
23
  ],
25
- :notificationprofiles => [
26
- { :name => "24x7",
27
- :host_notification_options => "u,d,r,f",
28
- :notificationmethods => [
29
- { :name => "Email" }
24
+ notificationprofiles: [
25
+ { name: '24x7',
26
+ host_notification_options: 'u,d,r,f',
27
+ notificationmethods: [
28
+ { name: 'Email' }
30
29
  ],
31
- :servicegroups => [],
32
- :all_servicegroups => 1,
33
- :all_hostgroups => 0,
34
- :keywords => [],
35
- :service_notification_options => "w,c,r,u,f",
36
- :hostgroups => [],
37
- :notification_level => 1,
38
- :notification_period => { :name => "24x7" } },
39
- { :name => "8x5",
40
- :host_notification_options => "u,d,r,f",
41
- :notificationmethods => [
42
- { :name => "Email" }
30
+ servicegroups: [],
31
+ all_servicegroups: 1,
32
+ all_hostgroups: 0,
33
+ keywords: [],
34
+ service_notification_options: 'w,c,r,u,f',
35
+ hostgroups: [],
36
+ notification_level: 1,
37
+ notification_period: { name: '24x7' } },
38
+ { name: '8x5',
39
+ host_notification_options: 'u,d,r,f',
40
+ notificationmethods: [
41
+ { name: 'Email' }
43
42
  ],
44
- :servicegroups => [],
45
- :all_servicegroups => 1,
46
- :all_hostgroups => 0,
47
- :keywords => [],
48
- :service_notification_options => "w,c,r,u,f",
49
- :hostgroups => [],
50
- :notification_level => 1,
51
- :notification_period => { :name => "workhours" } }
43
+ servicegroups: [],
44
+ all_servicegroups: 1,
45
+ all_hostgroups: 0,
46
+ keywords: [],
47
+ service_notification_options: 'w,c,r,u,f',
48
+ hostgroups: [],
49
+ notification_level: 1,
50
+ notification_period: { name: 'workhours' } }
52
51
  ],
53
- :save => true,
54
- :replace => false
52
+ save: true,
53
+ replace: false
55
54
  }.update options
56
55
 
57
56
  @opsview = opsview
58
57
  @resource_type = @options[:type]
59
58
 
60
- @options[:all_servicegroups] = if @options[:all_servicegroups] then 1 else 0 end
61
- @options[:all_hostgroups] = if @options[:all_hostgroups] then 1 else 0 end
62
- @options[:servicegroups] = @options[:servicegroups].map { |x| { "name" => x } } unless @options[:servicegroups].nil?
63
- @options[:keywords] = @options[:keywords].map { |x| { "name" => x } } unless @options[:keywords].nil?
64
- @options[:hostgroups] = @options[:hostgroups].map { |x| { "name" => x } } unless @options[:hostgroups].nil?
65
- @options[:role] = { "name" => @options[:role] }
59
+ @options[:all_servicegroups] = (@options[:all_servicegroups] ? 1 : 0)
60
+ @options[:all_hostgroups] = (@options[:all_hostgroups] ? 1 : 0)
61
+ @options[:servicegroups] = @options[:servicegroups].map { |x| { 'name' => x } } unless @options[:servicegroups].nil?
62
+ @options[:keywords] = @options[:keywords].map { |x| { 'name' => x } } unless @options[:keywords].nil?
63
+ @options[:hostgroups] = @options[:hostgroups].map { |x| { 'name' => x } } unless @options[:hostgroups].nil?
64
+ @options[:role] = { 'name' => @options[:role] }
66
65
 
67
66
  save(@options[:replace]) if @options[:save]
68
67
  end
69
-
70
68
  end
71
69
  end
@@ -2,7 +2,6 @@ require 'opsview_rest/mixin'
2
2
 
3
3
  class OpsviewRest
4
4
  class Host
5
-
6
5
  include OpsviewRest::Mixin
7
6
 
8
7
  attr_accessor :options, :opsview, :resource_type
@@ -10,46 +9,46 @@ class OpsviewRest
10
9
  def initialize(opsview, options = {})
11
10
  # Default set of attributes to send to Opsview:
12
11
  @options = {
13
- :flap_detection_enabled => false,
14
- :snmpv3_privprotocol => nil,
15
- :hosttemplates => [],
16
- :keywords => [],
17
- :check_period => "24x7",
18
- :hostattributes => [],
19
- :notification_period => "24x7",
20
- :name => "unknown",
21
- :rancid_vendor => nil,
22
- :snmp_community => "public",
23
- :hostgroup => "Unknown",
24
- :enable_snmp => false,
25
- :monitored_by => "Master Monitoring Server",
26
- :alias => "Managed Host",
27
- :uncommitted => false,
28
- :parents => [],
29
- :icon => { "name" => "LOGO - Opsview" },
30
- :retry_check_interval => 1,
31
- :ip => "localhost",
32
- :use_mrtg => false,
33
- :servicechecks => [],
34
- :use_rancid => false,
35
- :nmis_node_type => "router",
36
- :snmp_version => "2c",
37
- :snmp_authpassword => "",
38
- :use_nmis => false,
39
- :rancid_connection_type => "ssh",
40
- :snmpv3_authprotocol => nil,
41
- :rancid_username => nil,
42
- :rancid_password => nil,
43
- :check_command => "ping",
44
- :check_attempts => 2,
45
- :check_interval => 0,
46
- :notification_interval => 60,
47
- :snmp_port => 161,
48
- :snmpv3_username => "",
49
- :snmpv3_privpassword => "",
50
- :other_addresses => "",
51
- :save => true,
52
- :replace => false
12
+ flap_detection_enabled: false,
13
+ snmpv3_privprotocol: nil,
14
+ hosttemplates: [],
15
+ keywords: [],
16
+ check_period: '24x7',
17
+ hostattributes: [],
18
+ notification_period: '24x7',
19
+ name: 'unknown',
20
+ rancid_vendor: nil,
21
+ snmp_community: 'public',
22
+ hostgroup: 'Unknown',
23
+ enable_snmp: false,
24
+ monitored_by: 'Master Monitoring Server',
25
+ alias: 'Managed Host',
26
+ uncommitted: false,
27
+ parents: [],
28
+ icon: { 'name' => 'LOGO - Opsview' },
29
+ retry_check_interval: 1,
30
+ ip: 'localhost',
31
+ use_mrtg: false,
32
+ servicechecks: [],
33
+ use_rancid: false,
34
+ nmis_node_type: 'router',
35
+ snmp_version: '2c',
36
+ snmp_authpassword: '',
37
+ use_nmis: false,
38
+ rancid_connection_type: 'ssh',
39
+ snmpv3_authprotocol: nil,
40
+ rancid_username: nil,
41
+ rancid_password: nil,
42
+ check_command: 'ping',
43
+ check_attempts: 2,
44
+ check_interval: 0,
45
+ notification_interval: 60,
46
+ snmp_port: 161,
47
+ snmpv3_username: '',
48
+ snmpv3_privpassword: '',
49
+ other_addresses: '',
50
+ save: true,
51
+ replace: false
53
52
  }.update options
54
53
 
55
54
  @opsview = opsview
@@ -57,21 +56,20 @@ class OpsviewRest
57
56
 
58
57
  # Add any weird exceptions here (like hostgroups having to be mapped
59
58
  # to "name" => hostgroup, etc.):
60
- @options[:flap_detection_enabled] = if @options[:flap_detection_enabled] then 1 else 0 end
61
- @options[:enable_snmp] = if @options[:enable_snmp] then 1 else 0 end
62
- @options[:use_mrtg] = if @options[:use_mrtg] then 1 else 0 end
63
- @options[:use_rancid] = if @options[:use_rancid] then 1 else 0 end
64
- @options[:use_nmis] = if @options[:use_nmis] then 1 else 0 end
65
- @options[:uncommitted] = if @options[:uncommitted] then 1 else 0 end
66
- @options[:check_period] = { "name" => @options[:check_period] }
67
- @options[:hostgroup] = { "name" => @options[:hostgroup] }
68
- @options[:notification_period] = { "name" => @options[:notification_period] }
69
- @options[:monitored_by] = { "name" => @options[:monitored_by] }
70
- @options[:servicechecks] = @options[:servicechecks].map { |x| { "name" => x } }
71
- @options[:check_command] = { "name" => @options[:check_command] }
59
+ @options[:flap_detection_enabled] = (@options[:flap_detection_enabled] ? 1 : 0)
60
+ @options[:enable_snmp] = (@options[:enable_snmp] ? 1 : 0)
61
+ @options[:use_mrtg] = (@options[:use_mrtg] ? 1 : 0)
62
+ @options[:use_rancid] = (@options[:use_rancid] ? 1 : 0)
63
+ @options[:use_nmis] = (@options[:use_nmis] ? 1 : 0)
64
+ @options[:uncommitted] = (@options[:uncommitted] ? 1 : 0)
65
+ @options[:check_period] = { 'name' => @options[:check_period] }
66
+ @options[:hostgroup] = { 'name' => @options[:hostgroup] }
67
+ @options[:notification_period] = { 'name' => @options[:notification_period] }
68
+ @options[:monitored_by] = { 'name' => @options[:monitored_by] }
69
+ @options[:servicechecks] = @options[:servicechecks].map { |x| { 'name' => x } }
70
+ @options[:check_command] = { 'name' => @options[:check_command] }
72
71
 
73
72
  save(@options[:replace]) if @options[:save]
74
73
  end
75
-
76
74
  end
77
75
  end