Created
July 2, 2013 11:31
-
-
Save jiphex/5908567 to your computer and use it in GitHub Desktop.
Send a single mauve alert about any outstanding gem updates on a host. See projects.bytemark.co.uk/projects/mauvealert
This file contains hidden or 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
#!/usr/bin/env ruby1.8 | |
# Alert about available gem updates | |
require 'mauve/sender' | |
require 'mauve/proto' | |
require 'mauve/mauve_time' | |
require 'rubygems' | |
require 'gems' | |
installed = `gem list`.split("\n").map do |txt| | |
txt =~ /(.+) \((.+)\)/ | |
[$1.strip,$2] | |
end.reject{|a|a.first=="gems"} | |
updates = installed.map do |ins| | |
(gem,installed_version) = ins | |
latest = Gems.info(gem) | |
if latest["version"] > installed_version | |
[gem,installed_version,latest] | |
else | |
nil | |
end | |
end.reject{|a|a.nil?} | |
hostname = %x[hostname].strip | |
update = Mauve::Proto::AlertUpdate.new | |
update.replace = false | |
message = Mauve::Proto::Alert.new | |
message.id = "gem-updates-needed" | |
message.subject = hostname | |
if updates.length > 0 | |
message.summary = "#{updates.length} gem updates required on #{hostname}" | |
message.source = "gem version checker in cron.daily on #{hostname}" | |
message.detail << "The following gems are in need of updating: \n\n" | |
updates.each do |u| | |
message.detail << " * #{u[0]}: #{u[1]} => #{u[2]}\n" | |
end | |
message.raise_time = Time.now.to_i | |
else | |
message.summary = "All gems on #{hostname} are up-to-date." | |
message.clear_time = Time.now.to_i | |
end | |
update.alert = [message] | |
Mauve::Sender.new.send(update) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment