<commit_before><%
  path = Rails.root.join("data/nagios")
  machines_nagios = %x(grep host_name= #{path}/status.dat|cut -d"=" -f 2|sort -u).split(/\n/)
  machines_nagios.reject!{|h| h.match(/^(VIPS?\d*_|GW_|URL_|sgbd-prod[abc]$|sgbd-prod[abc]-[a-z])/) } # service checks that can't be renamed easily in nagios
  machines_nagios.each{|h| h.gsub!(/^(MIN_|RH_|RITAC_|AM_|DEV_)/,"") }
  machines_cartocs = Machine.all

  unknown_in_nagios = machines_cartocs.map(&:name) - machines_nagios
  unknown_in_nagios.reject!{ |name| name.starts_with?("vm-hra") || name.starts_with?("vm-hrw") } #RH project we're not responsible of
  unknown_in_nagios.reject!{ |name| name.match(/millos|ritac-|-nt-|-ac-|^dns-[01]$/) } #Windows servers we're not responsible of
  unknown_in_nagios.map!{|name| link_to_servername name}
  unknown_in_cartocs = machines_nagios - machines_cartocs.map(&:name)
  unknown_in_cartocs.map!{|s| server_missing s}

  tomcats_jason = Tomcat.all.map{|t| t[:tomcat]+"@"+t[:server]}.select{|t| t.match(/\S@\S/)}
  tomcats_nagios = []; prev=""
  File.open("#{Rails.root}/data/nagios/status.dat").each_line do |line|
    tomcats_nagios << line.split("PROCESS_").last.chomp + "@" + prev.split("=").last.chomp if line.include?("PROCESS_TC")
    prev=line
  end
  tomcat_unknown_in_nagios = tomcats_jason - tomcats_nagios
  tomcat_unknown_in_nagios.reject!{|t| t.match(/vm-preprod/) }
  nb_tomcats = tomcats_jason.reject!{|t| t.match(/vm-preprod/) }.count

  diff_list = {
    "dans Nagios manquants dans Cartocs" => unknown_in_cartocs,
    "de Cartocs inconnus dans Nagios"  => unknown_in_nagios,
    "Tomcat non supervisés (sur #{nb_tomcats} hors préproduction)" => tomcat_unknown_in_nagios
  }
%>

<% title "Outils - Comparaison Nagios" %>

<div id="tools" class="grid_12 items_list">

<%= render "submenu" %>

<% diff_list.each do |title,machines| %>
<ul>
  <li><strong><%= pluralize(machines.count, "serveur") %> <%= title %></strong></li><commit_msg>Fixed 500 error when nagios' status.dat file does not exist<commit_after><%
  path = Rails.root.join("data/nagios")
  machines_nagios = %x(grep host_name= #{path}/status.dat|cut -d"=" -f 2|sort -u).split(/\n/)
  machines_nagios.reject!{|h| h.match(/^(VIPS?\d*_|GW_|URL_|sgbd-prod[abc]$|sgbd-prod[abc]-[a-z])/) } # service checks that can't be renamed easily in nagios
  machines_nagios.each{|h| h.gsub!(/^(MIN_|RH_|RITAC_|AM_|DEV_)/,"") }
  machines_cartocs = Machine.all

  unknown_in_nagios = machines_cartocs.map(&:name) - machines_nagios
  unknown_in_nagios.reject!{ |name| name.starts_with?("vm-hra") || name.starts_with?("vm-hrw") } #RH project we're not responsible of
  unknown_in_nagios.reject!{ |name| name.match(/millos|ritac-|-nt-|-ac-|^dns-[01]$/) } #Windows servers we're not responsible of
  unknown_in_nagios.map!{|name| link_to_servername name}
  unknown_in_cartocs = machines_nagios - machines_cartocs.map(&:name)
  unknown_in_cartocs.map!{|s| server_missing s}

  tomcats_jason = Tomcat.all.map{|t| t[:tomcat]+"@"+t[:server]}.select{|t| t.match(/\S@\S/)}
  tomcats_nagios = []; prev=""
  datafile = "#{Rails.root}/data/nagios/status.dat"
  File.open(datafile).each_line do |line|
    tomcats_nagios << line.split("PROCESS_").last.chomp + "@" + prev.split("=").last.chomp if line.include?("PROCESS_TC")
    prev=line
  end if File.exists?(datafile)
  tomcat_unknown_in_nagios = tomcats_jason - tomcats_nagios
  tomcat_unknown_in_nagios.reject!{|t| t.match(/vm-preprod/) }
  nb_tomcats = tomcats_jason.reject!{|t| t.match(/vm-preprod/) }.count

  diff_list = {
    "dans Nagios manquants dans Cartocs" => unknown_in_cartocs,
    "de Cartocs inconnus dans Nagios"  => unknown_in_nagios,
    "Tomcat non supervisés (sur #{nb_tomcats} hors préproduction)" => tomcat_unknown_in_nagios
  }
%>

<% title "Outils - Comparaison Nagios" %>

<div id="tools" class="grid_12 items_list">

<%= render "submenu" %>

<% diff_list.each do |title,machines| %>
<ul>
  <li><strong><%= pluralize(machines.count, "serveur") %> <%= title %></strong></li>
{'fraction_non_alphanumeric': 0.18356643356643357, 'fraction_numerical': 0.003246753246753247, 'mean_word_length': 5.13323124042879, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '120999', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1601, 'n_words': 256}