smart_proxy_monitoring 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +60 -28
- data/lib/smart_proxy_monitoring/monitoring_api.rb +21 -42
- data/lib/smart_proxy_monitoring/monitoring_plugin.rb +2 -0
- data/lib/smart_proxy_monitoring/version.rb +1 -1
- data/lib/smart_proxy_monitoring_common/monitoring_common.rb +1 -0
- data/lib/smart_proxy_monitoring_icinga2/icinga2_result_uploader.rb +2 -2
- data/lib/smart_proxy_monitoring_icinga2/monitoring_icinga2_main.rb +11 -4
- data/lib/smart_proxy_monitoring_icinga2/monitoring_icinga2_plugin.rb +5 -0
- data/lib/smart_proxy_monitoring_icingadirector/director_client.rb +21 -4
- data/lib/smart_proxy_monitoring_icingadirector/monitoring_icingadirector_plugin.rb +3 -0
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e366cc37c357a3178a8d28262e1b177a384296778987df9b7107fb400a22dfae
|
4
|
+
data.tar.gz: 6f38e4e49c70adc11feee5bf495c00650dbe5aaf7f5187a5dca31e1c80edbc3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbfbf8d19457f374c487630507cfd867aed6726bc3d84396e31596b648c26e047bc8ccf084d801edba5ea9667e3c17fb609f2cce47d6e033cf7c036c0c3df286
|
7
|
+
data.tar.gz: 846663a2a6aaee48323920970a3199326d888f45918ac575808699267f6b1af11181d3bd2d4f71db8bc5efb79aab13bc11a0798b02a540a014df04776cf1b13f
|
data/README.md
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# Smart Proxy - Monitoring
|
2
2
|
|
3
3
|
This plug-in adds support for Monitoring to Foreman's Smart Proxy.
|
4
|
-
It requires
|
4
|
+
It also requires the Foreman Monitoring plug-in.
|
5
5
|
|
6
6
|
# Installation
|
7
7
|
|
8
8
|
Please see the Foreman manual for appropriate instructions:
|
9
9
|
|
10
|
-
* [Foreman: How to Install a Plugin](http://theforeman.org/
|
10
|
+
* [Foreman: How to Install a Proxy Plugin](http://projects.theforeman.org/projects/foreman/wiki/How_to_Install_a_Smart-Proxy_Plugin)
|
11
11
|
|
12
12
|
The gem name is `smart_proxy_monitoring`.
|
13
13
|
|
14
14
|
RPM users can install the `rubygem-smart_proxy_monitoring` packages.
|
15
15
|
|
16
|
-
|
16
|
+
Deb users can install the `ruby-smart-proxy-monitoring` packages.
|
17
17
|
|
18
18
|
# Configuration
|
19
19
|
|
20
20
|
The plug-in requires some configuration on the Monitoring server and the Smart Proxy.
|
21
|
-
For now the only supported Monitoring solution is Icinga 2 and the combination of Icinga 2
|
21
|
+
For now, the only supported Monitoring solution is Icinga 2 and the combination of Icinga 2
|
22
22
|
and the Icinga Web 2 Module Director.
|
23
23
|
|
24
24
|
## Icinga 2
|
@@ -31,7 +31,7 @@ The required steps for connecting the Smart Proxy and Icinga 2 will be found bel
|
|
31
31
|
|
32
32
|
### Monitoring Server
|
33
33
|
|
34
|
-
On the Monitoring Server you have to enable the API and create API User.
|
34
|
+
On the Monitoring Server, you have to enable the API and create API User.
|
35
35
|
|
36
36
|
For testing the fastest way to setup this will be the following commands.
|
37
37
|
|
@@ -40,12 +40,12 @@ For testing the fastest way to setup this will be the following commands.
|
|
40
40
|
# systemctl restart icinga2.service
|
41
41
|
```
|
42
42
|
|
43
|
-
This will create the
|
43
|
+
This will create the certificates, enable the API feature and create and API User `root` with
|
44
44
|
a random password. The configuration of the API User will be located in `/etc/icinga2/conf.d/api-users.conf`.
|
45
45
|
|
46
46
|
More detailed instructions:
|
47
47
|
|
48
|
-
To enable the API follow the next steps
|
48
|
+
To enable the API, follow the next steps if the API is already enabled skip this steps
|
49
49
|
and start by creating an API User. The API will already be enabled if you use the Icingaweb 2
|
50
50
|
Module Director for configuration, Icinga 2 as Agents or in a distributed or high-available
|
51
51
|
setup.
|
@@ -60,9 +60,12 @@ To create Icinga 2's own CA run:
|
|
60
60
|
# icinga2 pki new-ca
|
61
61
|
```
|
62
62
|
|
63
|
-
Afterwards copy the CA certificate to Icinga 2's
|
63
|
+
Afterwards copy the CA certificate to Icinga 2's PKI directory (depending on installation
|
64
|
+
source and platform you have to create the PKI directory first with write permissions for the
|
65
|
+
user Icinga 2 is running with, typically `icinga` or `nagios`):
|
64
66
|
|
65
67
|
```
|
68
|
+
# install -o icinga -g icinga -m 0775 -d /etc/icinga2/pki
|
66
69
|
# cp /var/lib/icinga2/ca/ca.crt /etc/icinga2/pki/
|
67
70
|
```
|
68
71
|
|
@@ -78,7 +81,7 @@ And then sign the certficate request to get a certificate by executing:
|
|
78
81
|
# icinga2 pki sign-csr --csr /etc/icinga2/pki/$(hostname -f).csr --cert /etc/icinga2/pki/$(hostname -f).crt
|
79
82
|
```
|
80
83
|
|
81
|
-
With the certificates created and placed in Icinga 2's
|
84
|
+
With the certificates created and placed in Icinga 2's PKI directory, you can enable the API feature.
|
82
85
|
|
83
86
|
```
|
84
87
|
# icinga2 feature enable api
|
@@ -86,7 +89,7 @@ With the certificates created and placed in Icinga 2's pki directory you can ena
|
|
86
89
|
```
|
87
90
|
|
88
91
|
To allow API connections you have to create an API User. You should name him according to the use case,
|
89
|
-
so instructions will create
|
92
|
+
so instructions will create a user named `foreman`.
|
90
93
|
|
91
94
|
Password authentication is easier to setup, but certificate-based authentication is more secure.
|
92
95
|
|
@@ -115,8 +118,8 @@ object ApiUser "foreman" {
|
|
115
118
|
# icinga2 pki sign-csr --csr /etc/icinga2/pki/foreman.csr --cert /etc/icinga2/pki/foreman.crt
|
116
119
|
```
|
117
120
|
|
118
|
-
In addition to the authentication a Host template is required. By default it uses "foreman-host" if none
|
119
|
-
is provided
|
121
|
+
In addition to the authentication, a Host template is required. By default, it uses "foreman-host" if none
|
122
|
+
is provided at the Foreman WebUI. This template should define defaults for the host check and intervals.
|
120
123
|
|
121
124
|
```
|
122
125
|
# vi /etc/icinga2/conf.d/templates.conf
|
@@ -138,13 +141,13 @@ template Host "foreman-host" {
|
|
138
141
|
|
139
142
|
Ensure that the Monitoring module is enabled and uses the provider monitoring_icinga2.
|
140
143
|
It is the default provider so also no setting for use_provider is fine.
|
141
|
-
If you configured hosts in Icinga2 only with hostname instead of FQDN, you can add `:strip_domain` with
|
144
|
+
If you configured hosts in Icinga2 only with the hostname instead of the FQDN, you can add `:strip_domain` with
|
142
145
|
all the parts to strip, e.g. `.localdomain`.
|
143
146
|
By default, SmartProxy will collect monitoring statuses from your monitoring solution and upload them to
|
144
147
|
Foreman. This can be disabled by setting `collect_status` to `false`.
|
145
148
|
|
146
149
|
```
|
147
|
-
# vi /etc/foreman-proxy/settings.d/monitoring.
|
150
|
+
# vi /etc/foreman-proxy/settings.d/monitoring.yml
|
148
151
|
---
|
149
152
|
:enabled: true
|
150
153
|
:use_provider: monitoring_icinga2
|
@@ -157,7 +160,7 @@ in /etc/icinga2/pki/) and provide the authentication details of the API User. If
|
|
157
160
|
instead of the FQDN of the server, you will have to set verify_ssl to false.
|
158
161
|
|
159
162
|
```
|
160
|
-
# vi /etc/foreman-proxy/settings.d/monitoring_icinga2.
|
163
|
+
# vi /etc/foreman-proxy/settings.d/monitoring_icinga2.yml
|
161
164
|
---
|
162
165
|
:enabled: true
|
163
166
|
:server: icinga2.localdomain
|
@@ -170,26 +173,36 @@ instead of the FQDN of the server, you will have to set verify_ssl to false.
|
|
170
173
|
:verify_ssl: true
|
171
174
|
```
|
172
175
|
|
176
|
+
Afterwards, restart the service.
|
177
|
+
|
178
|
+
```
|
179
|
+
# systemctl restart foreman-proxy.service
|
180
|
+
```
|
181
|
+
|
173
182
|
## Icinga 2 and Icinga Web 2 Module Director
|
174
183
|
|
175
184
|
This requires you to do the configuration steps above so
|
176
|
-
Downtimes
|
185
|
+
Downtimes can be sent to Foreman and Status information can be
|
177
186
|
read from Icinga 2.
|
178
187
|
|
179
|
-
In addition you have to configure the provider Icingadirector
|
180
|
-
for managing hosts in the Icinga Web 2 Module Director.
|
188
|
+
In addition, you have to configure the provider Icingadirector
|
189
|
+
for managing hosts in the Icinga Web 2 Module Director. This
|
190
|
+
graphical configuration frontend for Icinga 2 will allow you
|
191
|
+
to customize the host, e.g. adding additional required objects
|
192
|
+
for using Icinga 2 as a monitoring agent or assign more attributes
|
193
|
+
and services. By default, it requires a template named `foreman-host`.
|
181
194
|
|
182
195
|
### Icinga Web 2 Module Director
|
183
196
|
|
184
197
|
Using the API of the Icinga Web 2 Module Director requires
|
185
|
-
Authentication and Authorisation
|
198
|
+
Authentication and Authorisation as it is described in the
|
186
199
|
[documentation](https://github.com/Icinga/icingaweb2-module-director/blob/master/doc/70-REST-API.md).
|
187
200
|
|
188
|
-
For the basic authentication of the webserver there are two
|
201
|
+
For the basic authentication of the webserver, there are two
|
189
202
|
possible ways of configuration. If you already use basic auth
|
190
203
|
simply add a user and password to the authentication source.
|
191
204
|
If you do not want to add basic authentication you can configure
|
192
|
-
the webserver to auto login as a user depending on your source
|
205
|
+
the webserver to auto login as a user depending on your source IP.
|
193
206
|
```
|
194
207
|
# vi /etc/httpd/conf.d/icingaweb2.conf
|
195
208
|
...
|
@@ -200,16 +213,16 @@ RewriteRule ^(.*)$ - [E=REMOTE_USER:foreman]
|
|
200
213
|
```
|
201
214
|
|
202
215
|
In Icinga Web 2 you also have to add an authentication backend
|
203
|
-
|
216
|
+
`external`.
|
204
217
|
```
|
205
218
|
# vi /etc/icingaweb2/authentication.ini
|
206
219
|
[External]
|
207
220
|
backend = "external"
|
208
221
|
```
|
209
222
|
|
210
|
-
Furthermore a role is required assigning permissions to your user.
|
223
|
+
Furthermore, a role is required assigning permissions to your user.
|
211
224
|
```
|
212
|
-
# vi /etc/icingaweb2/roles.ini
|
225
|
+
# vi /etc/icingaweb2/roles.ini
|
213
226
|
[Foreman]
|
214
227
|
users = "foreman"
|
215
228
|
permissions = "module/director, director/api, director/*"
|
@@ -217,13 +230,13 @@ permissions = "module/director, director/api, director/*"
|
|
217
230
|
|
218
231
|
### Smart Proxy
|
219
232
|
|
220
|
-
Ensure that the Monitoring module is enabled and uses the provider monitoring_icinga2
|
221
|
-
and monitoring_icingadirector
|
233
|
+
Ensure that the Monitoring module is enabled and uses the provider `monitoring_icinga2`
|
234
|
+
and `monitoring_icingadirector`.
|
222
235
|
```
|
223
|
-
# vi /etc/foreman-proxy/settings.d/monitoring.
|
236
|
+
# vi /etc/foreman-proxy/settings.d/monitoring.yml
|
224
237
|
---
|
225
238
|
:enabled: true
|
226
|
-
:use_provider:
|
239
|
+
:use_provider:
|
227
240
|
- monitoring_icinga2
|
228
241
|
- monitoring_icingadirector
|
229
242
|
```
|
@@ -242,6 +255,25 @@ but not required.
|
|
242
255
|
:verify_ssl: true
|
243
256
|
```
|
244
257
|
|
258
|
+
Afterwards, restart the service.
|
259
|
+
|
260
|
+
```
|
261
|
+
# systemctl restart foreman-proxy.service
|
262
|
+
```
|
263
|
+
|
264
|
+
# Troubleshooting
|
265
|
+
|
266
|
+
The plug-in uses the configuration of the Smart Proxy to write its logs and does
|
267
|
+
not provide a separate log for now. So have a look into `/var/log/foreman-proxy/proxy.log`
|
268
|
+
for default installations.
|
269
|
+
|
270
|
+
Also look into the logs of the monitoring solution and when opening issues attach relevant entries
|
271
|
+
for both logs. For Icinga 2 it is typically `/var/log/icinga2/icinga2.log` or if enabled
|
272
|
+
`/var/log/icinga2/debug.log`. Icinga Web 2 Director uses Icinga Web 2's configuration
|
273
|
+
which is typically logging to syslog with facility `user` and application prefix `icingaweb2`
|
274
|
+
which will result in a logging entry in `/var/log/message` for osfamily Red Hat and `/var/log/syslog`
|
275
|
+
for osfamily Debian.
|
276
|
+
|
245
277
|
# TODO
|
246
278
|
|
247
279
|
Provider Icinga2:
|
@@ -13,67 +13,43 @@ module Proxy::Monitoring
|
|
13
13
|
authorize_with_ssl_client
|
14
14
|
|
15
15
|
get '/host/:host' do |host|
|
16
|
-
|
16
|
+
log_provider_errors do
|
17
17
|
validate_dns_name!(host)
|
18
18
|
host = strip_domain(host)
|
19
19
|
|
20
20
|
server.query_host(host).to_json
|
21
|
-
rescue Proxy::Monitoring::NotFound => e
|
22
|
-
log_halt 404, e
|
23
|
-
rescue Proxy::Monitoring::ConnectionError => e
|
24
|
-
log_halt 503, e
|
25
|
-
rescue Exception => e
|
26
|
-
log_halt 400, e
|
27
21
|
end
|
28
22
|
end
|
29
23
|
|
30
24
|
put '/host/:host' do |host|
|
31
|
-
|
25
|
+
log_provider_errors do
|
32
26
|
validate_dns_name!(host)
|
33
27
|
host = strip_domain(host)
|
34
28
|
attributes = params[:attributes]
|
35
29
|
logger.debug "Creating host #{host} object with attributes #{attributes.inspect}"
|
36
30
|
|
37
31
|
server.create_host(host, attributes)
|
38
|
-
rescue Proxy::Monitoring::NotFound => e
|
39
|
-
log_halt 404, e
|
40
|
-
rescue Proxy::Monitoring::ConnectionError => e
|
41
|
-
log_halt 503, e
|
42
|
-
rescue Exception => e
|
43
|
-
log_halt 400, e
|
44
32
|
end
|
45
33
|
end
|
46
34
|
|
47
35
|
post '/host/:host' do |host|
|
48
|
-
|
36
|
+
log_provider_errors do
|
49
37
|
validate_dns_name!(host)
|
50
38
|
host = strip_domain(host)
|
51
39
|
attributes = params[:attributes]
|
52
40
|
logger.debug "Updating host #{host} object with attributes #{attributes.inspect}"
|
53
41
|
|
54
42
|
server.update_host(host, attributes)
|
55
|
-
rescue Proxy::Monitoring::NotFound => e
|
56
|
-
log_halt 404, e
|
57
|
-
rescue Proxy::Monitoring::ConnectionError => e
|
58
|
-
log_halt 503, e
|
59
|
-
rescue Exception => e
|
60
|
-
log_halt 400, e
|
61
43
|
end
|
62
44
|
end
|
63
45
|
|
64
46
|
delete '/host/:host' do |host|
|
65
|
-
|
47
|
+
log_provider_errors do
|
66
48
|
validate_dns_name!(host)
|
67
49
|
host = strip_domain(host)
|
68
50
|
logger.debug "Removing host #{host} object"
|
69
51
|
|
70
52
|
server.remove_host(host)
|
71
|
-
rescue Proxy::Monitoring::NotFound => e
|
72
|
-
log_halt 404, e
|
73
|
-
rescue Proxy::Monitoring::ConnectionError => e
|
74
|
-
log_halt 503, e
|
75
|
-
rescue Exception => e
|
76
|
-
log_halt 400, e
|
77
53
|
end
|
78
54
|
end
|
79
55
|
|
@@ -82,18 +58,15 @@ module Proxy::Monitoring
|
|
82
58
|
comment = params[:comment] || 'triggered by foreman'
|
83
59
|
start_time = params[:start_time] || Time.now.to_i
|
84
60
|
end_time = params[:end_time] || (Time.now.to_i + (24 * 3600))
|
61
|
+
all_services = params[:all_services]
|
85
62
|
|
86
|
-
|
63
|
+
log_provider_errors do
|
87
64
|
validate_dns_name!(host)
|
88
65
|
host = strip_domain(host)
|
89
66
|
|
67
|
+
server.set_downtime_host(host, author, comment, start_time, end_time, all_services: all_services)
|
68
|
+
rescue ArgumentError
|
90
69
|
server.set_downtime_host(host, author, comment, start_time, end_time)
|
91
|
-
rescue Proxy::Monitoring::NotFound => e
|
92
|
-
log_halt 404, e
|
93
|
-
rescue Proxy::Monitoring::ConnectionError => e
|
94
|
-
log_halt 503, e
|
95
|
-
rescue Exception => e
|
96
|
-
log_halt 400, e
|
97
70
|
end
|
98
71
|
end
|
99
72
|
|
@@ -101,20 +74,26 @@ module Proxy::Monitoring
|
|
101
74
|
author = params[:author] || 'foreman'
|
102
75
|
comment = params[:comment] || 'triggered by foreman'
|
103
76
|
|
104
|
-
|
77
|
+
log_provider_errors do
|
105
78
|
validate_dns_name!(host)
|
106
79
|
host = strip_domain(host)
|
107
80
|
|
108
81
|
server.remove_downtime_host(host, author, comment)
|
109
|
-
rescue Proxy::Monitoring::NotFound => e
|
110
|
-
log_halt 404, e
|
111
|
-
rescue Proxy::Monitoring::ConnectionError => e
|
112
|
-
log_halt 503, e
|
113
|
-
rescue Exception => e
|
114
|
-
log_halt 400, e
|
115
82
|
end
|
116
83
|
end
|
117
84
|
|
85
|
+
def log_provider_errors
|
86
|
+
yield
|
87
|
+
rescue Proxy::Monitoring::NotFound => e
|
88
|
+
log_halt 404, e
|
89
|
+
rescue Proxy::Monitoring::ConnectionError => e
|
90
|
+
log_halt 503, e
|
91
|
+
rescue Proxy::Monitoring::AuthenticationError => e
|
92
|
+
log_halt 500, e
|
93
|
+
rescue Exception => e
|
94
|
+
log_halt 400, e
|
95
|
+
end
|
96
|
+
|
118
97
|
def validate_dns_name!(name)
|
119
98
|
raise Proxy::Monitoring::Error.new("Invalid DNS name #{name}") unless name =~ /^([a-zA-Z0-9]([-a-zA-Z0-9]+)?\.?)+$/
|
120
99
|
end
|
@@ -11,6 +11,8 @@ module Proxy::Monitoring
|
|
11
11
|
uses_provider
|
12
12
|
default_settings use_provider: 'monitoring_icinga2'
|
13
13
|
default_settings collect_status: true
|
14
|
+
expose_setting :collect_status
|
15
|
+
expose_setting :strip_domain
|
14
16
|
|
15
17
|
http_rackup_path File.expand_path('monitoring_http_config.ru', File.expand_path('../', __FILE__))
|
16
18
|
https_rackup_path File.expand_path('monitoring_http_config.ru', File.expand_path('../', __FILE__))
|
@@ -3,7 +3,7 @@ require 'thread'
|
|
3
3
|
module ::Proxy::Monitoring::Icinga2
|
4
4
|
class MonitoringResult < Proxy::HttpRequest::ForemanRequest
|
5
5
|
def push_result(result)
|
6
|
-
send_request(request_factory.create_post('api/monitoring_results', result))
|
6
|
+
send_request(request_factory.create_post('api/v2/monitoring_results', result))
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
@@ -39,7 +39,7 @@ module ::Proxy::Monitoring::Icinga2
|
|
39
39
|
transformed = { result: change[:check_result][:state] }
|
40
40
|
when 'AcknowledgementSet'
|
41
41
|
transformed = { acknowledged: true }
|
42
|
-
when '
|
42
|
+
when 'AcknowledgementCleared'
|
43
43
|
transformed = { acknowledged: false }
|
44
44
|
when 'DowntimeTriggered'
|
45
45
|
transformed = { downtime: true }
|
@@ -49,7 +49,7 @@ module Proxy::Monitoring::Icinga2
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def remove_downtime_host(host, author, comment)
|
52
|
-
request_url = "/actions/remove-downtime?type=Host&filter
|
52
|
+
request_url = "/actions/remove-downtime?type=Host&filter=#{uri_encode_filter("host.name==\"#{host}\"\&\&author==\"#{author}\"\&\&comment=\"#{comment}\"")}"
|
53
53
|
data = {}
|
54
54
|
|
55
55
|
result = with_errorhandling("Remove downtime from #{host}") do
|
@@ -58,8 +58,8 @@ module Proxy::Monitoring::Icinga2
|
|
58
58
|
result.to_json
|
59
59
|
end
|
60
60
|
|
61
|
-
def set_downtime_host(host, author, comment, start_time, end_time)
|
62
|
-
request_url = "/actions/schedule-downtime?type=Host&filter
|
61
|
+
def set_downtime_host(host, author, comment, start_time, end_time, all_services: nil, **)
|
62
|
+
request_url = "/actions/schedule-downtime?type=Host&filter=#{uri_encode_filter("host.name==\"#{host}\"")}"
|
63
63
|
data = {
|
64
64
|
'author' => author,
|
65
65
|
'comment' => comment,
|
@@ -67,6 +67,7 @@ module Proxy::Monitoring::Icinga2
|
|
67
67
|
'end_time' => end_time,
|
68
68
|
'duration' => 1000
|
69
69
|
}
|
70
|
+
data['all_services'] = all_services unless all_services.nil?
|
70
71
|
|
71
72
|
result = with_errorhandling("Set downtime on #{host}") do
|
72
73
|
Icinga2Client.post(request_url, data.to_json)
|
@@ -76,6 +77,10 @@ module Proxy::Monitoring::Icinga2
|
|
76
77
|
|
77
78
|
private
|
78
79
|
|
80
|
+
def uri_encode_filter(filter)
|
81
|
+
URI.encode(filter)
|
82
|
+
end
|
83
|
+
|
79
84
|
def host_attributes(host, data)
|
80
85
|
attributes = {}
|
81
86
|
|
@@ -130,7 +135,9 @@ module Proxy::Monitoring::Icinga2
|
|
130
135
|
result
|
131
136
|
rescue JSON::ParserError => e
|
132
137
|
raise Proxy::Monitoring::Error.new("Icinga server at #{::Proxy::Monitoring::Icinga2::Plugin.settings.server} returned invalid JSON: '#{e.message}'")
|
133
|
-
rescue RestClient::
|
138
|
+
rescue RestClient::Unauthorized => e
|
139
|
+
raise Proxy::Monitoring::AuthenticationError.new("Error authenicating to Icinga server at #{::Proxy::Monitoring::Icinga2::Plugin.settings.server}: #{e.message}.")
|
140
|
+
rescue RestClient::ResourceNotFound => e
|
134
141
|
raise Proxy::Monitoring::NotFound.new("Icinga server at #{::Proxy::Monitoring::Icinga2::Plugin.settings.server} returned: #{e.message}.")
|
135
142
|
rescue RestClient::Exception => e
|
136
143
|
raise Proxy::Monitoring::Error.new("Icinga server at #{::Proxy::Monitoring::Icinga2::Plugin.settings.server} returned an error: '#{e.response}'")
|
@@ -5,6 +5,11 @@ module ::Proxy::Monitoring::Icinga2
|
|
5
5
|
default_settings server: 'localhost'
|
6
6
|
default_settings api_port: '5665'
|
7
7
|
default_settings verify_ssl: true
|
8
|
+
expose_setting :server
|
9
|
+
expose_setting :api_user
|
10
|
+
capability("config")
|
11
|
+
capability("downtime")
|
12
|
+
capability("status") unless Proxy::Monitoring::Plugin.settings.collect_status
|
8
13
|
|
9
14
|
requires :monitoring, ::Proxy::Monitoring::VERSION
|
10
15
|
|
@@ -23,25 +23,29 @@ module ::Proxy::Monitoring::IcingaDirector
|
|
23
23
|
def get(url)
|
24
24
|
logger.debug "IcingaDirector: GET request to #{url}"
|
25
25
|
client(url).get.body
|
26
|
-
rescue
|
27
|
-
raise
|
26
|
+
rescue StandardError => e
|
27
|
+
raise handle_http_exception(e, url)
|
28
28
|
end
|
29
29
|
|
30
30
|
def post(url, payload)
|
31
31
|
logger.debug "IcingaDirector: POST request to #{url} with payload: #{payload}"
|
32
32
|
client(url).post(payload).body
|
33
|
+
rescue StandardError => e
|
34
|
+
raise handle_http_exception(e, url)
|
33
35
|
end
|
34
36
|
|
35
37
|
def put(url, payload)
|
36
38
|
logger.debug "IcingaDirector: PUT request to #{url} with payload: #{payload}"
|
37
39
|
client(url).put(payload).body
|
40
|
+
rescue StandardError => e
|
41
|
+
raise handle_http_exception(e, url)
|
38
42
|
end
|
39
43
|
|
40
44
|
def delete(url)
|
41
45
|
logger.debug "IcingaDirector: DELETE request to #{url}"
|
42
46
|
client(url).delete.body
|
43
|
-
rescue
|
44
|
-
raise
|
47
|
+
rescue StandardError => e
|
48
|
+
raise handle_http_exception(e, url)
|
45
49
|
end
|
46
50
|
|
47
51
|
private
|
@@ -72,6 +76,19 @@ module ::Proxy::Monitoring::IcingaDirector
|
|
72
76
|
}
|
73
77
|
end
|
74
78
|
|
79
|
+
def handle_http_exception(e, url)
|
80
|
+
case e
|
81
|
+
when RestClient::ResourceNotFound
|
82
|
+
Proxy::Monitoring::NotFound.new("Icinga Director returned not found for #{request_url(url)}.")
|
83
|
+
when RestClient::Unauthorized
|
84
|
+
Proxy::Monitoring::AuthenticationError.new("Error authenicating to Icinga Director at #{request_url(url)}: #{e.message}")
|
85
|
+
when RestClient::NotModified
|
86
|
+
raise
|
87
|
+
else
|
88
|
+
Proxy::Monitoring::Error.new("Error connecting to Icinga Director at #{request_url(url)}: #{e.message}")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
75
92
|
def baseurl
|
76
93
|
Proxy::Monitoring::IcingaDirector::Plugin.settings.director_url + '/'
|
77
94
|
end
|
@@ -3,6 +3,9 @@ module ::Proxy::Monitoring::IcingaDirector
|
|
3
3
|
plugin :monitoring_icingadirector, ::Proxy::Monitoring::VERSION
|
4
4
|
|
5
5
|
default_settings verify_ssl: true
|
6
|
+
expose_setting :director_url
|
7
|
+
expose_setting :director_user
|
8
|
+
capability("config")
|
6
9
|
|
7
10
|
requires :monitoring, ::Proxy::Monitoring::VERSION
|
8
11
|
requires :monitoring_icinga2, ::Proxy::Monitoring::VERSION
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_proxy_monitoring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timo Goebel
|
8
8
|
- Dirk Goetz
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-05-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -121,11 +121,11 @@ files:
|
|
121
121
|
- settings.d/monitoring.yml.example
|
122
122
|
- settings.d/monitoring_icinga2.yml.example
|
123
123
|
- settings.d/monitoring_icingadirector.yml.example
|
124
|
-
homepage:
|
124
|
+
homepage: https://github.com/theforeman/smart_proxy_monitoring
|
125
125
|
licenses:
|
126
|
-
-
|
126
|
+
- GPL-3.0
|
127
127
|
metadata: {}
|
128
|
-
post_install_message:
|
128
|
+
post_install_message:
|
129
129
|
rdoc_options: []
|
130
130
|
require_paths:
|
131
131
|
- lib
|
@@ -140,9 +140,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
|
-
|
144
|
-
|
145
|
-
signing_key:
|
143
|
+
rubygems_version: 3.2.22
|
144
|
+
signing_key:
|
146
145
|
specification_version: 4
|
147
146
|
summary: Monitoring plug-in for Foreman's smart proxy
|
148
147
|
test_files: []
|