icinga2 0.6.6.1 → 0.7.0.1

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: 8bd8c5f9e6f260ffd94ce85a0814de8400db08d2
4
- data.tar.gz: 5343c9012ca164d3fbd9a06a107a31d0258f2020
3
+ metadata.gz: c177787de41957958f31e98143b45e04d0215718
4
+ data.tar.gz: ca5ee207818c54b5622a4c8bd82b81331a4345c7
5
5
  SHA512:
6
- metadata.gz: 21b027f3133be7f7eb320371e401202328c1868e0325a8ef0cfd3c5ff0dfcb18e27d2e1e99aadf1466dbb71895601b20598c1c885c3a134e5949ef4a115023bc
7
- data.tar.gz: 2f3fea541b42764e334961d81080ed997ebbacee0bba0f2255607c09f585b079c371bb04e6a8aaff7d203dece7bfe8b2ddb67b2f67b035a178aa55d437de4c93
6
+ metadata.gz: b231ee1147b7d6dbec8f3261dccdb50490f52df3264c3f167907f4f7c56d099ee9d42fd9a34c9085f4b512149f20137d5c464ad360d890b1c3e1565a3a5a495c
7
+ data.tar.gz: 31e1bb01d9c1d1121234700b16fb2ce03d859ae46b61f58f42ca9893ab6cf11e1a352e73c9cfb11f538bc492cea4f62ae4fae58eb039a50301480b73895b39f8
data/examples/test.rb CHANGED
@@ -12,12 +12,15 @@ require_relative '../lib/icinga2'
12
12
 
13
13
  # -----------------------------------------------------------------------------
14
14
 
15
- icinga_host = ENV.fetch( 'ICINGA_HOST' , 'icinga2' )
16
- icinga_api_port = ENV.fetch( 'ICINGA_API_PORT' , 5665 )
17
- icinga_api_user = ENV.fetch( 'ICINGA_API_USER' , 'admin' )
18
- icinga_api_pass = ENV.fetch( 'ICINGA_API_PASSWORD' , nil )
19
- icinga_cluster = ENV.fetch( 'ICINGA_CLUSTER' , false )
20
- icinga_satellite = ENV.fetch( 'ICINGA_CLUSTER_SATELLITE', nil )
15
+ icinga_host = ENV.fetch( 'ICINGA_HOST' , 'icinga2' )
16
+ icinga_api_port = ENV.fetch( 'ICINGA_API_PORT' , 5665 )
17
+ icinga_api_user = ENV.fetch( 'ICINGA_API_USER' , 'admin' )
18
+ icinga_api_pass = ENV.fetch( 'ICINGA_API_PASSWORD' , nil )
19
+ icinga_api_pki_path = ENV.fetch( 'ICINGA_API_PKI_PATH' , '/etc/icinga2' )
20
+ icinga_api_node_name = ENV.fetch( 'ICINGA_API_NODE_NAME' , nil )
21
+ icinga_cluster = ENV.fetch( 'ICINGA_CLUSTER' , false )
22
+ icinga_satellite = ENV.fetch( 'ICINGA_CLUSTER_SATELLITE', nil )
23
+
21
24
 
22
25
  # convert string to bool
23
26
  icinga_cluster = icinga_cluster.to_s.eql?('true') ? true : false
