# script to watch production code commit log and send a diff of if any changes for PCI regulation needs require 'rss' require 'openssl' DEBUG = false # set the local store for marshalled data $prod_code_last_reported_date = '/home/someuser/bin/watch_rss/data/last_reported.yml' $feed = 'SCRUBBED' $full_diff_email = 'longchanges@someplace.com' $small_diff_email = 'smallerlist@someplace.com' $fromuser = 'admins@someplace.com' def get_latest_time(feed) open(feed,:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE) do |atom| content = RSS::Parser.parse(atom, false) return content.items.first.updated.content end end if not File.exists?($prod_code_last_reported_date) last_run = ( Time.mktime('1970') ) File.open($prod_code_last_reported_date,'w') do |file| file.write Marshal.dump(last_run) end else last_run = Marshal.load( File.read($prod_code_last_reported_date) ) end latest_update_time = get_latest_time($feed) # if items from rss are older than last_run if latest_update_time > last_run puts "new commits or mergers" if DEBUG begin results = %x[/home/someplace/bin/getlong.sh | /usr/local/bin/mailer.rb -s "CodeWatcher: Production Java" -f #{$fromuser} #{$full_diff_email}] results = %x[/home/someplace/bin/getshort.sh | /usr/local/bin/mailer.rb -s "CodeWatcher: Production Java" -f #{$fromuser} #{$small_diff_email}] # pushing latest date to the yaml File.open($prod_code_last_reported_date,'w') do |file| file.write Marshal.dump(latest_update_time) end rescue %x[echo "issue with the codewatcher job on gitlab" | /usr/loca/bin/mailer.rb -s "Alert Problem with Codewatcher" -f #{fromuser} #{$fromuser}] exit end else puts "no new commits or mergers" if DEBUG exit end