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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a7a28e46c91e531a8442586d4f1a920ad2e01c2
|
4
|
+
data.tar.gz: 949ef6c923a5f5efe3a4dde2b983a5877f5e3e17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fbf96dde58391e3a0cba5d6fc497359fe52835919043f170df30c55ed9adf9e2d34a218076e36755da54271845807736fd861174833e48bd8c784ae6179fe5f
|
7
|
+
data.tar.gz: f8310775e88be3c876024b5510d1f0e26a85147f9dab5ac8994cb73fe4edc0d71692b2f4a6b3ec5a63d7c0c3cc9e8d8319b5f1842c63c3914c46e5b316ea5a30
|
data/README.md
CHANGED
@@ -144,6 +144,7 @@ supports the following API Calls:
|
|
144
144
|
|
145
145
|
- [Downtimes](doc/downtimes.md)
|
146
146
|
* [add downtime](doc/downtimes.md#add-downtime)
|
147
|
+
* [remove downtime](doc/downtimes.md#remove-downtime)
|
147
148
|
* [list downtimes](doc/downtimes.md#list-downtimes)
|
148
149
|
|
149
150
|
- [Notifications](doc/notifications.md)
|
@@ -165,12 +166,3 @@ supports the following API Calls:
|
|
165
166
|
* [statistic data for hosts](doc/statistics.md#stats-hosts)
|
166
167
|
* [queue statistics from the api](doc/statistics.md#stats-work-queue)
|
167
168
|
|
168
|
-
|
169
|
-
|
170
|
-
## Contributing
|
171
|
-
|
172
|
-
1. Fork it
|
173
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
174
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
175
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
176
|
-
5. Create new Pull Request
|
data/doc/downtimes.md
CHANGED
@@ -18,6 +18,45 @@
|
|
18
18
|
@icinga.add_downtime( param )
|
19
19
|
|
20
20
|
|
21
|
+
## <a name="remove-downtime"></a>remove a downtime
|
22
|
+
remove_downtime( params )
|
23
|
+
|
24
|
+
### Example
|
25
|
+
|
26
|
+
remove all downtimes from the user `icingaadmin` and the comment `test downtime`
|
27
|
+
|
28
|
+
```bash
|
29
|
+
param = {
|
30
|
+
comment: 'test downtime',
|
31
|
+
author: 'icingaadmin'
|
32
|
+
}
|
33
|
+
@icinga.remove_downtime(param)
|
34
|
+
```
|
35
|
+
|
36
|
+
remove a downtime from a host but not the services filtered by the author name.
|
37
|
+
This example uses filter variables explained in the
|
38
|
+
[advanced filters](https://github.com/Icinga/icinga2/blob/master/doc/12-icinga2-api.md#icinga2-api-advanced-filters)
|
39
|
+
chapter from the official API documentation.
|
40
|
+
|
41
|
+
```bash
|
42
|
+
param = {
|
43
|
+
filter: '"host.name == filterHost && !service && downtime.author == filterAuthor"',
|
44
|
+
filter_vars: { filterHost: 'c1-mysql-1', filterAuthor: 'icingaadmin' }
|
45
|
+
)
|
46
|
+
@icinga.remove_downtime(param)
|
47
|
+
```
|
48
|
+
|
49
|
+
remove a downtime for service `ping4` and host `c1-mysql-1`
|
50
|
+
|
51
|
+
```bash
|
52
|
+
param = {
|
53
|
+
host_name: 'c1-mysql-1',
|
54
|
+
service_name: 'ping4'
|
55
|
+
}
|
56
|
+
@icinga.remove_downtime(param)
|
57
|
+
```
|
58
|
+
|
59
|
+
|
21
60
|
## <a name="list-downtimes"></a>list all downtimes
|
22
61
|
downtimes
|
23
62
|
|
@@ -0,0 +1,152 @@
|
|
1
|
+
|
2
|
+
# frozen_string_literal: false
|
3
|
+
|
4
|
+
module Icinga2
|
5
|
+
|
6
|
+
# namespace for action handling
|
7
|
+
#
|
8
|
+
# There are several actions available for Icinga 2 provided by the /v1/actions URL endpoint.
|
9
|
+
#
|
10
|
+
#
|
11
|
+
# original API Documentation: https://www.icinga.com/docs/icinga2/latest/doc/12-icinga2-api/#actions
|
12
|
+
#
|
13
|
+
module Actions
|
14
|
+
|
15
|
+
# Process a check result for a host or a service.
|
16
|
+
#
|
17
|
+
# FUNCTION IS NOT IMPLEMENTED YET
|
18
|
+
#
|
19
|
+
# original Documentation: https://www.icinga.com/docs/icinga2/latest/doc/12-icinga2-api/#process-check-result
|
20
|
+
#
|
21
|
+
# @param [Hash] params
|
22
|
+
# @option params [Integer] exit_status For services: 0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN, for hosts: 0=OK, 1=CRITICAL.
|
23
|
+
# @option params [String] plugin_output One or more lines of the plugin main output. Does not contain the performance data.
|
24
|
+
# @option params [Array] performance_data The performance data.
|
25
|
+
# @option params [Array] check_command The first entry should be the check commands path, then one entry for each command line option followed by an entry for each of its argument.
|
26
|
+
# @option params [String] check_source Usually the name of the command_endpoint
|
27
|
+
# @option params [Integer] execution_start The timestamp where a script/process started its execution.
|
28
|
+
# @option params [Integer] execution_end The timestamp where a script/process ended its execution. This timestamp is used in features to determine e.g. the metric timestamp.
|
29
|
+
# @option params [String] host_name
|
30
|
+
# @option params [String] service_name
|
31
|
+
# @option params [String] type
|
32
|
+
# @option params [String] filter
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# params = {
|
36
|
+
# host_name: 'example.localdomain',
|
37
|
+
# service_name: 'passive-ping6',
|
38
|
+
# exit_status: 2,
|
39
|
+
# plugin_output: 'PING CRITICAL - Packet loss = 100%',
|
40
|
+
# performance_data: [
|
41
|
+
# 'rta=5000.000000ms;3000.000000;5000.000000;0.000000',
|
42
|
+
# 'pl=100%;80;100;0'
|
43
|
+
# ],
|
44
|
+
# check_source: 'example.localdomain'
|
45
|
+
# }
|
46
|
+
# process_check_result(params)
|
47
|
+
#
|
48
|
+
# params = {
|
49
|
+
# exit_status: 1,
|
50
|
+
# plugin_output: 'Host is not available.',
|
51
|
+
# type: 'Host',
|
52
|
+
# filter: 'host.name == "example.localdomain"'
|
53
|
+
# }
|
54
|
+
# process_check_result(params)
|
55
|
+
#
|
56
|
+
# @return [Hash] result
|
57
|
+
#
|
58
|
+
# def process_check_result(params)
|
59
|
+
#
|
60
|
+
# raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) )
|
61
|
+
# raise ArgumentError.new('missing \'params\'') if( params.size.zero? )
|
62
|
+
#
|
63
|
+
# # exit_status = validate( params, required: true, var: 'exit_status', type: Integer )
|
64
|
+
# # plugin_output = validate( params, required: true, var: 'plugin_output', type: String )
|
65
|
+
# # performance_data = validate( params, required: false, var: 'performance_data', type: Array )
|
66
|
+
# # check_command = validate( params, required: false, var: 'check_command', type: Array )
|
67
|
+
# # check_source = validate( params, required: false, var: 'check_source', type: String )
|
68
|
+
# # execution_start = validate( params, required: false, var: 'execution_start', type: Integer )
|
69
|
+
# # execution_end = validate( params, required: false, var: 'execution_end', type: String )
|
70
|
+
#
|
71
|
+
# end
|
72
|
+
|
73
|
+
#
|
74
|
+
# original Documentation: https://www.icinga.com/docs/icinga2/latest/doc/12-icinga2-api/#reschedule-check
|
75
|
+
# def reschedule_check(params)
|
76
|
+
#
|
77
|
+
# # $ curl -k -s -u root:icinga -H 'Accept: application/json' -X POST 'https://localhost:5665/v1/actions/reschedule-check' \
|
78
|
+
# # -d '{ "type": "Service", "filter": "service.name==\"ping6\"" }' | python -m json.tool
|
79
|
+
# end
|
80
|
+
|
81
|
+
#
|
82
|
+
# original Documentation: https://www.icinga.com/docs/icinga2/latest/doc/12-icinga2-api/#send-custom-notification
|
83
|
+
# def send_custom_notification
|
84
|
+
# end
|
85
|
+
|
86
|
+
#
|
87
|
+
# original Documentation: https://www.icinga.com/docs/icinga2/latest/doc/12-icinga2-api/#delay-notification
|
88
|
+
# def delay_notification
|
89
|
+
# end
|
90
|
+
|
91
|
+
#
|
92
|
+
# original Documentation: https://www.icinga.com/docs/icinga2/latest/doc/12-icinga2-api/#acknowledge-problem
|
93
|
+
# def acknowledge_problem
|
94
|
+
# end
|
95
|
+
|
96
|
+
#
|
97
|
+
# original Documentation: https://www.icinga.com/docs/icinga2/latest/doc/12-icinga2-api/#remove-acknowledgement
|
98
|
+
# def remove_acknowledgement
|
99
|
+
# end
|
100
|
+
|
101
|
+
#
|
102
|
+
# original Documentation: https://www.icinga.com/docs/icinga2/latest/doc/12-icinga2-api/#add-comment
|
103
|
+
# def add_comment
|
104
|
+
# end
|
105
|
+
|
106
|
+
#
|
107
|
+
# original Documentation: https://www.icinga.com/docs/icinga2/latest/doc/12-icinga2-api/#remove-comment
|
108
|
+
# def remove_comment
|
109
|
+
# end
|
110
|
+
|
111
|
+
#
|
112
|
+
# original Documentation: https://www.icinga.com/docs/icinga2/latest/doc/12-icinga2-api/#schedule-downtime
|
113
|
+
# def schedule_downtime
|
114
|
+
# end
|
115
|
+
|
116
|
+
# Shuts down Icinga2.
|
117
|
+
#
|
118
|
+
# @example
|
119
|
+
# shutdown_process
|
120
|
+
#
|
121
|
+
# @return [Hash]
|
122
|
+
#
|
123
|
+
def shutdown_process
|
124
|
+
post(
|
125
|
+
url: format('%s/actions/shutdown-process', @icinga_api_url_base),
|
126
|
+
headers: @headers,
|
127
|
+
options: @options
|
128
|
+
)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Restarts Icinga2.
|
132
|
+
#
|
133
|
+
# @example
|
134
|
+
# restart_process
|
135
|
+
#
|
136
|
+
# @return [Hash]
|
137
|
+
#
|
138
|
+
def restart_process
|
139
|
+
post(
|
140
|
+
url: format('%s/actions/restart-process', @icinga_api_url_base),
|
141
|
+
headers: @headers,
|
142
|
+
options: @options
|
143
|
+
)
|
144
|
+
end
|
145
|
+
|
146
|
+
#
|
147
|
+
# original Documentation: https://www.icinga.com/docs/icinga2/latest/doc/12-icinga2-api/#generate-ticket
|
148
|
+
# def generate_ticket
|
149
|
+
# end
|
150
|
+
|
151
|
+
end
|
152
|
+
end
|
data/lib/icinga2/client.rb
CHANGED
@@ -13,6 +13,8 @@ require_relative 'services'
|
|
13
13
|
require_relative 'servicegroups'
|
14
14
|
require_relative 'users'
|
15
15
|
require_relative 'usergroups'
|
16
|
+
require_relative 'configuration_management'
|
17
|
+
require_relative 'actions'
|
16
18
|
|
17
19
|
# -------------------------------------------------------------------------------------------------------------------
|
18
20
|
#
|
@@ -59,15 +61,19 @@ module Icinga2
|
|
59
61
|
include Icinga2::Servicegroups
|
60
62
|
include Icinga2::Users
|
61
63
|
include Icinga2::Usergroups
|
64
|
+
include Icinga2::ConfigurationManagement
|
65
|
+
include Icinga2::Actions
|
62
66
|
|
63
67
|
# Returns a new instance of Client
|
64
68
|
#
|
65
69
|
# @param [Hash, #read] settings the settings for Icinga2
|
66
|
-
# @option settings [String]
|
67
|
-
# @option settings [Integer]
|
68
|
-
# @option settings [String]
|
69
|
-
# @option settings [String]
|
70
|
-
# @option settings [Integer]
|
70
|
+
# @option settings [String] host the Icinga2 Hostname
|
71
|
+
# @option settings [Integer] port (5665) the Icinga2 API Port
|
72
|
+
# @option settings [String] username the Icinga2 API User
|
73
|
+
# @option settings [String] password the Icinga2 API Password
|
74
|
+
# @option settings [Integer] version (1) the Icinga2 API Version
|
75
|
+
# @option settings [String] pki_path the location of the Certificate Files
|
76
|
+
# @option settings [String] node_name overwrite the Icnag2 hostname for the PKI. if the node_name no set, we try to resolve with gethostbyname()
|
71
77
|
#
|
72
78
|
# @example to create an new Instance
|
73
79
|
# config = {
|
@@ -119,16 +125,16 @@ module Icinga2
|
|
119
125
|
# create a HTTP Header based on a Icinga2 Certificate or an User API Login
|
120
126
|
#
|
121
127
|
# @param [Hash, #read] params
|
122
|
-
# @option params [String]
|
123
|
-
# @option params [String]
|
124
|
-
# @option params [String]
|
125
|
-
# @option params [String]
|
128
|
+
# @option params [String] pki_path the location of the Certificate Files
|
129
|
+
# @option params [String] node_name the Icinga2 Hostname
|
130
|
+
# @option params [String] user the Icinga2 API User
|
131
|
+
# @option params [String] password the Icinga2 API Password
|
126
132
|
#
|
127
133
|
# @example with Certificate
|
128
|
-
#
|
134
|
+
# cert?(pki_path: '/etc/icinga2', node_name: 'icinga2-dashing')
|
129
135
|
#
|
130
136
|
# @example with User
|
131
|
-
#
|
137
|
+
# cert?(username: 'root', password: 'icinga')
|
132
138
|
#
|
133
139
|
# @return [Array]
|
134
140
|
#
|
@@ -190,7 +196,7 @@ module Icinga2
|
|
190
196
|
# return Icinga2 Application data
|
191
197
|
#
|
192
198
|
# @example
|
193
|
-
#
|
199
|
+
# application_data
|
194
200
|
#
|
195
201
|
# @return [Hash]
|
196
202
|
#
|
@@ -203,6 +209,7 @@ module Icinga2
|
|
203
209
|
)
|
204
210
|
|
205
211
|
return nil if( data.nil? )
|
212
|
+
return nil unless(data.is_a?(Hash))
|
206
213
|
|
207
214
|
app_data = data.dig('icingaapplication','app')
|
208
215
|
|
@@ -219,7 +226,7 @@ module Icinga2
|
|
219
226
|
# return Icinga2 CIB
|
220
227
|
#
|
221
228
|
# @example
|
222
|
-
#
|
229
|
+
# cib_data
|
223
230
|
#
|
224
231
|
# @return [Hash]
|
225
232
|
#
|
@@ -278,7 +285,7 @@ module Icinga2
|
|
278
285
|
# return Icinga2 Status Data
|
279
286
|
#
|
280
287
|
# @example
|
281
|
-
#
|
288
|
+
# status_data
|
282
289
|
#
|
283
290
|
# @return [Hash]
|
284
291
|
#
|
@@ -296,7 +303,7 @@ module Icinga2
|
|
296
303
|
# return Icinga2 API Listener
|
297
304
|
#
|
298
305
|
# @example
|
299
|
-
#
|
306
|
+
# api_listener
|
300
307
|
#
|
301
308
|
# @return [Hash]
|
302
309
|
#
|
@@ -314,7 +321,7 @@ module Icinga2
|
|
314
321
|
# check the availability of a Icinga network connect
|
315
322
|
#
|
316
323
|
# @example
|
317
|
-
#
|
324
|
+
# available?
|
318
325
|
#
|
319
326
|
# @return [Bool]
|
320
327
|
#
|
@@ -330,9 +337,9 @@ module Icinga2
|
|
330
337
|
# return Icinga2 version and revision
|
331
338
|
#
|
332
339
|
# @example
|
333
|
-
#
|
340
|
+
# version.values
|
334
341
|
#
|
335
|
-
# v =
|
342
|
+
# v = version
|
336
343
|
# version = v.dig(:version)
|
337
344
|
#
|
338
345
|
# @return [Hash]
|
@@ -355,7 +362,7 @@ module Icinga2
|
|
355
362
|
# return Icinga2 node_name
|
356
363
|
#
|
357
364
|
# @example
|
358
|
-
#
|
365
|
+
# node_name
|
359
366
|
#
|
360
367
|
# @return [String]
|
361
368
|
#
|
@@ -371,7 +378,7 @@ module Icinga2
|
|
371
378
|
# return Icinga2 start time
|
372
379
|
#
|
373
380
|
# @example
|
374
|
-
#
|
381
|
+
# start_time
|
375
382
|
#
|
376
383
|
# @return [String]
|
377
384
|
#
|
@@ -387,8 +394,8 @@ module Icinga2
|
|
387
394
|
# return Icinga2 uptime
|
388
395
|
#
|
389
396
|
# @example
|
390
|
-
#
|
391
|
-
#
|
397
|
+
# cib_data
|
398
|
+
# uptime
|
392
399
|
#
|
393
400
|
# @return [String]
|
394
401
|
#
|
@@ -0,0 +1,312 @@
|
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Icinga2
|
5
|
+
|
6
|
+
# namespace for config packages
|
7
|
+
#
|
8
|
+
# The main idea behind configuration management is to allow external applications creating configuration packages and stages based on configuration files and directory trees.
|
9
|
+
#
|
10
|
+
# This replaces any additional SSH connection and whatnot to dump configuration files to Icinga 2 directly.
|
11
|
+
#
|
12
|
+
# In case you are pushing a new configuration stage to a package, Icinga 2 will validate the configuration asynchronously and populate a status log which can be fetched in a separated request.
|
13
|
+
#
|
14
|
+
# original API Documentation: https://www.icinga.com/docs/icinga2/latest/doc/12-icinga2-api/#configuration-management
|
15
|
+
#
|
16
|
+
module ConfigurationManagement
|
17
|
+
|
18
|
+
# create a new empty configuration package.
|
19
|
+
#
|
20
|
+
# Package names starting with an underscore are reserved for internal packages and can not be used.
|
21
|
+
#
|
22
|
+
# @param [String] name the name for the new package.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# create_config_package('cfg-package')
|
26
|
+
#
|
27
|
+
# @return [Hash]
|
28
|
+
#
|
29
|
+
def create_config_package(name)
|
30
|
+
|
31
|
+
raise ArgumentError.new(format('wrong type. \'name\' must be an String, given \'%s\'', name.class.to_s)) unless( name.is_a?(String) )
|
32
|
+
raise ArgumentError.new('missing \'name\'') if( name.size.zero? )
|
33
|
+
|
34
|
+
return { 'code' => 404, 'name' => name, 'status' => 'Package names starting with an underscore are reserved for internal packages and can not be used.' } if( name.initial == '_' )
|
35
|
+
|
36
|
+
post(
|
37
|
+
url: format( '%s/config/packages/%s', @icinga_api_url_base, name ),
|
38
|
+
headers: @headers,
|
39
|
+
options: @options
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Configuration files in packages are managed in stages.
|
44
|
+
# Stages provide a way to maintain multiple configuration versions for a package.
|
45
|
+
#
|
46
|
+
# @param [Hash] params
|
47
|
+
# @option params [String] package name of the package
|
48
|
+
# @option params [String] name name for the package
|
49
|
+
# @option params [Bool] cluser (false) package for an satellite
|
50
|
+
# @option params [Bool] reload (true) reload icinga2 after upload
|
51
|
+
# @option params [String] vars
|
52
|
+
#
|
53
|
+
# @example
|
54
|
+
# params = {
|
55
|
+
# package: 'cfg-package',
|
56
|
+
# name: 'host1',
|
57
|
+
# cluster: false,
|
58
|
+
# vars: 'object Host "cmdb-host" { chec_command = "dummy" }',
|
59
|
+
# reload: false
|
60
|
+
# }
|
61
|
+
# upload_config_package(params)
|
62
|
+
#
|
63
|
+
# @return [Hash]
|
64
|
+
#
|
65
|
+
def upload_config_package(params)
|
66
|
+
|
67
|
+
raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) )
|
68
|
+
raise ArgumentError.new('missing params') if( params.size.zero? )
|
69
|
+
|
70
|
+
package = validate( params, required: true, var: 'package', type: String )
|
71
|
+
name = validate( params, required: true, var: 'name', type: String )
|
72
|
+
cluster = validate( params, required: false, var: 'cluster', type: Boolean ) || false
|
73
|
+
vars = validate( params, required: false, var: 'vars', type: String )
|
74
|
+
reload = validate( params, required: false, var: 'reload', type: Boolean ) || true
|
75
|
+
name = name.gsub('.conf','')
|
76
|
+
|
77
|
+
return { 'code' => 404, 'status' => format('no package \'%s\' exists', package) } unless(package_exists?(package))
|
78
|
+
|
79
|
+
path = 'conf.d'
|
80
|
+
path = 'zones.d/satellite' if(cluster)
|
81
|
+
file = format( '%s/%s.conf', path, name )
|
82
|
+
|
83
|
+
payload = {
|
84
|
+
'files' => {
|
85
|
+
file.to_s => vars
|
86
|
+
},
|
87
|
+
'reload' => reload
|
88
|
+
}
|
89
|
+
|
90
|
+
post(
|
91
|
+
url: format( '%s/config/stages/%s', @icinga_api_url_base, package ),
|
92
|
+
headers: @headers,
|
93
|
+
options: @options,
|
94
|
+
payload: payload
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
# A list of packages.
|
99
|
+
#
|
100
|
+
# @example
|
101
|
+
# list_config_packages
|
102
|
+
#
|
103
|
+
# @return [Hash]
|
104
|
+
#
|
105
|
+
def list_config_packages
|
106
|
+
|
107
|
+
get(
|
108
|
+
url: format( '%s/config/packages', @icinga_api_url_base ),
|
109
|
+
headers: @headers,
|
110
|
+
options: @options
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
# A list of packages and their stages.
|
115
|
+
#
|
116
|
+
# @param [Hash] params
|
117
|
+
# @option params [String] package
|
118
|
+
# @option params [String] stage
|
119
|
+
#
|
120
|
+
# @example
|
121
|
+
# params = {
|
122
|
+
# package: 'cfg-package',
|
123
|
+
# stage: 'example.localdomain-1441625839-0'
|
124
|
+
# }
|
125
|
+
# list_config_stages(params)
|
126
|
+
#
|
127
|
+
# @return [Hash]
|
128
|
+
#
|
129
|
+
def list_config_stages(params)
|
130
|
+
|
131
|
+
raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) )
|
132
|
+
raise ArgumentError.new('missing params') if( params.size.zero? )
|
133
|
+
|
134
|
+
package = validate( params, required: true, var: 'package', type: String )
|
135
|
+
stage = validate( params, required: true, var: 'stage', type: String )
|
136
|
+
|
137
|
+
get(
|
138
|
+
url: format( '%s/config/stages/%s/%s', @icinga_api_url_base, package, stage ),
|
139
|
+
headers: @headers,
|
140
|
+
options: @options
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
# fetched the whole config package and return them as a String.
|
146
|
+
#
|
147
|
+
# @param [Hash] params
|
148
|
+
# @option params [String] package
|
149
|
+
# @option params [String] stage
|
150
|
+
# @option params [Bool] cluser (false) package for an satellite
|
151
|
+
# @option params [String] name
|
152
|
+
#
|
153
|
+
# @example
|
154
|
+
# params = {
|
155
|
+
# package: 'cfg-package',
|
156
|
+
# stage: 'example.localdomain-1441625839-0',
|
157
|
+
# name: 'host1',
|
158
|
+
# cluster: false
|
159
|
+
# }
|
160
|
+
# fetch_config_stages(params)
|
161
|
+
#
|
162
|
+
# @return [String]
|
163
|
+
#
|
164
|
+
def fetch_config_stages(params)
|
165
|
+
|
166
|
+
raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) )
|
167
|
+
raise ArgumentError.new('missing params') if( params.size.zero? )
|
168
|
+
|
169
|
+
package = validate( params, required: true, var: 'package', type: String )
|
170
|
+
stage = validate( params, required: true, var: 'stage', type: String )
|
171
|
+
name = validate( params, required: true, var: 'name', type: String )
|
172
|
+
cluster = validate( params, required: false, var: 'cluster', type: Boolean ) || false
|
173
|
+
name = name.gsub('.conf','')
|
174
|
+
|
175
|
+
return { 'code' => 404, 'status' => format('no package \'%s\' exists', package) } unless(package_exists?(package))
|
176
|
+
|
177
|
+
path = 'conf.d'
|
178
|
+
path = 'zones.d/satellite' if(cluster)
|
179
|
+
file = format( '%s/%s/%s/%s.conf', package, stage, path, name )
|
180
|
+
|
181
|
+
get(
|
182
|
+
url: format( '%s/config/files/%s', @icinga_api_url_base, file ),
|
183
|
+
headers: {},
|
184
|
+
options: @options
|
185
|
+
)
|
186
|
+
end
|
187
|
+
|
188
|
+
# fetch the startup.log from the named packe / stage combination to see possible errors.
|
189
|
+
#
|
190
|
+
# @param [Hash] params
|
191
|
+
# @option params [String] package
|
192
|
+
# @option params [String] stage
|
193
|
+
# @option params [Bool] cluser (false) package for an satellite
|
194
|
+
#
|
195
|
+
# @example
|
196
|
+
# params = {
|
197
|
+
# package: 'cfg-package',
|
198
|
+
# stage: 'example.localdomain-1441625839-0',
|
199
|
+
# cluster: false
|
200
|
+
# }
|
201
|
+
# package_stage_errors(params)
|
202
|
+
#
|
203
|
+
# @return [String]
|
204
|
+
#
|
205
|
+
def package_stage_errors(params)
|
206
|
+
|
207
|
+
raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) )
|
208
|
+
raise ArgumentError.new('missing params') if( params.size.zero? )
|
209
|
+
|
210
|
+
package = validate( params, required: true, var: 'package', type: String )
|
211
|
+
stage = validate( params, required: true, var: 'stage', type: String )
|
212
|
+
# cluster = validate( params, required: false, var: 'cluster', type: Boolean ) || false
|
213
|
+
|
214
|
+
return { 'code' => 404, 'status' => format('no package \'%s\' exists', package) } unless(package_exists?(package))
|
215
|
+
|
216
|
+
file = format( '%s/%s/startup.log', package, stage )
|
217
|
+
|
218
|
+
get(
|
219
|
+
url: format( '%s/config/files/%s', @icinga_api_url_base, file ),
|
220
|
+
headers: {},
|
221
|
+
options: @options
|
222
|
+
)
|
223
|
+
end
|
224
|
+
|
225
|
+
# Deleting Configuration Package Stage
|
226
|
+
#
|
227
|
+
# @param [Hash] params
|
228
|
+
# @option params [String] package
|
229
|
+
# @option params [String] stage
|
230
|
+
#
|
231
|
+
# @example
|
232
|
+
# params = {
|
233
|
+
# package: 'cfg-package',
|
234
|
+
# stage: 'example.localdomain-1441625839-0',
|
235
|
+
# cluster: false
|
236
|
+
# }
|
237
|
+
# remove_config_stage(params)
|
238
|
+
#
|
239
|
+
# @return [Hash]
|
240
|
+
#
|
241
|
+
def remove_config_stage(params)
|
242
|
+
|
243
|
+
raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) )
|
244
|
+
raise ArgumentError.new('missing params') if( params.size.zero? )
|
245
|
+
|
246
|
+
package = validate( params, required: true, var: 'package', type: String )
|
247
|
+
stage = validate( params, required: true, var: 'stage', type: String )
|
248
|
+
|
249
|
+
return { 'code' => 404, 'name' => package, 'status' => 'Package names starting with an underscore are reserved for internal packages and can not be used.' } if( package.initial == '_' )
|
250
|
+
return { 'code' => 404, 'status' => format('no package \'%s\' exists', name) } unless(package_exists?(package))
|
251
|
+
|
252
|
+
delete(
|
253
|
+
url: format( '%s/config/stages/%s/%s', @icinga_api_url_base, package, stage ),
|
254
|
+
headers: @headers,
|
255
|
+
options: @options
|
256
|
+
)
|
257
|
+
end
|
258
|
+
|
259
|
+
# Deleting Configuration Package
|
260
|
+
#
|
261
|
+
# @param [String] name the name for the package.
|
262
|
+
#
|
263
|
+
# @example
|
264
|
+
# remove_config_package('cfg-package')
|
265
|
+
#
|
266
|
+
# @return [Hash]
|
267
|
+
#
|
268
|
+
def remove_config_package(name)
|
269
|
+
|
270
|
+
raise ArgumentError.new(format('wrong type. \'name\' must be an String, given \'%s\'', name.class.to_s)) unless( name.is_a?(String) )
|
271
|
+
raise ArgumentError.new('missing \'name\'') if( name.size.zero? )
|
272
|
+
|
273
|
+
return { 'code' => 404, 'name' => name, 'status' => 'Package names starting with an underscore are reserved for internal packages and can not be used.' } if( name.initial == '_' )
|
274
|
+
return { 'code' => 404, 'status' => format('no package \'%s\' exists', name) } unless(package_exists?(name))
|
275
|
+
|
276
|
+
delete(
|
277
|
+
url: format( '%s/config/packages/%s', @icinga_api_url_base, name ),
|
278
|
+
headers: @headers,
|
279
|
+
options: @options
|
280
|
+
)
|
281
|
+
end
|
282
|
+
|
283
|
+
# check if a package exists
|
284
|
+
#
|
285
|
+
# @param [String] name the name for the package.
|
286
|
+
#
|
287
|
+
# @example
|
288
|
+
# package_exists?('cfg-package')
|
289
|
+
#
|
290
|
+
# @return [Bool]
|
291
|
+
#
|
292
|
+
def package_exists?(name)
|
293
|
+
|
294
|
+
raise ArgumentError.new(format('wrong type. \'name\' must be an String, given \'%s\'', name.class.to_s)) unless( name.is_a?(String) )
|
295
|
+
raise ArgumentError.new('missing \'name\'') if( name.size.zero? )
|
296
|
+
|
297
|
+
current_packages = list_config_packages
|
298
|
+
|
299
|
+
return { 'code' => 404, 'status' => 'error to get packages' } if( current_packages.nil? && current_packages.dig('code') != 200 )
|
300
|
+
|
301
|
+
current_packages = current_packages.dig('results')
|
302
|
+
|
303
|
+
data = current_packages.select { |k,_| k['name'] == name }
|
304
|
+
data = data.first if( data )
|
305
|
+
|
306
|
+
return false unless(data)
|
307
|
+
|
308
|
+
true
|
309
|
+
end
|
310
|
+
|
311
|
+
end
|
312
|
+
end
|