icinga2 0.8.1.2 → 0.9.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -7
- data/doc/Array.html +202 -0
- data/doc/Boolean.html +124 -0
- data/doc/FalseClass.html +134 -0
- data/doc/Hash.html +214 -0
- data/doc/Icinga2.html +10 -8
- data/doc/Logging.html +10 -8
- data/doc/Object.html +288 -0
- data/doc/Time.html +202 -0
- data/doc/TrueClass.html +134 -0
- data/doc/_index.html +77 -23
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +75 -58
- data/doc/frames.html +1 -1
- data/doc/index.html +75 -58
- data/doc/method_list.html +126 -54
- data/doc/services.md +34 -16
- data/doc/top-level-namespace.html +9 -5
- data/examples/test.rb +75 -14
- data/lib/icinga2.rb +16 -1
- data/lib/icinga2/network.rb +8 -6
- data/lib/icinga2/services.rb +243 -65
- data/lib/icinga2/version.rb +3 -3
- metadata +10 -3
data/doc/services.md
CHANGED
@@ -4,17 +4,27 @@
|
|
4
4
|
## <a name="add-service"></a>add services
|
5
5
|
add_services( params )
|
6
6
|
|
7
|
-
**this function is not operable! need help, time and/or beer**
|
8
|
-
|
9
7
|
### Example
|
10
8
|
services = {
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
vars: {
|
10
|
+
display_name: 'Tomcat - Heap Memory',
|
11
|
+
check_command: 'tomcat-heap-memory'
|
14
12
|
}
|
15
13
|
}
|
16
14
|
|
17
|
-
@icinga.add_services( '
|
15
|
+
@icinga.add_services( host: 'icinga2', service_name: 'ping4', vars: services )
|
16
|
+
|
17
|
+
@icinga.add_services(
|
18
|
+
host: 'icinga2',
|
19
|
+
service_name: 'ping4',
|
20
|
+
vars: {
|
21
|
+
attrs: {
|
22
|
+
check_command: 'ping4',
|
23
|
+
check_interval: 10,
|
24
|
+
retry_interval: 30
|
25
|
+
}
|
26
|
+
}
|
27
|
+
)
|
18
28
|
|
19
29
|
|
20
30
|
## <a name="list-services"></a>list services
|
@@ -33,12 +43,19 @@
|
|
33
43
|
|
34
44
|
|
35
45
|
## <a name="delete-service"></a>delete
|
36
|
-
|
46
|
+
delete_service( params )
|
37
47
|
|
38
|
-
|
39
|
-
|
48
|
+
#### Example
|
49
|
+
@icinga.delete_service(host: 'foo', service_name: 'ping4')
|
50
|
+
|
51
|
+
@icinga.delete_service(host: 'foo', service_name: 'new_ping4', cascade: true)
|
40
52
|
|
41
53
|
|
54
|
+
## <a name="unhandled-services"></a>list unhandled_services
|
55
|
+
unhandled_services
|
56
|
+
|
57
|
+
#### Example
|
58
|
+
@icinga.unhandled_services
|
42
59
|
|
43
60
|
|
44
61
|
## <a name="service-exists"></a>check if the service exists
|
@@ -84,13 +101,6 @@ or
|
|
84
101
|
problems, problems_and_severity = @icinga.list_services_with_problems(10).values
|
85
102
|
|
86
103
|
|
87
|
-
## <a name="update-host"></a>update host
|
88
|
-
update_host( hash, host )
|
89
|
-
**this function is not operable! need help, time and/or beer**
|
90
|
-
|
91
|
-
### Example
|
92
|
-
|
93
|
-
|
94
104
|
## <a name="count-all-services"></a>count all services
|
95
105
|
services_all
|
96
106
|
|
@@ -117,3 +127,11 @@ or
|
|
117
127
|
|
118
128
|
### Example
|
119
129
|
service_severity( {'attrs' => { 'state' => 0.0, 'acknowledgement' => 0.0, 'downtime_depth' => 0.0 } } )
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
## <a name=""></a>(private) update host
|
134
|
+
update_host( hash, host )
|
135
|
+
|
136
|
+
### Example
|
137
|
+
update_host( v, host_name )
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Top Level Namespace
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.4
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -28,7 +28,7 @@
|
|
28
28
|
</head>
|
29
29
|
<body>
|
30
30
|
<div class="nav_wrap">
|
31
|
-
<iframe id="nav" src="class_list.html
|
31
|
+
<iframe id="nav" src="class_list.html"></iframe>
|
32
32
|
<div id="resizer"></div>
|
33
33
|
</div>
|
34
34
|
|
@@ -59,6 +59,8 @@
|
|
59
59
|
<div class="clear"></div>
|
60
60
|
</div>
|
61
61
|
|
62
|
+
<iframe id="search_frame" src="class_list.html"></iframe>
|
63
|
+
|
62
64
|
<div id="content"><h1>Top Level Namespace
|
63
65
|
|
64
66
|
|
@@ -82,10 +84,12 @@
|
|
82
84
|
<p class="children">
|
83
85
|
|
84
86
|
|
85
|
-
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Icinga2.html" title="Icinga2 (module)">Icinga2</a></span>, <span class='object_link'><a href="Logging.html" title="Logging (module)">Logging</a></span>
|
87
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Boolean.html" title="Boolean (module)">Boolean</a></span>, <span class='object_link'><a href="Icinga2.html" title="Icinga2 (module)">Icinga2</a></span>, <span class='object_link'><a href="Logging.html" title="Logging (module)">Logging</a></span>
|
86
88
|
|
87
89
|
|
88
90
|
|
91
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Array.html" title="Array (class)">Array</a></span>, <span class='object_link'><a href="FalseClass.html" title="FalseClass (class)">FalseClass</a></span>, <span class='object_link'><a href="Hash.html" title="Hash (class)">Hash</a></span>, <span class='object_link'><a href="Object.html" title="Object (class)">Object</a></span>, <span class='object_link'><a href="Time.html" title="Time (class)">Time</a></span>, <span class='object_link'><a href="TrueClass.html" title="TrueClass (class)">TrueClass</a></span>
|
92
|
+
|
89
93
|
|
90
94
|
</p>
|
91
95
|
|
@@ -100,9 +104,9 @@
|
|
100
104
|
</div>
|
101
105
|
|
102
106
|
<div id="footer">
|
103
|
-
Generated on
|
107
|
+
Generated on Sun Nov 12 15:48:13 2017 by
|
104
108
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
105
|
-
0.9.
|
109
|
+
0.9.4 (ruby-2.2.8).
|
106
110
|
</div>
|
107
111
|
|
108
112
|
</div>
|
data/examples/test.rb
CHANGED
@@ -52,6 +52,9 @@ unless( i.nil? )
|
|
52
52
|
|
53
53
|
puts ''
|
54
54
|
puts ' ============================================================= '
|
55
|
+
puts '= icinga2 available'
|
56
|
+
puts i.available?
|
57
|
+
puts ''
|
55
58
|
puts '= icinga2 status'
|
56
59
|
puts i.status_data
|
57
60
|
puts ''
|
@@ -74,6 +77,7 @@ unless( i.nil? )
|
|
74
77
|
puts format( '= uptime: %s', i.uptime )
|
75
78
|
puts ''
|
76
79
|
|
80
|
+
puts ''
|
77
81
|
puts ' ------------------------------------------------------------- '
|
78
82
|
puts ''
|
79
83
|
puts ' ==> HOSTS'
|
@@ -84,15 +88,18 @@ unless( i.nil? )
|
|
84
88
|
|
85
89
|
p, a = i.hosts_adjusted
|
86
90
|
|
87
|
-
puts format( '= host handled problems : %
|
88
|
-
puts format( '= host down adjusted : %
|
91
|
+
puts format( '= host handled problems : %s', p )
|
92
|
+
puts format( '= host down adjusted : %s', a )
|
89
93
|
|
90
94
|
puts '= host objects'
|
95
|
+
|
96
|
+
all, down, critical, unknown = i.host_problems.values
|
97
|
+
|
91
98
|
puts format( '= count of all hosts : %d', i.hosts_all )
|
92
|
-
puts format( '= hosts with problems: %
|
93
|
-
puts format( '= hosts are down : %d',
|
94
|
-
puts format( '= hosts are critical : %d',
|
95
|
-
puts format( '= hosts are unknown : %d',
|
99
|
+
puts format( '= hosts with problems: %s', i.list_hosts_with_problems )
|
100
|
+
puts format( '= hosts are down : %d', down )
|
101
|
+
puts format( '= hosts are critical : %d', critical )
|
102
|
+
puts format( '= hosts are unknown : %d', unknown )
|
96
103
|
puts format( '= count hosts w. problems: %d', i.count_hosts_with_problems )
|
97
104
|
|
98
105
|
['icinga2', 'bp-foo'].each do |h|
|
@@ -113,8 +120,10 @@ unless( i.nil? )
|
|
113
120
|
puts ''
|
114
121
|
puts '= list all Hosts'
|
115
122
|
puts i.hosts
|
123
|
+
puts ''
|
116
124
|
puts ' = delete Host'
|
117
125
|
puts i.delete_host( host: 'foo' )
|
126
|
+
puts ''
|
118
127
|
puts ' = add Host'
|
119
128
|
puts i.add_host(
|
120
129
|
host: 'foo',
|
@@ -156,22 +165,28 @@ unless( i.nil? )
|
|
156
165
|
puts ''
|
157
166
|
puts ' ==> SERVICES'
|
158
167
|
puts ''
|
168
|
+
i.cib_data
|
159
169
|
i.service_objects
|
160
170
|
|
161
|
-
warning, critical, unknown = i.
|
162
|
-
|
171
|
+
all, warning, critical, unknown, pending, in_downtime, acknowledged = i.service_problems.values
|
163
172
|
puts format( '= count of all services: %d', i.services_all )
|
164
|
-
puts format( '= services
|
165
|
-
puts format( '= services
|
166
|
-
puts format( '= services unknown: %d',
|
173
|
+
puts format( '= services warning: %d', warning)
|
174
|
+
puts format( '= services critical: %d', critical)
|
175
|
+
puts format( '= services unknown: %d', unknown)
|
176
|
+
puts format( '= services in downtime: %d', in_downtime)
|
177
|
+
puts format( '= services acknowledged: %d', acknowledged)
|
178
|
+
|
167
179
|
puts ''
|
168
|
-
|
169
|
-
puts format( '= services handled
|
170
|
-
puts format( '= services handled
|
180
|
+
all, warning, critical, unknown = i.service_problems_handled.values
|
181
|
+
puts format( '= services handled warning problems: %d', warning)
|
182
|
+
puts format( '= services handled critical problems: %d', critical)
|
183
|
+
puts format( '= services handled unknown problems: %d', unknown)
|
171
184
|
puts ''
|
185
|
+
warning, critical, unknown = i.services_adjusted.values
|
172
186
|
puts format( '= services adjusted warning: %d', warning)
|
173
187
|
puts format( '= services adjusted critical: %d', critical)
|
174
188
|
puts format( '= services adjusted unknown: %d', unknown)
|
189
|
+
|
175
190
|
puts ''
|
176
191
|
puts '= check if service \'users\' on host \'icinga2\' exists'
|
177
192
|
puts i.exists_service?( host: 'icinga2', service: 'users' ) ? 'true' : 'false'
|
@@ -195,6 +210,52 @@ unless( i.nil? )
|
|
195
210
|
puts '= list all Services'
|
196
211
|
puts i.services
|
197
212
|
puts ''
|
213
|
+
puts '= add Service'
|
214
|
+
puts i.add_services(
|
215
|
+
host: 'icinga2',
|
216
|
+
service_name: 'new_http',
|
217
|
+
vars: {
|
218
|
+
attrs: {
|
219
|
+
check_command: 'http',
|
220
|
+
check_interval: 10,
|
221
|
+
retry_interval: 30,
|
222
|
+
vars: {
|
223
|
+
http_address: '127.0.0.1',
|
224
|
+
http_url: '/access/index',
|
225
|
+
http_port: 80
|
226
|
+
}
|
227
|
+
}
|
228
|
+
}
|
229
|
+
)
|
230
|
+
puts ''
|
231
|
+
puts '= list new named Service \'new_http\' from Host \'icinga2\''
|
232
|
+
puts i.services( host: 'icinga2', service: 'new_http' )
|
233
|
+
puts ''
|
234
|
+
puts '= modify named Service \'new_http\' from Host \'icinga2\''
|
235
|
+
puts JSON.pretty_generate i.modify_service(
|
236
|
+
service_name: 'new_http',
|
237
|
+
vars: {
|
238
|
+
attrs: {
|
239
|
+
check_interval: 60,
|
240
|
+
retry_interval: 10,
|
241
|
+
vars: {
|
242
|
+
http_url: '/access/login' ,
|
243
|
+
http_address: '10.41.80.63'
|
244
|
+
}
|
245
|
+
}
|
246
|
+
}
|
247
|
+
)
|
248
|
+
puts ''
|
249
|
+
puts '= list modified named Service \'new_http\' from Host \'icinga2\''
|
250
|
+
puts JSON.pretty_generate i.services( host: 'icinga2', service: 'new_http' )
|
251
|
+
puts ''
|
252
|
+
puts '= delete named Service \'new_http\' from Host \'icinga2\''
|
253
|
+
puts i.delete_service(
|
254
|
+
host: 'icinga2',
|
255
|
+
service_name: 'new_http',
|
256
|
+
cascade: true
|
257
|
+
)
|
258
|
+
puts ''
|
198
259
|
puts ' ------------------------------------------------------------- '
|
199
260
|
puts ''
|
200
261
|
|
data/lib/icinga2.rb
CHANGED
@@ -202,7 +202,6 @@ module Icinga2
|
|
202
202
|
|
203
203
|
end
|
204
204
|
|
205
|
-
|
206
205
|
# return Icinga2 Application data
|
207
206
|
#
|
208
207
|
# @example
|
@@ -322,6 +321,22 @@ module Icinga2
|
|
322
321
|
)
|
323
322
|
end
|
324
323
|
|
324
|
+
# check the availability of a Icinga network connect
|
325
|
+
#
|
326
|
+
# @example
|
327
|
+
# @icinga.available?
|
328
|
+
#
|
329
|
+
# @return [Bool]
|
330
|
+
#
|
331
|
+
def available?
|
332
|
+
|
333
|
+
data = application_data
|
334
|
+
|
335
|
+
return true unless( data.nil? )
|
336
|
+
|
337
|
+
false
|
338
|
+
end
|
339
|
+
|
325
340
|
# return Icinga2 version and revision
|
326
341
|
#
|
327
342
|
# @example
|
data/lib/icinga2/network.rb
CHANGED
@@ -165,6 +165,7 @@ module Icinga2
|
|
165
165
|
)
|
166
166
|
|
167
167
|
data = JSON.parse( data )
|
168
|
+
|
168
169
|
results = data.dig('results').first
|
169
170
|
|
170
171
|
return { status: results.dig('code').to_i, name: results.dig('name'), message: results.dig('status') } unless( results.nil? )
|
@@ -177,9 +178,6 @@ module Icinga2
|
|
177
178
|
results = error.dig( 'results' )
|
178
179
|
|
179
180
|
if( !results.nil? )
|
180
|
-
|
181
|
-
# result = result.first
|
182
|
-
|
183
181
|
return {
|
184
182
|
status: results.dig('code').to_i,
|
185
183
|
name: results.dig('name'),
|
@@ -261,7 +259,7 @@ module Icinga2
|
|
261
259
|
data = JSON.parse( data )
|
262
260
|
results = data.dig('results').first
|
263
261
|
|
264
|
-
return { status: results.dig('code').to_i,
|
262
|
+
return { status: results.dig('code').to_i, message: results.dig('status') } unless( results.nil? )
|
265
263
|
|
266
264
|
rescue RestClient::ExceptionWithResponse => e
|
267
265
|
|
@@ -273,7 +271,7 @@ module Icinga2
|
|
273
271
|
return { status: error.dig('error').to_i, message: error.dig('status'), error: results } if( results.nil? )
|
274
272
|
|
275
273
|
if( results.is_a?( Hash ) && results.count != 0 )
|
276
|
-
|
274
|
+
|
277
275
|
return {
|
278
276
|
status: results.dig('code').to_i,
|
279
277
|
name: results.dig('name'),
|
@@ -370,10 +368,14 @@ module Icinga2
|
|
370
368
|
message: error.dig( 'status' )
|
371
369
|
}
|
372
370
|
else
|
371
|
+
|
372
|
+
results = results.first if( results.is_a?(Array) )
|
373
|
+
|
373
374
|
return {
|
374
375
|
status: results.dig('code').to_i,
|
375
376
|
name: results.dig('name'),
|
376
|
-
message: results.dig('status')
|
377
|
+
message: results.dig('status'),
|
378
|
+
error: results.dig('errors')
|
377
379
|
}
|
378
380
|
end
|
379
381
|
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH => e
|
data/lib/icinga2/services.rb
CHANGED
@@ -10,69 +10,204 @@ module Icinga2
|
|
10
10
|
#
|
11
11
|
# @param [Hash] params
|
12
12
|
# @option params [String] :host
|
13
|
-
# @option params [String] :
|
13
|
+
# @option params [String] :service_name
|
14
|
+
# @option params [Array] :templates
|
15
|
+
# @option params [Hash] :vars
|
14
16
|
#
|
15
|
-
# @
|
16
|
-
#
|
17
|
-
#
|
17
|
+
# @example
|
18
|
+
# @icinga.add_services(
|
19
|
+
# host: 'icinga2',
|
20
|
+
# service_name: 'http2',
|
21
|
+
# vars: {
|
22
|
+
# attrs: {
|
23
|
+
# check_command: 'http',
|
24
|
+
# check_interval: 10,
|
25
|
+
# retry_interval: 30,
|
26
|
+
# vars: {
|
27
|
+
# http_address: '127.0.0.1',
|
28
|
+
# http_url: '/access/index',
|
29
|
+
# http_port: 80
|
30
|
+
# }
|
31
|
+
# }
|
32
|
+
# }
|
33
|
+
# )
|
18
34
|
#
|
19
35
|
# @return [Hash]
|
36
|
+
# * status
|
37
|
+
# * message
|
20
38
|
#
|
21
39
|
def add_services( params = {} )
|
22
40
|
|
23
41
|
raise ArgumentError.new('only Hash are allowed') unless( params.is_a?(Hash) )
|
24
42
|
|
25
|
-
|
26
|
-
|
43
|
+
host_name = params.dig(:host)
|
44
|
+
service_name = params.dig(:service_name)
|
45
|
+
templates = params.dig(:templates) || ['generic-service']
|
46
|
+
vars = params.dig(:vars)
|
27
47
|
|
28
|
-
|
29
|
-
|
48
|
+
raise ArgumentError.new('Missing host') if( host_name.nil? )
|
49
|
+
raise ArgumentError.new('Missing service_name') if( service_name.nil? )
|
50
|
+
raise ArgumentError.new('only Array for templates are allowed') unless( templates.is_a?(Array) )
|
51
|
+
raise ArgumentError.new('Missing vars') if( vars.nil? )
|
52
|
+
raise ArgumentError.new('only Hash for vars are allowed') unless( vars.is_a?(Hash) )
|
53
|
+
|
54
|
+
# validate
|
55
|
+
# needed_values = %w[check_command check_interval retry_interval]
|
30
56
|
|
31
|
-
|
57
|
+
attrs = vars.dig(:attrs)
|
58
|
+
|
59
|
+
validate_check_command = attrs.select { |k,_v| k == 'check_command'.to_sym }.size
|
60
|
+
validate_check_interval = attrs.select { |k,_v| k == 'check_interval'.to_sym }.size
|
61
|
+
validate_retry_interval = attrs.select { |k,_v| k == 'retry_interval'.to_sym }.size
|
62
|
+
|
63
|
+
raise 'Error in attrs, expected \'check_command\' but was not found' if( validate_check_command.zero? )
|
64
|
+
raise 'Error in attrs, expected \'check_interval\' but was not found' if( validate_check_interval.zero? )
|
65
|
+
raise 'Error in attrs, expected \'retry_interval\' but was not found' if( validate_retry_interval.zero? )
|
66
|
+
|
67
|
+
payload = ''
|
68
|
+
|
69
|
+
vars.each do |_s,v|
|
32
70
|
|
33
71
|
payload = {
|
34
|
-
'templates' =>
|
72
|
+
'templates' => templates,
|
35
73
|
'attrs' => update_host( v, host_name )
|
36
74
|
}
|
75
|
+
end
|
76
|
+
|
77
|
+
Network.put(
|
78
|
+
url: format( '%s/objects/services/%s!%s', @icinga_api_url_base, host_name, service_name ),
|
79
|
+
headers: @headers,
|
80
|
+
options: @options,
|
81
|
+
payload: payload
|
82
|
+
)
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
# delete a service
|
87
|
+
#
|
88
|
+
# @param [Hash] params
|
89
|
+
# @option params [String] :host host name for the service
|
90
|
+
# @option params [String] :service_name
|
91
|
+
# @option params [Bool] :cascade (false) delete service also when other objects depend on it
|
92
|
+
#
|
93
|
+
# @example
|
94
|
+
# @icinga.delete_service(host: 'foo', service_name: 'http2')
|
95
|
+
# @icinga.delete_service(host: 'foo', service_name: 'http2', cascade: true)
|
96
|
+
#
|
97
|
+
# @return [Hash] result
|
98
|
+
#
|
99
|
+
def delete_service( params )
|
100
|
+
|
101
|
+
raise ArgumentError.new('only Hash are allowed') unless( params.is_a?(Hash) )
|
102
|
+
raise ArgumentError.new('missing params') if( params.size.zero? )
|
37
103
|
|
38
|
-
|
39
|
-
|
104
|
+
host_name = params.dig(:host)
|
105
|
+
service_name = params.dig(:service_name)
|
106
|
+
cascade = params.dig(:cascade)
|
40
107
|
|
41
|
-
|
108
|
+
raise ArgumentError.new('Missing host') if( host_name.nil? )
|
109
|
+
raise ArgumentError.new('Missing service_name') if( service_name.nil? )
|
42
110
|
|
43
|
-
|
44
|
-
|
45
|
-
headers: @headers,
|
46
|
-
options: @options,
|
47
|
-
payload: payload
|
48
|
-
)
|
111
|
+
if( ! cascade.nil? && ( ! cascade.is_a?(TrueClass) && ! cascade.is_a?(FalseClass) ) )
|
112
|
+
raise ArgumentError.new('cascade can only be true or false')
|
49
113
|
end
|
50
114
|
|
115
|
+
url = format( '%s/objects/services/%s!%s%s', @icinga_api_url_base, host_name, service_name, cascade.is_a?(TrueClass) ? '?cascade=1' : nil )
|
116
|
+
|
117
|
+
Network.delete(
|
118
|
+
url: url,
|
119
|
+
headers: @headers,
|
120
|
+
options: @options
|
121
|
+
)
|
122
|
+
|
51
123
|
end
|
52
124
|
|
53
|
-
#
|
125
|
+
# modify an service
|
54
126
|
#
|
55
127
|
# @param [Hash] params
|
128
|
+
# @option params [String] :service_name
|
129
|
+
# @option params [Hash] :vars
|
56
130
|
#
|
57
|
-
# @
|
58
|
-
#
|
59
|
-
#
|
131
|
+
# @example
|
132
|
+
# @icinga.modify_service(
|
133
|
+
# service_name: 'http2',
|
134
|
+
# vars: {
|
135
|
+
# attrs: {
|
136
|
+
# check_interval: 60,
|
137
|
+
# retry_interval: 10,
|
138
|
+
# vars: {
|
139
|
+
# http_url: '/access/login' ,
|
140
|
+
# http_address: '10.41.80.63'
|
141
|
+
# }
|
142
|
+
# }
|
143
|
+
# }
|
144
|
+
# )
|
60
145
|
#
|
61
|
-
# @return [
|
146
|
+
# @return [Hash]
|
147
|
+
# * status
|
148
|
+
# * message
|
62
149
|
#
|
63
|
-
def
|
150
|
+
def modify_service( params )
|
64
151
|
|
65
152
|
raise ArgumentError.new('only Hash are allowed') unless( params.is_a?(Hash) )
|
153
|
+
raise ArgumentError.new('missing params') if( params.size.zero? )
|
66
154
|
|
67
|
-
|
68
|
-
|
155
|
+
templates = params.dig(:templates) || ['generic-service']
|
156
|
+
vars = params.dig(:vars)
|
157
|
+
service_name = params.dig(:service_name)
|
69
158
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
# -d '{ "attrs": [ "__name", "state", "downtime_depth", "acknowledgement" ], "filter": "service.state != ServiceOK && service.downtime_depth == 0.0 && service.acknowledgement == 0.0" }''' | jq
|
159
|
+
raise ArgumentError.new('Missing service_name') if( service_name.nil? )
|
160
|
+
raise ArgumentError.new('only Array for templates are allowed') unless( templates.is_a?(Array) )
|
161
|
+
raise ArgumentError.new('Missing vars') if( vars.nil? )
|
162
|
+
raise ArgumentError.new('only Hash for vars are allowed') unless( vars.is_a?(Hash) )
|
75
163
|
|
164
|
+
payload = {}
|
165
|
+
|
166
|
+
vars.each do |_s,v|
|
167
|
+
|
168
|
+
payload = {
|
169
|
+
'templates' => templates,
|
170
|
+
'attrs' => v
|
171
|
+
}
|
172
|
+
end
|
173
|
+
|
174
|
+
payload['filter'] = format( 'service.name=="%s"', service_name )
|
175
|
+
|
176
|
+
Network.post(
|
177
|
+
url: format( '%s/objects/services', @icinga_api_url_base ),
|
178
|
+
headers: @headers,
|
179
|
+
options: @options,
|
180
|
+
payload: payload
|
181
|
+
)
|
182
|
+
end
|
183
|
+
|
184
|
+
# return all unhandled services
|
185
|
+
#
|
186
|
+
# @example
|
187
|
+
# @icinga.unhandled_services
|
188
|
+
#
|
189
|
+
# @return [Hash]
|
190
|
+
#
|
191
|
+
def unhandled_services
|
192
|
+
|
193
|
+
payload = {}
|
194
|
+
|
195
|
+
filter = 'service.state != ServiceOK && service.downtime_depth == 0.0 && service.acknowledgement == 0.0'
|
196
|
+
attrs = %w[__name name state acknowledgement downtime_depth last_check]
|
197
|
+
|
198
|
+
payload['attrs'] = attrs unless attrs.nil?
|
199
|
+
payload['filter'] = filter unless filter.nil?
|
200
|
+
|
201
|
+
data = Network.api_data(
|
202
|
+
url: format( '%s/objects/services', @icinga_api_url_base ),
|
203
|
+
headers: @headers,
|
204
|
+
options: @options,
|
205
|
+
payload: payload
|
206
|
+
)
|
207
|
+
|
208
|
+
status = data.dig(:status)
|
209
|
+
|
210
|
+
data.dig('results') if( status.nil? )
|
76
211
|
end
|
77
212
|
|
78
213
|
# return services
|
@@ -121,7 +256,7 @@ module Icinga2
|
|
121
256
|
# @option params [String] :service
|
122
257
|
#
|
123
258
|
# @example
|
124
|
-
# @icinga.exists_service?(host: 'icinga2', service: 'users'
|
259
|
+
# @icinga.exists_service?(host: 'icinga2', service: 'users')
|
125
260
|
#
|
126
261
|
# @return [Bool]
|
127
262
|
#
|
@@ -308,36 +443,6 @@ module Icinga2
|
|
308
443
|
}
|
309
444
|
end
|
310
445
|
|
311
|
-
# update host
|
312
|
-
#
|
313
|
-
# @param [Hash] hash
|
314
|
-
# @param [String] host
|
315
|
-
#
|
316
|
-
# @todo
|
317
|
-
# this function are not operable
|
318
|
-
# need help, time or beer
|
319
|
-
#
|
320
|
-
# @return [Hash]
|
321
|
-
#
|
322
|
-
def update_host( hash, host )
|
323
|
-
|
324
|
-
hash.each do |k, v|
|
325
|
-
|
326
|
-
if( k == 'host' && v.is_a?( String ) )
|
327
|
-
v.replace( host )
|
328
|
-
|
329
|
-
elsif( v.is_a?( Hash ) )
|
330
|
-
update_host( v, host )
|
331
|
-
|
332
|
-
elsif( v.is_a?(Array) )
|
333
|
-
|
334
|
-
v.flatten.each { |x| update_host( x, host ) if x.is_a?( Hash ) }
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
hash
|
339
|
-
end
|
340
|
-
|
341
446
|
# returns a counter of all services
|
342
447
|
#
|
343
448
|
# @example
|
@@ -351,12 +456,51 @@ module Icinga2
|
|
351
456
|
@services_all
|
352
457
|
end
|
353
458
|
|
459
|
+
# returns data with service problems
|
460
|
+
#
|
461
|
+
# @example
|
462
|
+
# @icinga.cib_data
|
463
|
+
# all, warning, critical, unknown, pending, in_downtime, acknowledged = @icinga.service_problems.values
|
464
|
+
#
|
465
|
+
# p = @icinga.service_problems
|
466
|
+
# warning = p.dig(:warning)
|
467
|
+
#
|
468
|
+
# @return [Hash]
|
469
|
+
# * ok
|
470
|
+
# * warning
|
471
|
+
# * critical
|
472
|
+
# * unknown
|
473
|
+
# * pending
|
474
|
+
# * in_downtime
|
475
|
+
# * acknowledged
|
476
|
+
#
|
477
|
+
def service_problems
|
478
|
+
|
479
|
+
services_ok = @services_ok.nil? ? 0 : @services_ok
|
480
|
+
services_warning = @services_warning.nil? ? 0 : @services_warning
|
481
|
+
services_critical = @services_critical.nil? ? 0 : @services_critical
|
482
|
+
services_unknown = @services_unknown.nil? ? 0 : @services_unknown
|
483
|
+
services_pending = @services_pending.nil? ? 0 : @services_pending
|
484
|
+
services_in_downtime = @services_in_downtime.nil? ? 0 : @services_in_downtime
|
485
|
+
services_acknowledged = @services_acknowledged.nil? ? 0 : @services_acknowledged
|
486
|
+
|
487
|
+
{
|
488
|
+
ok: services_ok.to_i,
|
489
|
+
warning: services_critical.to_i,
|
490
|
+
critical: services_warning.to_i,
|
491
|
+
unknown: services_unknown.to_i,
|
492
|
+
pending: services_pending.to_i,
|
493
|
+
in_downtime: services_in_downtime.to_i,
|
494
|
+
acknowledged: services_acknowledged.to_i
|
495
|
+
}
|
496
|
+
end
|
497
|
+
|
354
498
|
# returns data with service problems they be handled (acknowledged or in downtime)
|
355
499
|
#
|
356
500
|
# @example
|
357
501
|
# @icinga.cib_data
|
358
502
|
# @icinga.service_objects
|
359
|
-
# all,
|
503
|
+
# all, warning, critical, unknown = @icinga.service_problems_handled.values
|
360
504
|
#
|
361
505
|
# p = @icinga.service_problems_handled
|
362
506
|
# warning = p.dig(:warning)
|
@@ -376,8 +520,8 @@ module Icinga2
|
|
376
520
|
|
377
521
|
{
|
378
522
|
all: problems_all.to_i,
|
379
|
-
critical: problems_critical.to_i,
|
380
523
|
warning: problems_warning.to_i,
|
524
|
+
critical: problems_critical.to_i,
|
381
525
|
unknown: problems_unknown.to_i
|
382
526
|
}
|
383
527
|
|
@@ -462,5 +606,39 @@ module Icinga2
|
|
462
606
|
severity
|
463
607
|
end
|
464
608
|
|
609
|
+
private
|
610
|
+
# update host
|
611
|
+
#
|
612
|
+
# @param [Hash] hash
|
613
|
+
# @param [String] host
|
614
|
+
#
|
615
|
+
# @todo
|
616
|
+
# this function are not operable
|
617
|
+
# need help, time or beer
|
618
|
+
#
|
619
|
+
# @api protected
|
620
|
+
#
|
621
|
+
# @return [Hash]
|
622
|
+
#
|
623
|
+
def update_host( hash, host )
|
624
|
+
|
625
|
+
hash.each do |k, v|
|
626
|
+
|
627
|
+
if( k == 'host' && v.is_a?( String ) )
|
628
|
+
v.replace( host )
|
629
|
+
|
630
|
+
elsif( v.is_a?( Hash ) )
|
631
|
+
|
632
|
+
update_host( v, host )
|
633
|
+
|
634
|
+
elsif( v.is_a?(Array) )
|
635
|
+
|
636
|
+
v.flatten.each { |x| update_host( x, host ) if x.is_a?( Hash ) }
|
637
|
+
end
|
638
|
+
end
|
639
|
+
|
640
|
+
hash
|
641
|
+
end
|
642
|
+
|
465
643
|
end
|
466
644
|
end
|