Skip to content

Instantly share code, notes, and snippets.

@marcusbaguley
Created January 21, 2011 00:17
Show Gist options
  • Save marcusbaguley/789002 to your computer and use it in GitHub Desktop.
Save marcusbaguley/789002 to your computer and use it in GitHub Desktop.
Scout plugin for monitoring solr
# Scout plugin for monitoring solr
class SolrMonitoring < Scout::Plugin
OPTIONS = <<-EOS
solr_port:
notes: Solr port
default: 8080
solr_host:
notes: The host that solr is running on
default: http://127.0.0.1
search:
notes: The search string that should return a result
default: tel
EOS
needs 'net/http', 'rexml/document'
def build_report
if option(:solr_port).nil? or option(:solr_host).nil? or option(:search).nil?
return error("Parameters not provided", "Please provide the host, port, and search and search_expected")
end
base_url = "#{option(:solr_host)}:#{option(:solr_port)}/solr/select/?q=#{option(:search)}&qf=name_text+code_text+long_name_text&defType=dismax&rows=20"
doc = REXML::Document.new((Net::HTTP.get(URI.parse(base_url))))
if doc.elements['response'].elements['result'].attributes['numFound'].to_i == 0
error("No SOLR results found for #{option(:search)}")
end
rescue
error("SOLR Exception in code",$!.to_s)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment