Method: Sensu::Utilities#in_time_windows?

Defined in:
lib/sensu/utilities.rb

#in_time_windows?(conditions) ⇒ TrueClass, FalseClass

Determine if time window conditions for one or more days of the week are met. If a day of the week is provided, it can provide one or more conditions, each with a ‘:begin` and `:end` time, eg. “11:30:00 PM”, or `false` will be returned.

Parameters:

  • conditions (Hash)

Options Hash (conditions):

  • :days (String)

    of the week.

Returns:

  • (TrueClass, FalseClass)


357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'lib/sensu/utilities.rb', line 357

def in_time_windows?(conditions)
  in_window = false
  window_days = conditions[:days] || {}
  if window_days[:all]
    in_window = window_days[:all].any? do |condition|
      in_time_window?(condition)
    end
  end
  current_day = Time.now.strftime("%A").downcase.to_sym
  if !in_window && window_days[current_day]
    in_window = window_days[current_day].any? do |condition|
      in_time_window?(condition)
    end
  end
  in_window
end