Class: MonitorTypeHttpGetJsonList
- Inherits:
-
MonitorTypeThreshold
- Object
- MonitorType
- MonitorTypeThreshold
- MonitorTypeHttpGetJsonList
- Defined in:
- lib/monitor_type/http_get_json_list.rb
Overview
An http class for checking the length of a json list. For example,
Get the list of outstandinig errors
=> check that the number is not greater than 2
Instance Method Summary collapse
- #derived_value ⇒ Object
-
#extract_params ⇒ Object
Extract parameters.
Methods inherited from MonitorTypeThreshold
Methods inherited from MonitorType
#alert, #initialize, #process, #run, #setup, #teardown
Constructor Details
This class inherits a constructor from MonitorTypeThreshold
Instance Method Details
#derived_value ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/monitor_type/http_get_json_list.rb', line 32 def derived_value content = RestClient.get(@uri.to_s) list = JSON.parse(content) str = "Expected type, Array - Actual type, #{list.class.name}" fail MonitorTypeExceptionHandled, str unless list.class.name == 'Array' list.length rescue MonitorTypeExceptionHandled raise e rescue StandardError string = '*** HttpGetJsonList encountered an error while running the ' \ 'HTTP Get\n' \ "*** uri: #{@uri}\n" \ "*** Please fix the query and run again\n" raise MonitorTypeExceptionHandled, string end |
#extract_params ⇒ Object
Extract parameters
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/monitor_type/http_get_json_list.rb', line 12 def extract_params if @params[:uri].nil? string = "*** HttpGetJsonList parameter missing, uri\n" \ '*** :uri => <uri pointing to url to be monitored>' fail MonitorTypeParameterMissingError, string end begin @uri = URI.parse(@params[:uri]) rescue URI::InvalidURIError str = '*** HttpGetJsonList encountered an error while parsing the uri' \ "*** uri: #{@params[:uri]}" \ '*** Please fix the uri and run again' raise MonitorTypeParameterMissingError, str end url = "#{@uri.scheme}://#{@uri.host}#{@uri.path}" @context_sentence = "Checking size of json list returned from, #{url}" end |