Skip to content

Commit

Permalink
Fix email notifier; cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Brenton Fletcher authored and Brenton Fletcher committed May 14, 2009
1 parent 9bc3e04 commit 13c240e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 127 deletions.
1 change: 1 addition & 0 deletions bin/webstats_email_notifier
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require File.dirname(__FILE__) + '/../clients/email_notifier/email_notifier'
126 changes: 1 addition & 125 deletions clients/email_notifier/email_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,128 +63,4 @@ def notify
end

s = EmailNotifier.new()
s.start

=begin
require File.dirname(__FILE__) + '/../common'
prepare_client
load_settings('email_notifier', { 'email_addresses' => ['example@example.com'] }] }, "Please edit ~/.webstats_clients and add some email addresss to send to")
urls = $settings[:urls]
emails = $settings[:emails]
failed_url = lambda do |url, password, exception|
g.notify "Webstats Notification", "Cannot load Webstats data", "Could not load #{url}#{!password.nil? ? " with password #{password}" : ""}, error was #{exception.message}. Will try again in 60 seconds."
sleep(60)
true
end
urls.each do |url|
url.merge!({ :meta_info => make_request(URI.join(url[:url], "information"), url[:password], failed_url), :last_warnings_text => nil, :last_danger_text => nil, :last_time => 0 })
end
while(true)
urls.each do |url|
data = make_request(URI.join(url[:url], "update"), url[:password], failed_url)
bad = data.sort { |a, b| b[1]['importance'].to_f <=> a[1]['importance'].to_f }.select { |(k, v)| !v['status'].nil? && v['status'] != '' }
has_warnings = bad.detect { |(k, v)| v['status'] == 'warning' }
has_dangers = bad.detect { |(k, v)| v['status'] == 'danger' }
title = []
title << "Danger" if has_dangers
title << "Warnings" if has_warnings
title = title.join(" & ") + " for host #{URI.parse(url[:url]).host}"
warnings_text = has_warnings ? "Warnings for #{bad.select { |(k, v)| v['status'] == 'warning' }.map { |(k, v)| url[:meta_info][k]['in_sentence'] }.join(", ")}." : nil
danger_text = has_dangers ? "Dangerous situation for #{bad.select { |(k, v)| v['status'] == 'danger' }.map { |(k, v)| url[:meta_info][k]['in_sentence'] }.join(", ")}." : nil
if url[:last_warnings_text] != warnings_text or url[:last_danger_text] != danger_text or (url[:last_time] != 0 and (Time.now - url[:last_time]) > 60)
url[:last_warnings_text] = warnings_text
url[:last_danger_text] = danger_text
url[:last_time] = Time.now
unless bad.empty?
g.notify "Webstats Notification", title, [danger_text, warnings_text].compact.join(" "), nil, nil, true, (has_dangers ? 2 : 1)
end
end
end
sleep(10)
end
require 'rubygems'
require 'net/smtp'
require 'net/dns/resolver'
require 'net/dns/rr'
require 'time'
def send_mail_hardcore(recipient, recipient_name, from, from_name, subject, message)
username, domain = recipient.split('@', 2) #yeah yeah, username can contain @ sign, will fix later
mxrs = Net::DNS::Resolver.new.mx(domain)
if mxrs.empty?
puts "No MX records on domain; bad domain name"
return
end
msg = <<END_OF_MESSAGE
From: #{from_name || recipient_name} <#{from || recipient}>
To: #{recipient_name} <#{recipient}>
Subject: #{subject}
Date: #{Time.now.rfc2822}
Message-Id: <#{Time.now.to_i}.#{rand(10000000)}@#{domain}>
#{message}
END_OF_MESSAGE
Net::SMTP.start(mxrs.first.exchange, 25, domain) { |smtp| smtp.send_message msg, recipient, recipient }
end
send_mail_hardcore(*ARGV)
=end
s.start
Binary file removed server/data_providers/disk_usage.o
Binary file not shown.
5 changes: 3 additions & 2 deletions webstats.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

Gem::Specification.new do |s|
s.name = %q{webstats}
s.version = "0.10.1"
s.version = "0.10.2"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Brenton Fletcher"]
s.date = %q{2009-05-14}
s.date = %q{2009-05-15}
s.description = %q{Monitor server CPU/Memory/Disk Usage/URL Loading, so that you can view those statistics on a web page, as well as providing an interface to client prorams to read those statistics.}
s.email = %q{i@bloople.net}
s.executables = ["webstats", "webstats_growl_notifier"]
Expand All @@ -21,6 +21,7 @@ Gem::Specification.new do |s|
"Rakefile",
"VERSION.yml",
"bin/webstats",
"bin/webstats_email_notifier",
"bin/webstats_growl_notifier",
"clients/email_notifier/README.textile",
"clients/email_notifier/email_notifier.rb",
Expand Down

0 comments on commit 13c240e

Please sign in to comment.