Maj terminée. Pour consulter la release notes associée voici le lien :
https://about.gitlab.com/releases/2021/07/07/critical-security-release-gitlab-14-0-4-released/

network_monitoring.rb 2.85 KB
Newer Older
1 2 3
# add network_monitoring on supervision.site.grid5000.fr.yaml on hiera
#

4 5 6
NETWORK_EQUIPMENTS_BLACKLIST = [
  'swx1nef',
  'swy1nef',
7
  'sw-aci-333',
8 9
]

10
def generate_puppet_network_monitoring(options)
11

12 13 14 15 16 17 18 19 20 21 22 23
  refapi = load_data_hierarchy

  sites = options[:sites]
  out = options[:output_dir]

  sites.each do |s|
    net_eqs = refapi['sites'][s]['network_equipments']
    hiera_file = "#{out}/platforms/production/hieradata/clients/supervision2.#{s}.grid5000.fr.yaml"
    hiera_yaml = YAML.load_file(hiera_file)

    snmp_hosts = hiera_yaml['grid5000::munin::snmp::hosts'] || []
    net_hosts = hiera_yaml['grid5000::icinga::network::hosts'] || []
24
    admin_hosts = hiera_yaml['grid5000::icinga::network::admin_hosts'] || []
25 26

    net_eqs.each do |eq_name, eq_v|
27 28
      next if NETWORK_EQUIPMENTS_BLACKLIST.include?(eq_name)

29 30
      fqdn_eq_name = "#{eq_name}.#{s}.grid5000.fr"

31 32 33 34 35 36 37 38 39 40
      if %w[admin hpc].include?(eq_v['role'])
        unless admin_hosts.find { |i| i['name'] == fqdn_eq_name }
          admin_hosts << {
            'name' => fqdn_eq_name,
            'address' => eq_v['ip']
          }
        end
        next
      end

41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
      snmp_hosts << fqdn_eq_name unless
        snmp_hosts.find { |i| i == fqdn_eq_name }

      net_hosts_eq = net_hosts.select { |i| i['name'] == fqdn_eq_name }

      if net_hosts_eq.length.zero?
        net_hosts << {
          'name' => fqdn_eq_name,
          'address' => eq_v['ip'],
          'interfaces' => [],
          'has_ospf' => eq_v['kind'] == 'router'
        }
        net_hosts_eq = net_hosts.find { |i| i['name'] == fqdn_eq_name }

      elsif net_hosts_eq.length == 1
        net_hosts_eq = net_hosts_eq.first
      else
        net_hosts_eq = net_hosts_eq.first
        puts "ERROR: multiple entry for #{fqdn_eq_name} in hiera"
      end

      eq_v['linecards'].each do |l|
        next if l == {}

        l['ports'].each do |p|
          next if p == {}

          next unless %w[other switch router channel backbone].include?(p['kind'])

          port_name = p['snmp_name']
          next if net_hosts_eq['interfaces'].find { |i| i['name'] == port_name }

          sw = "#{eq_v['channels'][p['uid']]['uid']} " if p['kind'] == 'channel'

          net_hosts_eq['interfaces'] << {
            'name' => port_name,
            'description' => "Uplink #{sw}#{p['uid']}"
          }
        end
      end

      next unless eq_v['channels']
      eq_v['channels'].each do |c_name, c_v|
        next if net_hosts_eq['interfaces'].find { |i| i['name'] == c_name }

        net_hosts_eq['interfaces'] << {
          'name' => c_name,
          'description' => "LACP #{c_v['uid']}"
        }
      end
    end
    hiera_yaml['grid5000::munin::snmp::hosts'] = snmp_hosts
    hiera_yaml['grid5000::icinga::network::hosts'] = net_hosts
94
    hiera_yaml['grid5000::icinga::network::admin_hosts'] = admin_hosts
95 96 97
    IO.write(hiera_file, YAML.dump(hiera_yaml))
  end
end