Skip to content
This repository was archived by the owner on Mar 27, 2021. It is now read-only.

Commit daee762

Browse files
committed
cleanup and refactor url monitor plugin
1 parent 23177dc commit daee762

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

lib/ragios/plugins/url_monitor.rb

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,23 @@ class UrlMonitor
88
attr_reader :test_result
99
attr_reader :url
1010
attr_reader :connection
11-
attr_reader :retry_limit
12-
attr_reader :connect_timeout
11+
attr_reader :options
1312

1413
def init(monitor)
14+
raise "A url must be provided for url_monitor in #{monitor[:monitor]} monitor" if monitor[:url].nil?
1515
@url = monitor[:url]
16-
@retry_limit = monitor[:retry_limit]
17-
@connect_timeout = monitor[:connect_timeout]
18-
raise "A url must be provided for url_monitor in #{monitor[:monitor]} monitor" if @url.nil?
19-
end
20-
21-
def test_command?
2216
@connection = Excon.new(@url)
23-
options = {
17+
@options = {
2418
expects: [200, 301, 302],
2519
method: :get,
2620
idempotent: true
2721
}
22+
@options[:retry_limit] = monitor[:retry_limit] || 3
23+
@options[:connect_timeout] = monitor[:connect_timeout] || 60
24+
end
2825

29-
options[:retry_limit] = @retry_limit || 3
30-
options[:connect_timeout] = @connect_timeout || 60
31-
response = @connection.request(options)
26+
def test_command?
27+
response = @connection.request(@options)
3228
@test_result = { "HTTP GET Request to #{@url}" => response.status }
3329
return true
3430
rescue => e

0 commit comments

Comments
 (0)