Sha256: 931302778a13ae0cce80b7cc571f0ccf88014a99a985873ad995a9262cfac0af

Contents?: true

Size: 1.42 KB

Versions: 63

Compression:

Stored size: 1.42 KB

Contents

<%
  require 'base64'
  require 'json'
  require 'date'
  @current_time = Time.now.utc
  def display_holder(holder, value)
    begin
      holder_date = Time.parse(value)
      status = 'success'
      diff = (@current_time - holder_date).round(0)
      status = 'warning' if diff > 3600
      status = 'danger' if diff > 7200
      diff_txt = "#{diff % 3600} seconds"
      diff_txt = "#{(diff % 86400) / 3600} hours, #{diff_txt}" if diff > 3600
      diff_txt = "#{diff / 86400} days, #{diff_txt}" if diff > 86400
    rescue StandardError => e
      status = 'info'
      holder_date = "Cannot parse date: #{e}"
      diff_txt = "Error Parsing date #{value}"
    end
   [holder, holder_date, "#{diff_txt} ago", status]
  end

datacenters.each do |dc|
  kv('choregraphie', dc:dc, recurse:true).each do |tuple|
    ckey = tuple['Key'].gsub('/', '-')
    if tuple['Value'].nil?
      json = []
      holders = []
    else
      json = JSON.parse(Base64.decode64(tuple['Value']))
      holders = json['holders']
    end
    if holders.count > 0
      holders.each_pair do |key,value|
        if value.is_a?(Hash)
          value.each_pair do |k, v|
            host, holder_date, diff_txt, status = display_holder(k, v)
          end
        else
          host, holder_date, diff_txt, status = display_holder(key, value)
        end
        %><%= "#{host} ; #{dc} ; #{holder_date} ; #{status} ; #{ckey} ; #{diff_txt}" %>
<%
      end
    end
  end
end
%>

Version data entries

63 entries across 63 versions & 1 rubygems

Version Path
consul-templaterb-1.8.2 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.8.1 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.8.0 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.7.0 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.6.3 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.6.2 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.6.1 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.6.0 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.5.9 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.5.8 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.5.7 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.5.6 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.5.5 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.5.4 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.5.3 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.5.2 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.5.1 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.5.0 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.4.0 samples/criteo_choregraphies.txt.erb
consul-templaterb-1.3.1 samples/criteo_choregraphies.txt.erb