Class: UbcMonitor::CLI
- Inherits:
-
Object
- Object
- UbcMonitor::CLI
- Defined in:
- lib/ubc_monitor/cli.rb
Overview
Run the monitor
Class Method Summary collapse
Class Method Details
.execute(arguments = []) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ubc_monitor/cli.rb', line 8 def self.execute(arguments=[]) = { :file => File.('~/.ubc_monitor'), :email_recipient => nil, :email_subject => 'User beancounters has new errors' } OptionParser.new do |opts| opts. = <<-BANNER.gsub(/^ /,'') Monitor /proc/user_beancounters and send an email to the systems administrator if failcnt has increased since last time ubc_monitor was run. ubc_monitor uses a file (by default ~/.ubc_monitor) to keep track of user_beancounter fail counts. When running without this file (such as the first run) any fail count except 0 will be reported. Usage: #{File.basename(__FILE__)} [options] BANNER opts.on("-f", "--file [FILE]", "Log failcounts to this file, default\n" + " is #{[:file]}") { |f| [:file] = File. f } opts.on("-n", "--no-log", "Don't log fail counts") { |r| [:file] = nil } opts.on("-t", "--email-recipient [EMAIL]", "The recipient of report emails.\n" + " If this is not set, no email is sent") { |r| [:email_recipient] = r } opts.on("-s", "--email-subject [SUBJECT]", "Email subject. Default\n" + " 'value is #{[:email_subject]}'") { |s| [:email_subject] = s } end.parse! monitor = UbcMonitor::Monitor.new() report = monitor.run if report.updated && ![:email_recipient].nil? `echo '"#{report.to_s}"' | mail -s "#{[:email_subject]}" "#{[:email_recipient]}"` elsif report.updated puts report.to_s else puts "All's swell!" end end |