@@ -28,7 +31,9 @@ config = {
28
31
  api: {
29
32
  port: icinga_api_port,
30
33
  user: icinga_api_user,
31
- password: icinga_api_pass
34
+ password: icinga_api_pass,
35
+ pki_path: icinga_api_pki_path,
36
+ node_name: icinga_api_node_name
32
37
  },
33
38
  cluster: icinga_cluster,
34
39
  satellite: icinga_satellite
data/lib/icinga2/hosts.rb CHANGED
@@ -275,7 +275,9 @@ module Icinga2
275
275
 
276
276
  # get the count of problems
277
277
  #
278
- @host_problems.keys[1..max_items].each { |k,_v| @host_problems_severity[k] = @host_problems[k] }
278
+ if( @host_problems.count != 0 )
279
+ @host_problems.keys[1..max_items].each { |k,_v| @host_problems_severity[k] = @host_problems[k] }
280
+ end
279
281
  end
280
282
  @host_problems_severity
281
283
 
@@ -61,11 +61,17 @@ module Icinga2
61
61
  end
62
62
 
63
63
  end
64
+ rescue RestClient::Unauthorized => e
65
+
66
+ result = {
67
+ status: 401,
68
+ name: host,
69
+ message: 'unauthorized'
70
+ }
64
71
 
65
72
  rescue RestClient::ExceptionWithResponse => e
66
73
 
67
74
  error = e.response ? e.response : nil
68
-
69
75
  error = JSON.parse( error )
70
76
 
71
77
  result = {
@@ -86,30 +86,29 @@ module Icinga2
86
86
 
87
87
  return stats if data.nil?
88
88
 
89
- data = data.dig(:data)
89
+ data = data.dig(:data)
90
90
 
91
- a = {
92
- 'json-rpc' => data.dig('ApiListener', 'api', 'json_rpc'),
93
- 'graphite' => data.dig('GraphiteWriter', 'graphitewriter', 'graphite'),
94
- 'ido-mysql' => data.dig('IdoMysqlConnection', 'idomysqlconnection', 'ido-mysql')
95
- }
91
+ json_rpc_data = data.dig('ApiListener', 'api', 'json_rpc')
92
+ graphite_data = data.dig('GraphiteWriter', 'graphitewriter', 'graphite')
93
+ ido_mysql_data = data.dig('IdoMysqlConnection', 'idomysqlconnection', 'ido-mysql')
96
94
 
97
- key_list = %w[work_queue_item_rate query_queue_item_rate]
95
+ a = {}
96
+ a['json_rpc'] = json_rpc_data if(json_rpc_data.is_a?(Hash))
97
+ a['graphite'] = graphite_data if(graphite_data.is_a?(Hash))
98
+ a['ido-mysql'] = ido_mysql_data if(ido_mysql_data.is_a?(Hash))
98
99
 
99
- a.each do |k,v|
100
- if(v.nil?)
101
- next
102
- end
103
- key_list.each do |key|
104
- if( v.include?( key ))
105
- attr_name = format('%s queue rate', k)
106
- stats[attr_name] = v[key].to_f.round(3)
107
- end
100
+ key_list = %w[work_queue_item_rate query_queue_item_rate]
101
+
102
+ a.each do |k,v|
103
+ key_list.each do |key|
104
+ if( v.include?( key ))
105
+ attr_name = format('%s queue rate', k)
106
+ stats[attr_name] = v[key].to_f.round(3)
108
107
  end
109
108
  end
109
+ end
110
110
 
111
- stats
112
-
111
+ stats
113
112
  end
114
113
 
115
114
 
@@ -206,5 +205,6 @@ module Icinga2
206
205
  end
207
206
  end
208
207
  end
208
+
209
209
  end
210
210
  end
@@ -9,9 +9,9 @@ module Icinga2
9
9
  # major part of version
10
10
  MAJOR = 0
11
11
  # minor part of version
12
- MINOR = 6
12
+ MINOR = 7
13
13
  # tiny part of version
14
- TINY = 6
14
+ TINY = 0
15
15
  # patch part
16
16
  PATCH = 1
17
17
 
data/lib/icinga2.rb CHANGED
@@ -109,14 +109,26 @@ module Icinga2
109
109
  @icinga_api_port = settings.dig(:icinga, :api, :port) || 5665
110
110
  @icinga_api_user = settings.dig(:icinga, :api, :user)
111
111
  @icinga_api_pass = settings.dig(:icinga, :api, :password)
112
+ @icinga_api_pki_path = settings.dig(:icinga, :api, :pki_path)
113
+ @icinga_api_node_name = settings.dig(:icinga, :api, :node_name)
114
+
112
115
  @icinga_cluster = settings.dig(:icinga, :cluster) || false
113
116
  @icinga_satellite = settings.dig(:icinga, :satellite)
114
117
  @icinga_notifications = settings.dig(:icinga, :notifications) || false
115
118
 
116
119
  @icinga_api_url_base = format( 'https://%s:%d', @icinga_host, @icinga_api_port )
117
- @node_name = Socket.gethostbyname( Socket.gethostname ).first
118
120
 
119
- @has_cert = cert?( user: @icinga_api_user, password: @icinga_api_pass )
121
+ if( @icinga_api_node_name.nil? )
122
+ @icinga_api_node_name = Socket.gethostbyname( Socket.gethostname ).first
123
+ end
124
+
125
+ @has_cert, @options = cert?(
126
+ pki_path: @icinga_api_pki_path,
127
+ node_name: @icinga_api_node_name,
128
+ user: @icinga_api_user,
129
+ password: @icinga_api_pass
130
+ )
131
+
120
132
  @headers = { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
121
133
 
122
134
 
@@ -141,7 +153,7 @@ module Icinga2
141
153
  # @option params [Integer] :user the Icinga2 API User
142
154
  # @option params [Integer] :password the Icinga2 API Password
143
155
  # @example with Certificate
144
- # @icinga.cert?(name_name: 'icinga2-dashing')
156
+ # @icinga.cert?(pki_path: '/etc/icinga2', name_name: 'icinga2-dashing')
145
157
  #
146
158
  # @example with User
147
159
  # @icinga.cert?(user: 'root', password: 'icinga')
@@ -150,44 +162,46 @@ module Icinga2
150
162
  #
151
163
  def cert?( params = {} )
152
164
 
153
- node_name = params.dig(:node_name) || 'localhost'
165
+ pki_path = params.dig(:pki_path)
166
+ node_name = params.dig(:node_name)
154
167
  user = params.dig(:user)
155
168
  password = params.dig(:password)
156
169
 
157
- # check whether pki files are there, otherwise use basic auth
158
- if File.file?( format( 'pki/%s.crt', node_name ) )
170
+ ssl_cert_file = format( '%s/%s.crt', pki_path, node_name )
171
+ ssl_key_file = format( '%s/%s.key', pki_path, node_name )
172
+ ssl_ca_file = format( '%s/ca.crt', pki_path )
173
+
174
+ if( File.file?( ssl_cert_file ) && File.file?( ssl_key_file ) && File.file?( ssl_ca_file ) )
159
175
 
160
176
  logger.debug( 'PKI found, using client certificates for connection to Icinga 2 API' )
161
177
 
162
- ssl_cert_file = File.read( format( 'pki/%s.crt', node_name ) )
163
- ssl_key_file = File.read( format( 'pki/%s.key', node_name ) )
164
- ssl_ca_file = File.read( 'pki/ca.crt' )
178
+ ssl_cert_file = File.read( ssl_cert_file )
179
+ ssl_key_file = File.read( ssl_key_file )
180
+ ssl_ca_file = File.read( ssl_ca_file )
165
181
 
166
- cert = OpenSSL::X509::Certificate.new( ssl_cert_file )
167
- key = OpenSSL::PKey::RSA.new( ssl_key_file )
182
+ cert = OpenSSL::X509::Certificate.new( ssl_cert_file )
183
+ key = OpenSSL::PKey::RSA.new( ssl_key_file )
168
184
 
169
- @options = {
185
+ [true, {
170
186
  ssl_client_cert: cert,
171
187
  ssl_client_key: key,
172
188
  ssl_ca_file: ssl_ca_file,
173
189
  verify_ssl: OpenSSL::SSL::VERIFY_NONE
174
- }
190
+ } ]
175
191
 
176
- return true
177
192
  else
178
193
 
179
194
  logger.debug( 'PKI not found, using basic auth for connection to Icinga 2 API' )
180
195
 
181
- @options = {
196
+ [false, {
182
197
  user: user,
183
198
  password: password,
184
199
  verify_ssl: OpenSSL::SSL::VERIFY_NONE
185
- }
186
-
187
- return false
200
+ } ]
188
201
  end
189
202
 
190
203
  end
191
204
 
192
205
  end
193
206
  end
207
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icinga2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6.1
4
+ version: 0.7.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bodo Schulz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-10 00:00:00.000000000 Z
11
+ date: 2017-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client