class Naginata::Loader

Public Class Methods

load_configuration() click to toggle source
# File lib/naginata/loader.rb, line 13
def load_configuration
  # Load defaults.rb
  default = File.join(File.dirname(__FILE__), 'defaults.rb')
  instance_eval File.read(default), default
  # Load Naginatafile
  naginatafile_path = ::Naginata::Configuration.env.fetch(:naginatafile) || find_naginatafile
  if naginatafile_path.nil? or !File.file?(naginatafile_path)
    raise NaginatafileNotFound, 'Could not locate Naginatafile'
  else
    instance_eval File.read(naginatafile_path), naginatafile_path
  end
end
load_remote_objects(fetch_options = {}) click to toggle source
# File lib/naginata/loader.rb, line 26
def load_remote_objects(fetch_options = {})
  require 'naginata/cli/fetch'
  # Refresh cached status.dat
  CLI::Fetch.new(fetch_options).run

  nagios_servers = Configuration.env.filter(Configuration.env.nagios_servers)
  nagios_servers.each do |nagios_server|
    status = ::Naginata::Status.find(nagios_server.hostname)
    status.service_items.group_by{ |section| section.host_name }.each do |host, sections|
      services = sections.map { |s| s.service_description }
      Configuration.env.host(host, services: services, on: nagios_server.hostname)
    end
  end
end