lib/flapjack/gateways/pagerduty.rb in flapjack-0.6.51 vs lib/flapjack/gateways/pagerduty.rb in flapjack-0.6.52
- old
+ new
@@ -46,11 +46,14 @@
redis.rpush(@config['queue'], JSON.generate('notification_type' => 'shutdown'))
end
def main
logger.debug("pagerduty gateway - commencing main method")
- raise "Can't connect to the pagerduty API" unless test_pagerduty_connection
+ while not test_pagerduty_connection do
+ logger.error("Can't connect to the pagerduty API, retrying after 10 seconds")
+ EM::Synchrony.sleep(10)
+ end
# TODO: only clear this if there isn't another pagerduty gateway instance running
# or better, include an instance ID in the semaphore key name
@redis.del(SEM_PAGERDUTY_ACKS_RUNNING)
@@ -158,19 +161,28 @@
unacknowledged_failing_checks = Flapjack::Data::Global.unacknowledged_failing_checks(:redis => @redis_timer)
@logger.debug "found unacknowledged failing checks as follows: " + unacknowledged_failing_checks.join(', ')
unacknowledged_failing_checks.each do |entity_check|
- pagerduty_credentials = entity_check.pagerduty_credentials(:redis => @redis_timer)
+
+ # If more than one contact for this entity_check has pagerduty
+ # credentials then there'll be one hash in the array for each set of
+ # credentials.
+ ec_credentials = entity_check.contacts.inject([]) {|ret, contact|
+ cred = contact.pagerduty_credentials
+ ret << cred if cred
+ ret
+ }
+
check = entity_check.check
- if pagerduty_credentials.empty?
+ if ec_credentials.empty?
@logger.debug("No pagerduty credentials found for #{entity_check.entity_name}:#{check}, skipping")
next
end
# FIXME: try each set of credentials until one works (may have stale contacts turning up)
- options = pagerduty_credentials.first.merge('check' => "#{entity_check.entity_name}:#{check}")
+ options = ec_credentials.first.merge('check' => "#{entity_check.entity_name}:#{check}")
acknowledged = pagerduty_acknowledged?(options)
if acknowledged.nil?
@logger.debug "#{entity_check.entity_name}:#{check} is not acknowledged in pagerduty, skipping"
next