diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/custodian-enqueue | 68 |
1 files changed, 66 insertions, 2 deletions
diff --git a/bin/custodian-enqueue b/bin/custodian-enqueue index a462b0a..6e5627a 100755 --- a/bin/custodian-enqueue +++ b/bin/custodian-enqueue @@ -11,6 +11,9 @@ require 'beanstalk-client' require 'getoptlong' require 'json' +require 'net/http' +require 'net/https' +require 'uri' @@ -72,6 +75,61 @@ class MonitorConfig + + # + # Retrieve a HTTP page from the web - this is used for macro-expansion + # + # NOTE: This came from sentinel. + # + def getURL (uri_str) + begin + uri_str = 'http://' + uri_str unless uri_str.match(/^http/) + url = URI.parse(uri_str) + http = Net::HTTP.new(url.host, url.port) + http.open_timeout = 3 + http.read_timeout = 3 + + if (url.scheme == "https") + http.use_ssl = true + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + end + + response = nil + + if nil == url.query + response = http.start { http.get(url.path) } + else + response = http.start { http.get("#{url.path}?#{url.query}") } + end + + + if ( response.code.to_i != 200 ) + puts "Status code of #{uri_str} was #{response.code}" + puts "ABORTING" + exit( 0 ) + end + + case response + when Net::HTTPRedirection + then + newURL = response['location'].match(/^http/)? + response['Location']:uri_str+response['Location'] + return( getURL(newURL) ) + else + return response.body + end + + rescue Errno::EHOSTUNREACH => ex + raise ex, "no route to host" + rescue Timeout::Error => ex + raise ex, "timeout" + rescue Errno::ECONNREFUSED => ex + raise ex, "connection refused" + end + end + + + # # Define a macro, from the configuration file. # @@ -93,8 +151,12 @@ class MonitorConfig # # HTTP-fetch # - val.push( "steve") - val.push("kemp") + uri = $1.dup.chomp(".") + + text = getURL(uri) + text.split( /[\r\n]/ ).each do |line| + val.push( line ) if ( line.length() > 0) + end elsif ( line =~ /\s(is|are)\s+(.*)\.+$/ ) @@ -408,3 +470,5 @@ if __FILE__ == $0 then mon = MonitorConfig.new( ENV['FILE'] ) mon.parse_file(); end + + |