Class: Upstreamstatus
- Inherits:
-
Object
- Object
- Upstreamstatus
- Extended by:
- Forwardable
- Defined in:
- lib/upstreamstatus.rb,
lib/upstreamstatus/version.rb
Constant Summary collapse
- VERSION =
"0.2.3"
Instance Attribute Summary collapse
-
#conf ⇒ Object
readonly
Returns the value of attribute conf.
Instance Method Summary collapse
- #current_status ⇒ Object
-
#initialize ⇒ Upstreamstatus
constructor
A new instance of Upstreamstatus.
- #run ⇒ Object
Constructor Details
#initialize ⇒ Upstreamstatus
Returns a new instance of Upstreamstatus.
20 21 22 23 24 25 26 27 28 |
# File 'lib/upstreamstatus.rb', line 20 def initialize @conf = OpenStruct.new load_conf return unless opts[:notify] && sentry_dsn Raven.configure do |config| config.dsn = sentry_dsn config.logger = logger end end |
Instance Attribute Details
#conf ⇒ Object (readonly)
Returns the value of attribute conf.
18 19 20 |
# File 'lib/upstreamstatus.rb', line 18 def conf @conf end |
Instance Method Details
#current_status ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/upstreamstatus.rb', line 52 def current_status return fake_servers if opts[:simulate] r = Unirest.get status_check_url unless (200..299).include?(r.code) fail "Error code: #{r.code}\n" \ "Headers: #{r.headers}" \ "Body: #{r.body}" end r.body end |
#run ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/upstreamstatus.rb', line 30 def run down_hosts = current_status['servers']['server'].select { |s| s['status'] != 'up' } if down_hosts.empty? clear_active_alerts! exit 0 end print_hosts down_hosts logger.notice "Detected down hosts: #{down_hosts.to_json}" if opts[:notify] puts 'Sending notifications' notify( 'One or more API upstream hosts listed as down', JSON.pretty_generate(down_hosts) ) end exit 1 end |