icinga2 0.9.2.8 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -9
- data/doc/downtimes.md +39 -0
- data/lib/icinga2/actions.rb +152 -0
- data/lib/icinga2/client.rb +29 -22
- data/lib/icinga2/configuration_management.rb +312 -0
- data/lib/icinga2/downtimes.rb +72 -4
- data/lib/icinga2/hostgroups.rb +6 -6
- data/lib/icinga2/hosts.rb +23 -23
- data/lib/icinga2/network.rb +115 -10
- data/lib/icinga2/notifications.rb +17 -9
- data/lib/icinga2/servicegroups.rb +5 -5
- data/lib/icinga2/services.rb +32 -30
- data/lib/icinga2/statistics.rb +17 -14
- data/lib/icinga2/tools.rb +31 -10
- data/lib/icinga2/usergroups.rb +5 -5
- data/lib/icinga2/users.rb +5 -5
- data/lib/icinga2/validator.rb +40 -34
- data/lib/icinga2/version.rb +1 -3
- data/lib/monkey_patches.rb +67 -14
- data/spec/icinga2_spec.rb +1013 -0
- data/spec/spec_helper.rb +13 -0
- metadata +9 -22
- data/doc/Array.html +0 -200
- data/doc/Boolean.html +0 -122
- data/doc/FalseClass.html +0 -132
- data/doc/Hash.html +0 -332
- data/doc/Icinga2.html +0 -247
- data/doc/Logging.html +0 -328
- data/doc/Object.html +0 -286
- data/doc/Time.html +0 -200
- data/doc/TrueClass.html +0 -132
- data/doc/_index.html +0 -352
- data/doc/class_list.html +0 -51
- data/doc/examples +0 -122
- data/doc/file.README.html +0 -349
- data/doc/file_list.html +0 -56
- data/doc/frames.html +0 -17
- data/doc/index.html +0 -349
- data/doc/method_list.html +0 -755
- data/doc/top-level-namespace.html +0 -112
@@ -11,7 +11,7 @@ module Icinga2
|
|
11
11
|
# @param [String] host
|
12
12
|
#
|
13
13
|
# @example
|
14
|
-
#
|
14
|
+
# enable_host_notification('icinga')
|
15
15
|
#
|
16
16
|
# @return [Hash]
|
17
17
|
#
|
@@ -30,7 +30,7 @@ module Icinga2
|
|
30
30
|
# @param [String] host
|
31
31
|
#
|
32
32
|
# @example
|
33
|
-
#
|
33
|
+
# disable_host_notification('icinga')
|
34
34
|
#
|
35
35
|
# @return [Hash]
|
36
36
|
#
|
@@ -49,7 +49,7 @@ module Icinga2
|
|
49
49
|
# @param [String] host
|
50
50
|
#
|
51
51
|
# @example
|
52
|
-
#
|
52
|
+
# enable_service_notification('icinga')
|
53
53
|
#
|
54
54
|
# @return [Hash]
|
55
55
|
#
|
@@ -68,7 +68,7 @@ module Icinga2
|
|
68
68
|
# @param [String] host
|
69
69
|
#
|
70
70
|
# @example
|
71
|
-
#
|
71
|
+
# disable_service_notification('icinga')
|
72
72
|
#
|
73
73
|
# @return [Hash]
|
74
74
|
#
|
@@ -87,7 +87,7 @@ module Icinga2
|
|
87
87
|
# @param [String] host_group
|
88
88
|
#
|
89
89
|
# @example
|
90
|
-
#
|
90
|
+
# enable_hostgroup_notification('linux-servers')
|
91
91
|
#
|
92
92
|
# @return [Hash]
|
93
93
|
#
|
@@ -106,7 +106,7 @@ module Icinga2
|
|
106
106
|
# @param [String] host_group
|
107
107
|
#
|
108
108
|
# @example
|
109
|
-
#
|
109
|
+
# disable_hostgroup_notification('linux-servers')
|
110
110
|
#
|
111
111
|
# @return [Hash]
|
112
112
|
#
|
@@ -152,7 +152,11 @@ module Icinga2
|
|
152
152
|
name = validate( params, required: true, var: 'name', type: String )
|
153
153
|
notifications = validate( params, required: false, var: 'enable_notifications', type: Boolean ) || false
|
154
154
|
|
155
|
-
payload = {
|
155
|
+
payload = {
|
156
|
+
attrs: {
|
157
|
+
enable_notifications: notifications
|
158
|
+
}
|
159
|
+
}
|
156
160
|
|
157
161
|
post(
|
158
162
|
url: format( '%s/objects/hosts/%s', @icinga_api_url_base, name ),
|
@@ -181,7 +185,9 @@ module Icinga2
|
|
181
185
|
|
182
186
|
payload = {
|
183
187
|
filter: format( '"%s" in host.groups', group ),
|
184
|
-
attrs: {
|
188
|
+
attrs: {
|
189
|
+
enable_notifications: notifications
|
190
|
+
}
|
185
191
|
}
|
186
192
|
|
187
193
|
post(
|
@@ -211,7 +217,9 @@ module Icinga2
|
|
211
217
|
|
212
218
|
payload = {
|
213
219
|
filter: format( 'host.name=="%s"', name ),
|
214
|
-
attrs: {
|
220
|
+
attrs: {
|
221
|
+
enable_notifications: notifications
|
222
|
+
}
|
215
223
|
}
|
216
224
|
|
217
225
|
post(
|
@@ -16,7 +16,7 @@ module Icinga2
|
|
16
16
|
# @option params [String] action_url
|
17
17
|
#
|
18
18
|
# @example
|
19
|
-
#
|
19
|
+
# add_servicegroup(service_group: 'foo', display_name: 'FOO')
|
20
20
|
#
|
21
21
|
# @return [Hash] result
|
22
22
|
#
|
@@ -59,7 +59,7 @@ module Icinga2
|
|
59
59
|
# @option params [Bool] cascade (false) delete servicegroup also when other objects depend on it
|
60
60
|
#
|
61
61
|
# @example
|
62
|
-
#
|
62
|
+
# delete_servicegroup('foo')
|
63
63
|
#
|
64
64
|
# @return [Array] result
|
65
65
|
#
|
@@ -87,10 +87,10 @@ module Icinga2
|
|
87
87
|
# @param [String] service_group (nil) optional for a single servicegroup
|
88
88
|
#
|
89
89
|
# @example to get all users
|
90
|
-
#
|
90
|
+
# servicegroups
|
91
91
|
#
|
92
92
|
# @example to get one user
|
93
|
-
#
|
93
|
+
# servicegroups(service_group: 'disk')
|
94
94
|
#
|
95
95
|
# @return [Array] returns a hash with all servicegroups
|
96
96
|
#
|
@@ -113,7 +113,7 @@ module Icinga2
|
|
113
113
|
# @param [String] service_group the name of the servicegroup
|
114
114
|
#
|
115
115
|
# @example
|
116
|
-
#
|
116
|
+
# exists_servicegroup?('disk')
|
117
117
|
#
|
118
118
|
# @return [Bool] returns true if the servicegroup exists
|
119
119
|
#
|
data/lib/icinga2/services.rb
CHANGED
@@ -21,12 +21,12 @@ module Icinga2
|
|
21
21
|
# @option params [String] check_period
|
22
22
|
# @option params [Integer] check_timeout
|
23
23
|
# @option params [String] command_endpoint
|
24
|
-
# @option params [
|
25
|
-
# @option params [
|
26
|
-
# @option params [
|
27
|
-
# @option params [
|
28
|
-
# @option params [
|
29
|
-
# @option params [
|
24
|
+
# @option params [Bool] enable_active_checks
|
25
|
+
# @option params [Bool] enable_event_handler
|
26
|
+
# @option params [Bool] enable_flapping
|
27
|
+
# @option params [Bool] enable_notifications
|
28
|
+
# @option params [Bool] enable_passive_checks
|
29
|
+
# @option params [Bool] enable_perfdata
|
30
30
|
# @option params [String] event_command
|
31
31
|
# @option params [Integer] flapping_threshold_high
|
32
32
|
# @option params [Integer] flapping_threshold_low
|
@@ -35,11 +35,11 @@ module Icinga2
|
|
35
35
|
# @option params [String] icon_image
|
36
36
|
# @option params [Integer] max_check_attempts
|
37
37
|
# @option params [Integer] retry_interval
|
38
|
-
# @option params [
|
38
|
+
# @option params [Bool] volatile
|
39
39
|
# @option params [Hash] vars
|
40
40
|
#
|
41
41
|
# @example
|
42
|
-
#
|
42
|
+
# add_service(
|
43
43
|
# name: 'http2',
|
44
44
|
# host_name: 'icinga2',
|
45
45
|
# check_command: 'http',
|
@@ -144,8 +144,8 @@ module Icinga2
|
|
144
144
|
# @option params [Bool] cascade (false) delete service also when other objects depend on it
|
145
145
|
#
|
146
146
|
# @example
|
147
|
-
#
|
148
|
-
#
|
147
|
+
# delete_service(host_name: 'foo', name: 'http2')
|
148
|
+
# delete_service(host_name: 'foo', name: 'http2', cascade: true)
|
149
149
|
#
|
150
150
|
# @return [Hash] result
|
151
151
|
#
|
@@ -176,7 +176,7 @@ module Icinga2
|
|
176
176
|
# @option params [Hash] vars
|
177
177
|
#
|
178
178
|
# @example
|
179
|
-
#
|
179
|
+
# modify_service(
|
180
180
|
# name: 'http2',
|
181
181
|
# check_interval: 60,
|
182
182
|
# retry_interval: 10,
|
@@ -275,7 +275,7 @@ module Icinga2
|
|
275
275
|
# return all unhandled services
|
276
276
|
#
|
277
277
|
# @example
|
278
|
-
#
|
278
|
+
# unhandled_services
|
279
279
|
#
|
280
280
|
# @return [Hash]
|
281
281
|
#
|
@@ -308,10 +308,10 @@ module Icinga2
|
|
308
308
|
# @option params [String] name
|
309
309
|
#
|
310
310
|
# @example to get all services
|
311
|
-
#
|
311
|
+
# services
|
312
312
|
#
|
313
313
|
# @example to get one service for host
|
314
|
-
#
|
314
|
+
# services( host_name: 'icinga2', name: 'ping4' )
|
315
315
|
#
|
316
316
|
# @return [Hash]
|
317
317
|
#
|
@@ -339,7 +339,7 @@ module Icinga2
|
|
339
339
|
# @option params [String] name
|
340
340
|
#
|
341
341
|
# @example
|
342
|
-
#
|
342
|
+
# exists_service?(host_name: 'icinga2', name: 'users')
|
343
343
|
#
|
344
344
|
# @return [Bool]
|
345
345
|
#
|
@@ -368,10 +368,10 @@ module Icinga2
|
|
368
368
|
# @option params [Array] joins (['host.name','host.state','host.acknowledgement','host.downtime_depth','host.last_check'])
|
369
369
|
#
|
370
370
|
# @example with default attrs and joins
|
371
|
-
#
|
371
|
+
# service_objects
|
372
372
|
#
|
373
373
|
# @example
|
374
|
-
#
|
374
|
+
# service_objects(attrs: ['name', 'state'], joins: ['host.name','host.state'])
|
375
375
|
#
|
376
376
|
# @return [Array]
|
377
377
|
#
|
@@ -415,9 +415,9 @@ module Icinga2
|
|
415
415
|
# returns adjusted service state
|
416
416
|
#
|
417
417
|
# @example
|
418
|
-
# warning, critical, unknown =
|
418
|
+
# warning, critical, unknown = services_adjusted.values
|
419
419
|
#
|
420
|
-
# s =
|
420
|
+
# s = services_adjusted
|
421
421
|
# unknown = s.dig(:unknown)
|
422
422
|
#
|
423
423
|
# @return [Hash]
|
@@ -455,7 +455,7 @@ module Icinga2
|
|
455
455
|
# return count of services with problems
|
456
456
|
#
|
457
457
|
# @example
|
458
|
-
#
|
458
|
+
# count_services_with_problems
|
459
459
|
#
|
460
460
|
# @return [Integer]
|
461
461
|
#
|
@@ -476,9 +476,9 @@ module Icinga2
|
|
476
476
|
# @param [Integer] max_items numbers of list entries
|
477
477
|
#
|
478
478
|
# @example
|
479
|
-
# problems, problems_and_severity =
|
479
|
+
# problems, problems_and_severity = list_services_with_problems.values
|
480
480
|
#
|
481
|
-
# l =
|
481
|
+
# l = list_services_with_problems
|
482
482
|
# problems_and_severity = l.dig(:services_with_problems_and_severity)
|
483
483
|
#
|
484
484
|
# @return [Hash]
|
@@ -501,9 +501,11 @@ module Icinga2
|
|
501
501
|
name = s.dig('name')
|
502
502
|
state = s.dig('attrs','state')
|
503
503
|
|
504
|
-
next if
|
504
|
+
next if( state.zero? )
|
505
505
|
|
506
|
-
|
506
|
+
# TODO
|
507
|
+
# change spec tests!
|
508
|
+
services_with_problems[name] = state # service_severity(s)
|
507
509
|
end
|
508
510
|
|
509
511
|
if( services_with_problems.count != 0 )
|
@@ -521,7 +523,7 @@ module Icinga2
|
|
521
523
|
# returns a counter of all services
|
522
524
|
#
|
523
525
|
# @example
|
524
|
-
#
|
526
|
+
# services_all
|
525
527
|
#
|
526
528
|
# @return [Integer]
|
527
529
|
#
|
@@ -536,9 +538,9 @@ module Icinga2
|
|
536
538
|
# returns data with service problems
|
537
539
|
#
|
538
540
|
# @example
|
539
|
-
# all, warning, critical, unknown, pending, in_downtime, acknowledged, adjusted_warning, adjusted_critical, adjusted_unknown =
|
541
|
+
# all, warning, critical, unknown, pending, in_downtime, acknowledged, adjusted_warning, adjusted_critical, adjusted_unknown = service_problems.values
|
540
542
|
#
|
541
|
-
# p =
|
543
|
+
# p = service_problems
|
542
544
|
# warning = p.dig(:warning)
|
543
545
|
#
|
544
546
|
# @return [Hash]
|
@@ -593,10 +595,10 @@ module Icinga2
|
|
593
595
|
# returns data with service problems they be handled (acknowledged or in downtime)
|
594
596
|
#
|
595
597
|
# @example
|
596
|
-
#
|
597
|
-
# all, warning, critical, unknown =
|
598
|
+
# service_objects
|
599
|
+
# all, warning, critical, unknown = service_problems_handled.values
|
598
600
|
#
|
599
|
-
# p =
|
601
|
+
# p = service_problems_handled
|
600
602
|
# warning = p.dig(:warning)
|
601
603
|
#
|
602
604
|
# @return [Hash]
|
data/lib/icinga2/statistics.rb
CHANGED
@@ -10,9 +10,9 @@ module Icinga2
|
|
10
10
|
# return statistic data for latency and execution_time
|
11
11
|
#
|
12
12
|
# @example
|
13
|
-
# latency, execution_time =
|
13
|
+
# latency, execution_time = average_statistics.values
|
14
14
|
#
|
15
|
-
# h =
|
15
|
+
# h = average_statistics
|
16
16
|
# latency = h.dig(:latency)
|
17
17
|
#
|
18
18
|
# @return [Hash]
|
@@ -35,9 +35,9 @@ module Icinga2
|
|
35
35
|
# return statistic data for intervall data
|
36
36
|
#
|
37
37
|
# @example
|
38
|
-
# hosts_active_checks, hosts_passive_checks, services_active_checks, services_passive_checks =
|
38
|
+
# hosts_active_checks, hosts_passive_checks, services_active_checks, services_passive_checks = interval_statistics.values
|
39
39
|
#
|
40
|
-
# i =
|
40
|
+
# i = interval_statistics
|
41
41
|
# hosts_active_checks = i.dig(:hosts_active_checks)
|
42
42
|
#
|
43
43
|
# @return [Hash]
|
@@ -68,9 +68,9 @@ module Icinga2
|
|
68
68
|
# return statistic data for services
|
69
69
|
#
|
70
70
|
# @example
|
71
|
-
# ok, warning, critical, unknown, pending, in_downtime, ack =
|
71
|
+
# ok, warning, critical, unknown, pending, in_downtime, ack = service_statistics.values
|
72
72
|
#
|
73
|
-
# s =
|
73
|
+
# s = service_statistics
|
74
74
|
# critical = s.dig(:critical)
|
75
75
|
#
|
76
76
|
# @return [Hash]
|
@@ -108,9 +108,9 @@ module Icinga2
|
|
108
108
|
# return statistic data for hosts
|
109
109
|
#
|
110
110
|
# @example
|
111
|
-
# up, down, pending, unreachable, in_downtime, ack =
|
111
|
+
# up, down, pending, unreachable, in_downtime, ack = host_statistics.values
|
112
112
|
#
|
113
|
-
# h =
|
113
|
+
# h = host_statistics
|
114
114
|
# pending = h.dig(:pending)
|
115
115
|
#
|
116
116
|
# @return [Hash]
|
@@ -146,7 +146,7 @@ module Icinga2
|
|
146
146
|
# return queue statistics from the api
|
147
147
|
#
|
148
148
|
# @example
|
149
|
-
#
|
149
|
+
# work_queue_statistics
|
150
150
|
#
|
151
151
|
# @return [Hash]
|
152
152
|
#
|
@@ -171,14 +171,17 @@ module Icinga2
|
|
171
171
|
graphite_data = graphite_data.dig('status', 'graphitewriter', 'graphite') unless( graphite_data.nil? )
|
172
172
|
ido_mysql_data = ido_mysql_data.dig('status', 'idomysqlconnection', 'ido-mysql') unless( ido_mysql_data.nil? )
|
173
173
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
174
|
+
payload = {
|
175
|
+
json_rpc: json_rpc_data,
|
176
|
+
graphite: graphite_data,
|
177
|
+
ido_mysql: ido_mysql_data
|
178
|
+
}
|
179
|
+
|
180
|
+
payload.reject!{ |_k, v| v.nil? }
|
178
181
|
|
179
182
|
key_list = %w[work_queue_item_rate query_queue_item_rate]
|
180
183
|
|
181
|
-
|
184
|
+
payload.each do |k,v|
|
182
185
|
key_list.each do |key|
|
183
186
|
if( v.include?( key ))
|
184
187
|
attr_name = format('%s queue rate', k)
|
data/lib/icinga2/tools.rb
CHANGED
@@ -49,18 +49,18 @@ module Icinga2
|
|
49
49
|
# @param [Integer] state (nil)
|
50
50
|
#
|
51
51
|
# @example for host objects
|
52
|
-
# h_objects =
|
53
|
-
# all =
|
54
|
-
# down =
|
55
|
-
# critical =
|
56
|
-
# unknown =
|
52
|
+
# h_objects = host_objects
|
53
|
+
# all = count_problems(h_objects)
|
54
|
+
# down = count_problems(h_objects, Icinga2::HOSTS_DOWN)
|
55
|
+
# critical = count_problems(h_objects, Icinga2::HOSTS_CRITICAL)
|
56
|
+
# unknown = count_problems(h_objects, Icinga2::HOSTS_UNKNOWN)
|
57
57
|
#
|
58
58
|
# @example for service objects
|
59
|
-
# s_objects =
|
60
|
-
# all =
|
61
|
-
# warning =
|
62
|
-
# critical =
|
63
|
-
# unknown =
|
59
|
+
# s_objects = service_objects
|
60
|
+
# all = count_problems(s_objects)
|
61
|
+
# warning = count_problems(s_objects, Icinga2::SERVICE_STATE_WARNING)
|
62
|
+
# critical = count_problems(s_objects, Icinga2::SERVICE_STATE_CRITICAL)
|
63
|
+
# unknown = count_problems(s_objects, Icinga2::SERVICE_STATE_UNKNOWN)
|
64
64
|
#
|
65
65
|
# @return [Integer]
|
66
66
|
#
|
@@ -91,5 +91,26 @@ module Icinga2
|
|
91
91
|
f.size
|
92
92
|
end
|
93
93
|
|
94
|
+
|
95
|
+
# check, it an String a valid Json
|
96
|
+
#
|
97
|
+
# @param json [String] json
|
98
|
+
#
|
99
|
+
# @example
|
100
|
+
# valid_json?( json )
|
101
|
+
#
|
102
|
+
# @return [Bool]
|
103
|
+
#
|
104
|
+
def valid_json?( json )
|
105
|
+
|
106
|
+
begin
|
107
|
+
JSON.parse( json )
|
108
|
+
return true
|
109
|
+
rescue JSON::ParserError => e
|
110
|
+
@logger.error("json parse error: #{e}") if @debug
|
111
|
+
return false
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
94
115
|
end
|
95
116
|
end
|
data/lib/icinga2/usergroups.rb
CHANGED
@@ -13,7 +13,7 @@ module Icinga2
|
|
13
13
|
# @option params [String] display_name the displayed name
|
14
14
|
#
|
15
15
|
# @example
|
16
|
-
#
|
16
|
+
# add_usergroup(user_group: 'foo', display_name: 'FOO')
|
17
17
|
#
|
18
18
|
# @return [Hash] result
|
19
19
|
#
|
@@ -48,7 +48,7 @@ module Icinga2
|
|
48
48
|
# @param [String] user_group usergroup to delete
|
49
49
|
#
|
50
50
|
# @example
|
51
|
-
#
|
51
|
+
# delete_usergroup('foo')
|
52
52
|
#
|
53
53
|
# @return [Hash] result
|
54
54
|
#
|
@@ -69,10 +69,10 @@ module Icinga2
|
|
69
69
|
# @param [String] user_group (nil) optional for a single usergroup
|
70
70
|
#
|
71
71
|
# @example to get all users
|
72
|
-
#
|
72
|
+
# usergroups
|
73
73
|
#
|
74
74
|
# @example to get one user
|
75
|
-
#
|
75
|
+
# usergroups('icingaadmins')
|
76
76
|
#
|
77
77
|
# @return [Hash] returns a hash with all usergroups
|
78
78
|
#
|
@@ -93,7 +93,7 @@ module Icinga2
|
|
93
93
|
# @param [String] user_group the name of the usergroups
|
94
94
|
#
|
95
95
|
# @example
|
96
|
-
#
|
96
|
+
# exists_usergroup?('icingaadmins')
|
97
97
|
#
|
98
98
|
# @return [Bool] returns true if the usergroup exists
|
99
99
|
#
|