icinga2 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/Icinga2.html +151 -0
- data/doc/Logging.html +316 -0
- data/doc/_index.html +285 -0
- data/doc/class_list.html +51 -0
- data/doc/file.README.html +278 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +278 -0
- data/doc/method_list.html +523 -0
- data/doc/status.md +12 -0
- data/doc/top-level-namespace.html +110 -0
- data/examples/test.rb +143 -102
- data/lib/icinga2.rb +12 -4
- data/lib/icinga2/converts.rb +8 -8
- data/lib/icinga2/downtimes.rb +34 -14
- data/lib/icinga2/hostgroups.rb +54 -20
- data/lib/icinga2/hosts.rb +126 -65
- data/lib/icinga2/network.rb +44 -3
- data/lib/icinga2/notifications.rb +120 -25
- data/lib/icinga2/servicegroups.rb +44 -10
- data/lib/icinga2/services.rb +100 -51
- data/lib/icinga2/status.rb +16 -10
- data/lib/icinga2/tools.rb +5 -3
- data/lib/icinga2/usergroups.rb +47 -12
- data/lib/icinga2/users.rb +49 -23
- data/lib/icinga2/version.rb +6 -4
- metadata +13 -2
data/lib/icinga2/network.rb
CHANGED
@@ -2,14 +2,21 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
module Icinga2
|
4
4
|
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
5
|
+
# namespace for network handling
|
8
6
|
module Network
|
9
7
|
|
8
|
+
# static function for GET Requests
|
10
9
|
#
|
10
|
+
# @param [Hash] params
|
11
|
+
# @option params [String] :host
|
12
|
+
# @option params [String] :url
|
13
|
+
# @option params [String] :headers
|
14
|
+
# @option params [String] :options
|
15
|
+
# @option params [Hash] :payload
|
11
16
|
#
|
12
17
|
#
|
18
|
+
# @return [Hash]
|
19
|
+
#
|
13
20
|
def self.get( params = {} )
|
14
21
|
|
15
22
|
host = params.dig(:host)
|
@@ -95,8 +102,18 @@ module Icinga2
|
|
95
102
|
|
96
103
|
end
|
97
104
|
|
105
|
+
# static function for GET Requests with payload
|
106
|
+
# internal we use here an POST Request and overwrite a http header
|
107
|
+
#
|
108
|
+
# @param [Hash] params
|
109
|
+
# @option params [String] :host
|
110
|
+
# @option params [String] :url
|
111
|
+
# @option params [String] :headers
|
112
|
+
# @option params [String] :options
|
113
|
+
# @option params [Hash] :payload
|
98
114
|
#
|
99
115
|
#
|
116
|
+
# @return [Hash]
|
100
117
|
#
|
101
118
|
def self.get_with_payload( params = {} )
|
102
119
|
|
@@ -177,8 +194,16 @@ module Icinga2
|
|
177
194
|
|
178
195
|
end
|
179
196
|
|
197
|
+
# static function for POST Requests
|
198
|
+
#
|
199
|
+
# @param [Hash] params
|
200
|
+
# @option params [String] :url
|
201
|
+
# @option params [String] :headers
|
202
|
+
# @option params [String] :options
|
203
|
+
# @option params [Hash] :payload
|
180
204
|
#
|
181
205
|
#
|
206
|
+
# @return [Hash]
|
182
207
|
#
|
183
208
|
def self.post( params = {} )
|
184
209
|
|
@@ -265,9 +290,18 @@ module Icinga2
|
|
265
290
|
result
|
266
291
|
end
|
267
292
|
|
293
|
+
# static function for PUT Requests
|
268
294
|
#
|
295
|
+
# @param [Hash] params
|
296
|
+
# @option params [String] :host
|
297
|
+
# @option params [String] :url
|
298
|
+
# @option params [String] :headers
|
299
|
+
# @option params [String] :options
|
300
|
+
# @option params [Hash] :payload
|
269
301
|
#
|
270
302
|
#
|
303
|
+
# @return [Hash]
|
304
|
+
#
|
271
305
|
def self.put( params = {} )
|
272
306
|
|
273
307
|
host = params.dig(:host)
|
@@ -369,8 +403,15 @@ module Icinga2
|
|
369
403
|
result
|
370
404
|
end
|
371
405
|
|
406
|
+
# static function for DELETE Requests
|
407
|
+
#
|
408
|
+
# @param [Hash] params
|
409
|
+
# @option params [String] :url
|
410
|
+
# @option params [String] :headers
|
411
|
+
# @option params [String] :options
|
372
412
|
#
|
373
413
|
#
|
414
|
+
# @return [Hash]
|
374
415
|
#
|
375
416
|
def self.delete( params = {} )
|
376
417
|
|
@@ -3,34 +3,47 @@
|
|
3
3
|
|
4
4
|
module Icinga2
|
5
5
|
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# namespace for servicegroup handling
|
9
7
|
module Notifications
|
10
8
|
|
9
|
+
# enable host notifications
|
11
10
|
#
|
11
|
+
# @param [String] host
|
12
12
|
#
|
13
|
+
# @example
|
14
|
+
# @icinga.enable_host_notification('icinga')
|
15
|
+
#
|
16
|
+
# @return [Hash]
|
13
17
|
#
|
14
18
|
def enable_host_notification( host )
|
15
19
|
|
16
20
|
host_notification( name: host, enable_notifications: true )
|
17
21
|
end
|
18
22
|
|
23
|
+
# disable host notifications
|
24
|
+
#
|
25
|
+
# @param [String] host
|
19
26
|
#
|
27
|
+
# @example
|
28
|
+
# @icinga.disable_host_notification('icinga')
|
20
29
|
#
|
30
|
+
# @return [Hash]
|
21
31
|
#
|
22
32
|
def disable_host_notification( host )
|
23
33
|
|
24
34
|
host_notification( name: host, enable_notifications: false )
|
25
35
|
end
|
26
36
|
|
37
|
+
# enable service notifications
|
27
38
|
#
|
39
|
+
# @param [String] host
|
28
40
|
#
|
41
|
+
# @example
|
42
|
+
# @icinga.enable_service_notification('icinga')
|
29
43
|
#
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
service = params.get(:service)
|
44
|
+
# @return [Hash]
|
45
|
+
#
|
46
|
+
def enable_service_notification( host )
|
34
47
|
|
35
48
|
if( host.nil? )
|
36
49
|
|
@@ -40,52 +53,125 @@ module Icinga2
|
|
40
53
|
}
|
41
54
|
end
|
42
55
|
|
43
|
-
service_notification( name: host,
|
56
|
+
service_notification( name: host, enable_notifications: true )
|
44
57
|
end
|
45
58
|
|
59
|
+
# disable service notifications
|
60
|
+
#
|
61
|
+
# @param [String] host
|
46
62
|
#
|
63
|
+
# @example
|
64
|
+
# @icinga.disable_service_notification('icinga')
|
47
65
|
#
|
66
|
+
# @return [Hash]
|
48
67
|
#
|
49
68
|
def disable_service_notification( host )
|
50
69
|
|
70
|
+
if( host.nil? )
|
71
|
+
return {
|
72
|
+
status: 404,
|
73
|
+
message: 'missing host name'
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
51
77
|
service_notification( name: host, enable_notifications: false )
|
52
78
|
end
|
53
79
|
|
80
|
+
# enable hostgroup notifications
|
54
81
|
#
|
82
|
+
# @param [Hash] params
|
83
|
+
# @option params [String] host
|
84
|
+
# @option params [String] host_group
|
55
85
|
#
|
86
|
+
# @example
|
87
|
+
# @icinga.enable_hostgroup_notification(host: 'icinga2', host_group: 'linux-servers')
|
56
88
|
#
|
57
|
-
|
89
|
+
# @return [Hash]
|
90
|
+
#
|
91
|
+
def enable_hostgroup_notification( params = {} )
|
92
|
+
|
93
|
+
host = params.dig(:host)
|
94
|
+
host_group = params.dig(:host_group)
|
95
|
+
|
96
|
+
if( host.nil? )
|
97
|
+
return {
|
98
|
+
status: 404,
|
99
|
+
message: 'missing host name'
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
103
|
+
if( host_group.nil? )
|
104
|
+
return {
|
105
|
+
status: 404,
|
106
|
+
message: 'missing host_group name'
|
107
|
+
}
|
108
|
+
end
|
58
109
|
|
59
|
-
hostgroup_notification( host_group:
|
110
|
+
hostgroup_notification( host: host, host_group: host_group, enable_notifications: true )
|
60
111
|
end
|
61
112
|
|
113
|
+
# disable hostgroup notifications
|
62
114
|
#
|
115
|
+
# @param [Hash] params
|
116
|
+
# @option params [String] host
|
117
|
+
# @option params [String] host_group
|
63
118
|
#
|
119
|
+
# @example
|
120
|
+
# @icinga.disable_hostgroup_notification(host: 'icinga2', host_group: 'linux-servers')
|
64
121
|
#
|
65
|
-
|
122
|
+
# @return [Hash]
|
123
|
+
#
|
124
|
+
def disable_hostgroup_notification( params = {} )
|
125
|
+
|
126
|
+
host = params.dig(:host)
|
127
|
+
host_group = params.dig(:host_group)
|
128
|
+
|
129
|
+
if( host.nil? )
|
130
|
+
return {
|
131
|
+
status: 404,
|
132
|
+
message: 'missing host name'
|
133
|
+
}
|
134
|
+
end
|
66
135
|
|
67
|
-
|
136
|
+
if( host_group.nil? )
|
137
|
+
return {
|
138
|
+
status: 404,
|
139
|
+
message: 'missing host_group name'
|
140
|
+
}
|
141
|
+
end
|
142
|
+
|
143
|
+
hostgroup_notification( host: host, host_group: host_group, enable_notifications: false )
|
68
144
|
end
|
69
145
|
|
146
|
+
# return all notifications
|
70
147
|
#
|
148
|
+
# @param [Hash] params
|
149
|
+
# @option params [String] name
|
71
150
|
#
|
151
|
+
# @return [Hash]
|
72
152
|
#
|
73
153
|
def notifications( params = {} )
|
74
154
|
|
75
155
|
name = params.dig(:name)
|
76
156
|
|
77
|
-
|
157
|
+
Network.get( host: name,
|
78
158
|
url: format( '%s/v1/objects/notifications/%s', @icinga_api_url_base, name ),
|
79
159
|
headers: @headers,
|
80
160
|
options: @options )
|
81
161
|
|
82
|
-
JSON.pretty_generate( result )
|
83
|
-
|
84
162
|
end
|
85
163
|
|
86
164
|
|
87
|
-
#
|
165
|
+
# function for host notifications
|
166
|
+
# @private
|
88
167
|
#
|
168
|
+
# @param [Hash] params
|
169
|
+
# @option params [String] name
|
170
|
+
# @option params [Bool] enable_notifications (false)
|
171
|
+
#
|
172
|
+
# @return [Hash]
|
173
|
+
#
|
174
|
+
private
|
89
175
|
def host_notification( params = {} )
|
90
176
|
|
91
177
|
name = params.dig(:name)
|
@@ -97,21 +183,27 @@ module Icinga2
|
|
97
183
|
}
|
98
184
|
}
|
99
185
|
|
100
|
-
|
186
|
+
Network.post( host: name,
|
101
187
|
url: format( '%s/v1/objects/hosts/%s', @icinga_api_url_base, name ),
|
102
188
|
headers: @headers,
|
103
189
|
options: @options,
|
104
190
|
payload: payload )
|
105
191
|
|
106
|
-
JSON.pretty_generate( result )
|
107
|
-
|
108
192
|
end
|
109
193
|
|
194
|
+
# function for hostgroup notifications
|
195
|
+
# @private
|
110
196
|
#
|
197
|
+
# @param [Hash] params
|
198
|
+
# @option params [String] host_group
|
199
|
+
# @option params [Bool] enable_notifications (false)
|
111
200
|
#
|
201
|
+
# @return [Hash]
|
112
202
|
#
|
203
|
+
private
|
113
204
|
def hostgroup_notification( params = {} )
|
114
205
|
|
206
|
+
host = params.dig(:host)
|
115
207
|
group = params.dig(:host_group)
|
116
208
|
notifications = params.dig(:enable_notifications) || false
|
117
209
|
|
@@ -122,19 +214,24 @@ module Icinga2
|
|
122
214
|
}
|
123
215
|
}
|
124
216
|
|
125
|
-
|
217
|
+
Network.post( host: host,
|
126
218
|
url: format( '%s/v1/objects/services', @icinga_api_url_base ),
|
127
219
|
headers: @headers,
|
128
220
|
options: @options,
|
129
221
|
payload: payload )
|
130
222
|
|
131
|
-
JSON.pretty_generate( result )
|
132
|
-
|
133
223
|
end
|
134
224
|
|
225
|
+
# function for service notifications
|
226
|
+
# @private
|
135
227
|
#
|
228
|
+
# @param [Hash] params
|
229
|
+
# @option params [String] name
|
230
|
+
# @option params [Bool] enable_notifications (false)
|
136
231
|
#
|
232
|
+
# @return [Hash]
|
137
233
|
#
|
234
|
+
private
|
138
235
|
def service_notification( params = {} )
|
139
236
|
|
140
237
|
name = params.dig(:name)
|
@@ -147,14 +244,12 @@ module Icinga2
|
|
147
244
|
}
|
148
245
|
}
|
149
246
|
|
150
|
-
|
247
|
+
Network.post( host: name,
|
151
248
|
url: format( '%s/v1/objects/services', @icinga_api_url_base ),
|
152
249
|
headers: @headers,
|
153
250
|
options: @options,
|
154
251
|
payload: payload )
|
155
252
|
|
156
|
-
JSON.pretty_generate( result )
|
157
|
-
|
158
253
|
end
|
159
254
|
|
160
255
|
end
|
@@ -3,17 +3,25 @@
|
|
3
3
|
|
4
4
|
module Icinga2
|
5
5
|
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# namespace for servicegroup handling
|
9
7
|
module Servicegroups
|
10
8
|
|
9
|
+
# add a servicegroup
|
11
10
|
#
|
11
|
+
# @param [Hash] params
|
12
|
+
# @option params [String] :name servicegroup to create
|
13
|
+
# @option params [String] :display_name the displayed name
|
12
14
|
#
|
15
|
+
# @example
|
16
|
+
# @icinga.add_servicegroup(name: 'foo', display_name: 'FOO')
|
17
|
+
#
|
18
|
+
# @return [Hash] result
|
13
19
|
#
|
14
20
|
def add_servicegroup( params = {} )
|
21
|
+
|
15
22
|
name = params.dig(:name)
|
16
23
|
display_name = params.dig(:display_name)
|
24
|
+
|
17
25
|
if( name.nil? )
|
18
26
|
return {
|
19
27
|
status: 404,
|
@@ -23,20 +31,28 @@ module Icinga2
|
|
23
31
|
|
24
32
|
payload = { 'attrs' => { 'display_name' => display_name } }
|
25
33
|
|
26
|
-
|
34
|
+
Network.put( host: name,
|
27
35
|
url: format( '%s/v1/objects/servicegroups/%s', @icinga_api_url_base, name ),
|
28
36
|
headers: @headers,
|
29
37
|
options: @options,
|
30
38
|
payload: payload )
|
31
39
|
|
32
|
-
JSON.pretty_generate( result )
|
33
40
|
end
|
34
41
|
|
42
|
+
# delete a servicegroup
|
43
|
+
#
|
44
|
+
# @param [Hash] params
|
45
|
+
# @option params [String] :name servicegroup to delete
|
35
46
|
#
|
47
|
+
# @example
|
48
|
+
# @icinga.delete_servicegroup(name: 'foo')
|
36
49
|
#
|
50
|
+
# @return [Hash] result
|
37
51
|
#
|
38
52
|
def delete_servicegroup( params = {} )
|
53
|
+
|
39
54
|
name = params.dig(:name)
|
55
|
+
|
40
56
|
if( name.nil? )
|
41
57
|
return {
|
42
58
|
status: 404,
|
@@ -44,34 +60,52 @@ module Icinga2
|
|
44
60
|
}
|
45
61
|
end
|
46
62
|
|
47
|
-
|
63
|
+
Network.delete( host: name,
|
48
64
|
url: format( '%s/v1/objects/servicegroups/%s?cascade=1', @icinga_api_url_base, name ),
|
49
65
|
headers: @headers,
|
50
66
|
options: @options )
|
51
67
|
|
52
|
-
JSON.pretty_generate( result )
|
53
68
|
end
|
54
69
|
|
70
|
+
# returns all servicegroups
|
71
|
+
#
|
72
|
+
# @param [Hash] params
|
73
|
+
# @option params [String] :name ('') optional for a single servicegroup
|
55
74
|
#
|
75
|
+
# @example to get all users
|
76
|
+
# @icinga.servicegroups
|
56
77
|
#
|
78
|
+
# @example to get one user
|
79
|
+
# @icinga.servicegroups(name: 'disk')
|
80
|
+
#
|
81
|
+
# @return [Hash] returns a hash with all servicegroups
|
57
82
|
#
|
58
83
|
def servicegroups( params = {} )
|
84
|
+
|
59
85
|
name = params.dig(:name)
|
60
|
-
|
86
|
+
|
87
|
+
Network.get( host: name,
|
61
88
|
url: format( '%s/v1/objects/servicegroups/%s', @icinga_api_url_base, name ),
|
62
89
|
headers: @headers,
|
63
90
|
options: @options )
|
64
91
|
|
65
|
-
JSON.pretty_generate( result )
|
66
92
|
end
|
67
93
|
|
94
|
+
# returns true if the servicegroup exists
|
68
95
|
#
|
96
|
+
# @param [String] name the name of the servicegroups
|
69
97
|
#
|
98
|
+
# @example
|
99
|
+
# @icinga.exists_servicegroup?('disk')
|
100
|
+
#
|
101
|
+
# @return [Bool] returns true if the servicegroup exists
|
70
102
|
#
|
71
103
|
def exists_servicegroup?( name )
|
72
104
|
result = servicegroups( name: name )
|
73
105
|
result = JSON.parse( result ) if result.is_a?( String )
|
74
|
-
|
106
|
+
|
107
|
+
status = result.dig(:status)
|
108
|
+
|
75
109
|
return true if !status.nil? && status == 200
|
76
110
|
false
|
77
111
|
end
|