Created
October 29, 2014 23:33
-
-
Save skout23/146c2717a76dfa1fd153 to your computer and use it in GitHub Desktop.
simple-ish rss atom feed watcher to alert when a code change has taken place
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 = '[email protected]' | |
$small_diff_email = '[email protected]' | |
$fromuser = '[email protected]' | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment