helpers do def h(text) Rack::Utils.escape_html(text) end def markdown(text) markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, space_after_headers: true) markdown.render(text) end def get_forced_state(notices) notices.each do |notice| next unless notice.key? 'force_state' return notice['force_state'] end nil end def render_column(id) content = '' ServiceRegistry.instance.columns[id].each do |category| content << "

%s

\n" % category content << services_info(ServiceRegistry.instance.categories[category][:services]) end content end def services_info(services) content = '
' services.each do |service| _service_status = service_status(service) _status_text = status_text(_service_status) _service_info = service_info(service) #service_name = ServiceRegistry.instance.services[service][:name] service_array = ServiceRegistry.instance.services[service] service_name = service_array.nil? ? 'UNKNOWN NAME' : service_array[:name] data_service_name = service_name.gsub('"', "'") content << " #{service_name} #{_service_info} " end content << '
' end def service_status(service) return 'na' unless ServiceRegistry.instance.services.key? service active_notices = NoticeStore.instance.active_notices_for(service) unless (forced_state = get_forced_state(active_notices)) == nil return forced_state else case ServiceRegistry.instance.services[service][:status] when State::UP return 'up' when State::WARNING return 'warning' when State::DOWN return 'down' else return 'na' end end end def service_info(service) visible_notices = NoticeStore.instance.visible_notices_for(service) content = status_icon(service_status(service)) content << '%s' % [visible_notices.count, visible_notices.count] if visible_notices.count > 0 content end def panel_class(notice) if notice['type'] == 'outage' 'border-danger' elsif notice['type'] == 'information' 'border-info' elsif notice['type'] == 'maintenance' 'border-warning' else '' end end def status_icon(status) case status.to_s when 'up' return '' when 'down' return '' when 'warning' return '' when 'maintenance' return '' else return '' end end def status_text(status) case status.to_s when 'up' return 'The service is up and running.' when 'down' return 'There are indications the service is down.' when 'warning' return 'There are issues with the service.' when 'maintenance' return 'The service is undergoing scheduled maintenance.' else return 'No data available.' end end def item_icon(type) case type.to_s when 'maintenance' return '' when 'outage' return '' when 'information' return '' end end def date_format(date) if date.nil? 'n/a' else date.httpdate end end def humanize(secs) [[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].map do |count, name| if secs > 0 secs, n = secs.divmod(count) "#{n.to_i} #{name}" unless name == :seconds end end.compact.reverse.join(' ') end end