class CloudstackNagios::Cli
Public Class Methods
start(given_args=ARGV, config={})
click to toggle source
rescue error globally
Calls superclass method
# File lib/cloudstack-nagios/cli.rb 10 def self.start(given_args=ARGV, config={}) 11 super 12 rescue => e 13 error_class = e.class.name.split('::') 14 puts "\e[31mERROR\e[0m: #{error_class.last} - #{e.message}" 15 puts e.backtrace if ARGV.include? "--debug" 16 end
Public Instance Methods
environments(file = options[:config])
click to toggle source
# File lib/cloudstack-nagios/cli.rb 74 def environments(file = options[:config]) 75 config = {} 76 if File.exists? file 77 begin 78 config = YAML::load(IO.read(file)) 79 rescue 80 error "Can't load configuration from file #{config_file}." 81 exit 1 82 end 83 table = [%w(Name URL)] 84 table << ["default", config[:url]] 85 config.each_key do |key| 86 table << [key, config[key][:url]] unless key.class == Symbol 87 end 88 print_table table 89 end 90 end
setup(file = options[:config])
click to toggle source
# File lib/cloudstack-nagios/cli.rb 42 def setup(file = options[:config]) 43 config = {} 44 unless options[:url] 45 say "Configuring #{options[:environment] || 'default'} environment." 46 say "What's the URL of your Cloudstack API?", :yellow 47 say "Example: https://my-cloudstack-service/client/api/" 48 config[:url] = ask("URL:", :magenta) 49 end 50 unless options[:api_key] 51 config[:api_key] = ask("API Key:", :magenta) 52 end 53 unless options[:secret_key] 54 config[:secret_key] = ask("Secret Key:", :magenta) 55 end 56 if options[:environment] 57 config = {options[:environment] => config} 58 end 59 if File.exists? file 60 begin 61 old_config = YAML::load(IO.read(file)) 62 rescue 63 error "Can't load configuration from file #{config_file}." 64 exit 1 65 end 66 say "Warning: #{file} already exists.", :red 67 exit unless yes?("Do you want to merge your settings? [y/N]", :red) 68 config = old_config.merge(config) 69 end 70 File.open(file, 'w+') {|f| f.write(config.to_yaml) } 71 end
version()
click to toggle source
# File lib/cloudstack-nagios/cli.rb 34 def version 35 say "cloudstack-nagios v#{CloudstackNagios::VERSION}" 36 end