Class: Ragios::Plugins::UptimeMonitor
- Inherits:
-
Object
- Object
- Ragios::Plugins::UptimeMonitor
- Defined in:
- lib/uptime_monitor/uptime_monitor.rb
Instance Attribute Summary collapse
-
#browser_info ⇒ Object
readonly
Returns the value of attribute browser_info.
-
#has_screenshot ⇒ Object
readonly
Returns the value of attribute has_screenshot.
-
#monitor ⇒ Object
readonly
Returns the value of attribute monitor.
-
#s_expr ⇒ Object
readonly
Returns the value of attribute s_expr.
-
#screenshot_url ⇒ Object
readonly
Returns the value of attribute screenshot_url.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
-
#test_result ⇒ Object
readonly
Returns the value of attribute test_result.
-
#validations ⇒ Object
readonly
Returns the value of attribute validations.
Instance Method Summary collapse
- #close_browser ⇒ Object
- #exists(page_elements) ⇒ Object
- #init(monitor) ⇒ Object
-
#initialize ⇒ UptimeMonitor
constructor
A new instance of UptimeMonitor.
- #result!(validation, state) ⇒ Object
- #start_browser(url, browser_name, headless) ⇒ Object
- #take_screenshot ⇒ Object
- #test_command? ⇒ Boolean
Constructor Details
#initialize ⇒ UptimeMonitor
Returns a new instance of UptimeMonitor.
13 14 15 16 |
# File 'lib/uptime_monitor/uptime_monitor.rb', line 13 def initialize @result_set = [] @test_result = {results: @result_set} end |
Instance Attribute Details
#browser_info ⇒ Object (readonly)
Returns the value of attribute browser_info.
9 10 11 |
# File 'lib/uptime_monitor/uptime_monitor.rb', line 9 def browser_info @browser_info end |
#has_screenshot ⇒ Object (readonly)
Returns the value of attribute has_screenshot.
8 9 10 |
# File 'lib/uptime_monitor/uptime_monitor.rb', line 8 def has_screenshot @has_screenshot end |
#monitor ⇒ Object (readonly)
Returns the value of attribute monitor.
4 5 6 |
# File 'lib/uptime_monitor/uptime_monitor.rb', line 4 def monitor @monitor end |
#s_expr ⇒ Object (readonly)
Returns the value of attribute s_expr.
10 11 12 |
# File 'lib/uptime_monitor/uptime_monitor.rb', line 10 def s_expr @s_expr end |
#screenshot_url ⇒ Object (readonly)
Returns the value of attribute screenshot_url.
7 8 9 |
# File 'lib/uptime_monitor/uptime_monitor.rb', line 7 def screenshot_url @screenshot_url end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
6 7 8 |
# File 'lib/uptime_monitor/uptime_monitor.rb', line 6 def success @success end |
#test_result ⇒ Object (readonly)
Returns the value of attribute test_result.
5 6 7 |
# File 'lib/uptime_monitor/uptime_monitor.rb', line 5 def test_result @test_result end |
#validations ⇒ Object (readonly)
Returns the value of attribute validations.
11 12 13 |
# File 'lib/uptime_monitor/uptime_monitor.rb', line 11 def validations @validations end |
Instance Method Details
#close_browser ⇒ Object
51 52 53 |
# File 'lib/uptime_monitor/uptime_monitor.rb', line 51 def close_browser @browser.close if @browser.respond_to?('close') end |
#exists(page_elements) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/uptime_monitor/uptime_monitor.rb', line 59 def exists(page_elements) for i in 0..(page_elements.length - 1) if @browser.exists?(page_elements[i]) result!(@validations[i], true) else take_screenshot result!(@validations[i], false) end end end |
#init(monitor) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/uptime_monitor/uptime_monitor.rb', line 18 def init(monitor) @monitor = OpenStruct.new(monitor) = "A url must be provided for uptime_monitor: #{@monitor.monitor}" raise(Hercules::UptimeMonitor::NoUrlProvided.new(error: ), ) if @monitor.url.nil? = "A browser must be provided for uptime_monitor: #{@monitor.monitor}" raise(Hercules::UptimeMonitor::NoBrowserProvided.new(error: ), ) if @monitor.browser.nil? @browser_info = Hercules::UptimeMonitor::BrowsersLangParser.new.parse(@monitor.browser) = "A validation (exists?) must be provided for uptime_monitor: #{@monitor.monitor}" raise(Hercules::UptimeMonitor::NoValidationProvided.new(error: ), ) if @monitor.exists?.nil? @s_expr = Hercules::UptimeMonitor::MaestroLangParser.new.parse(@monitor.exists?) @validations = Hercules::UptimeMonitor::MaestroLangParser.new.parse(@monitor.exists?, description = true) {ok: true} end |
#result!(validation, state) ⇒ Object
70 71 72 73 74 |
# File 'lib/uptime_monitor/uptime_monitor.rb', line 70 def result!(validation, state) @success = false if state == false result = state ? [validation, "exists_as_expected"] : [validation, "does_not_exist_as_expected"] @result_set << result end |
#start_browser(url, browser_name, headless) ⇒ Object
55 56 57 |
# File 'lib/uptime_monitor/uptime_monitor.rb', line 55 def start_browser(url, browser_name, headless) @browser = Hercules::UptimeMonitor::Browser.new(url, browser_name, headless) end |
#take_screenshot ⇒ Object
76 77 78 79 80 81 |
# File 'lib/uptime_monitor/uptime_monitor.rb', line 76 def take_screenshot if RAGIOS_HERCULES_ENABLE_SCREENSHOTS && not(@monitor.disable_screenshots) && not(@has_screenshot) @screenshot_url = @browser.capture_screenshot @has_screenshot = true end end |
#test_command? ⇒ Boolean
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/uptime_monitor/uptime_monitor.rb', line 32 def test_command? @result_set = [] @success = true @has_screenshot = false start_browser(@monitor.url, browser_info[:browser], !!browser_info[:headless] ) exists(@s_expr) @test_result = {results: @result_set} @test_result[:screenshot] = @screenshot_url if @has_screenshot close_browser @success rescue Net::ReadTimeout => e close_browser rescue nil @test_result = {results: ["Page Load Timeout", "Page could not load after 2 minutes"]} return true rescue Exception => e close_browser rescue nil raise e end |