<commit_before># Plugin: Monitors a URL by sending a http GET request to it
# the test PASSES if it gets a HTTP 200, 301 or 302 Response status code from the http request

module Ragios
  module Plugin

    class UrlMonitor
      attr_reader :test_result
      attr_reader :url
      attr_reader :connection
      attr_reader :retry_limit
      attr_reader :connect_timeout

      def init(monitor)
        @url = monitor[:url]
        @retry_limit = monitor[:retry_limit]
        @connect_timeout = monitor[:connect_timeout]
        raise "A url must be provided for url_monitor in #{monitor[:monitor]} monitor" if @url.nil?
      end

      def test_command?
        @connection = Excon.new(@url)
        options = {
          expects: [200, 301, 302],
          method: :get,
          idempotent: true
        }

        options[:retry_limit] = @retry_limit || 3
        options[:connect_timeout] = @connect_timeout || 60
        response = @connection.request(options)
        @test_result = { "HTTP GET Request to #{@url}" => response.status }
        return true
      rescue => e
        @test_result = { "HTTP GET Request to #{@url}" => e.message }
        return false
      end
    end
  end
end<commit_msg>cleanup and refactor url monitor plugin<commit_after># Plugin: Monitors a URL by sending a http GET request to it
# the test PASSES if it gets a HTTP 200, 301 or 302 Response status code from the http request

module Ragios
  module Plugin

    class UrlMonitor
      attr_reader :test_result
      attr_reader :url
      attr_reader :connection
      attr_reader :options

      def init(monitor)
        raise "A url must be provided for url_monitor in #{monitor[:monitor]} monitor" if monitor[:url].nil?
        @url = monitor[:url]
        @connection = Excon.new(@url)
        @options = {
          expects: [200, 301, 302],
          method: :get,
          idempotent: true
        }
        @options[:retry_limit] = monitor[:retry_limit] || 3
        @options[:connect_timeout] = monitor[:connect_timeout] || 60
      end

      def test_command?
        response = @connection.request(@options)
        @test_result = { "HTTP GET Request to #{@url}" => response.status }
        return true
      rescue => e
        @test_result = { "HTTP GET Request to #{@url}" => e.message }
        return false
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09044585987261146, 'fraction_numerical': 0.017834394904458598, 'mean_word_length': 2.389928057553957, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4533275', 'n_tokens_mistral': 707, 'n_tokens_neox': 658, 'n_words': 228}