As promised, configurability!
This commit is contained in:
parent
cbf4199f78
commit
ba6bba348e
2 changed files with 44 additions and 18 deletions
5
uptime-notifier.conf
Normal file
5
uptime-notifier.conf
Normal file
|
@ -0,0 +1,5 @@
|
|||
http://this-website-should-be-down.com
|
||||
# Comments are allowed
|
||||
# Also, if you forget the protocol, http:// will be added
|
||||
google.com
|
||||
http://another-website-that-should-be-down.com
|
|
@ -1,29 +1,50 @@
|
|||
#!/usr/bin/ruby
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
##
|
||||
# Uptime Notifier
|
||||
#
|
||||
# Super simplistic website monitoring. Crontab is up and enjoy!
|
||||
# Super simplistic website monitoring. Crontab it up and enjoy!
|
||||
#
|
||||
# Usage: ruby uptime-notifier.rb
|
||||
# Note: Conf file should contain one website per line
|
||||
#
|
||||
# p.s. This was just a quick Thanksgiving proof of concept, I do plan on
|
||||
# expanding this and giving is some sick configuration options.
|
||||
#
|
||||
# Requires terminal-notifier:
|
||||
# Another Note: Requires terminal-notifier:
|
||||
# https://github.com/alloy/terminal-notifier
|
||||
#
|
||||
# @author Josh Sherman
|
||||
# @link https://github.com/joshtronic/uptime-notifier
|
||||
# @usage ruby uptime-notifier.rb /path/to/uptime-notifier.conf
|
||||
|
||||
require 'net/http'
|
||||
|
||||
url = 'http://this-website-should-be-down.com'
|
||||
unless ARGV[0].nil?
|
||||
then
|
||||
conf_file = ARGV[0]
|
||||
else
|
||||
conf_file = File.expand_path(File.dirname(__FILE__)) + '/uptime-notifier.conf'
|
||||
end
|
||||
|
||||
resource = Net::HTTP.get_response(URI.parse(url.to_s))
|
||||
if File.exists?(conf_file)
|
||||
then
|
||||
File.open(conf_file).each { |url|
|
||||
url.chomp!
|
||||
|
||||
next if (url[0..0] == '#' || url.empty?)
|
||||
|
||||
url.insert(0, 'http://') unless(url.match(/^http\:\/\//))
|
||||
|
||||
resource = Net::HTTP.get_response(URI.parse(url))
|
||||
|
||||
unless (resource.code =~ /2|3\d{2}/)
|
||||
then
|
||||
`terminal-notifier \
|
||||
-title "Uptime Notifier" \
|
||||
-message "OH NOES, it looks like #{URI.parse(url).host} is down!!~!" \
|
||||
-open #{url} \
|
||||
-group Uptime Notifier \
|
||||
-remove Uptime Notifier`
|
||||
-subtitle "Site Down!" \
|
||||
-message "#{URI.parse(url).host}" \
|
||||
-open "http://downforeveryoneorjustme.com/#{URI.parse(url).host}" \
|
||||
-group "Uptime Notifier #{url}" \
|
||||
-remove "Uptime Notifier #{url}"`
|
||||
end
|
||||
}
|
||||
else
|
||||
puts 'Unable to load configuration.'
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue