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
|
# 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
|
# Another Note: Requires terminal-notifier:
|
||||||
# expanding this and giving is some sick configuration options.
|
|
||||||
#
|
|
||||||
# Requires terminal-notifier:
|
|
||||||
# https://github.com/alloy/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'
|
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}/)
|
unless (resource.code =~ /2|3\d{2}/)
|
||||||
then
|
then
|
||||||
`terminal-notifier \
|
`terminal-notifier \
|
||||||
-title "Uptime Notifier" \
|
-title "Uptime Notifier" \
|
||||||
-message "OH NOES, it looks like #{URI.parse(url).host} is down!!~!" \
|
-subtitle "Site Down!" \
|
||||||
-open #{url} \
|
-message "#{URI.parse(url).host}" \
|
||||||
-group Uptime Notifier \
|
-open "http://downforeveryoneorjustme.com/#{URI.parse(url).host}" \
|
||||||
-remove Uptime Notifier`
|
-group "Uptime Notifier #{url}" \
|
||||||
|
-remove "Uptime Notifier #{url}"`
|
||||||
|
end
|
||||||
|
}
|
||||||
|
else
|
||||||
|
puts 'Unable to load configuration.'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue