Say you wanna monitor that your REST'ful service is up & working.
- treat gitted-file as a TAP unit-test
 - define a TAP output project in Jenkins (that runs every xx minutes and sends email notifications)
 - you're done
 
(in case of need, define more tests)
| require 'json' | |
| require 'net/http' | |
| class Service_Status_Monitor | |
| TEST_SERVICES = [ 'http://111.111.111.111:8001/status' ] # this IS our config file.. | |
| def run outf | |
| out = File.new( "#{File.dirname(__FILE__)}/#{outf}", "w" ) | |
| out.puts "1..#{TEST_SERVICES.size}" | |
| TEST_SERVICES.each_with_index do |ustr,ii| | |
| begin | |
| reply = Net::HTTP.get_response( URI( ustr ) ) | |
| body = JSON.parse( reply.body ) rescue { "status" => "no content / http code #{reply.code}" } | |
| out.puts "#{ ( reply.code == '200' and body["status"] == 'ok' ) ? "ok" : "not ok" } #{ii+1} - #{body}" | |
| rescue => err | |
| out.puts "not ok #{ii+1} - info: #{err}" | |
| end | |
| end | |
| out.close | |
| end | |
| end | |
| Service_Status_Monitor.new.run "monitor_status.out" |