class Anamo::Node::Thor
Public Instance Methods
config_file_path()
click to toggle source
# File lib/anamo/node/thor.rb, line 146 def config_file_path if defined? @config_file_path @config_file_path else return "#{Dir.home}/anamo.conf.yml" end end
configure()
click to toggle source
# File lib/anamo/node/thor.rb, line 89 def configure configuration = {} say "The Anamo configuration setup tool will walk you through the process\nof defining your configuration for:\n\n", [:green, :bold] say " #{config_file_path}\n\n", :green configuration['api_key'] = '' until configuration['api_key'].strip.length > 0 do configuration['api_key'] = ask "What is your Anamo API key?\n", :bold end configuration['modules'] = {} if ['y','yes'].include? ask("Would you like to configure send frequencies? (y/n)\n", :bold).downcase freq = ask "How often should filesystem data be sent to server? (in seconds -- default: 240 seconds)\n", :bold if freq.strip.length > 0 configuration['modules']['fstree'] = { 'frequency' => freq.to_i } end freq = ask "How often should package data be sent to server? (in seconds -- default: 60 seconds)\n", :bold if freq.strip.length > 0 configuration['modules']['pkgver'] = { 'frequency' => freq.to_i } end freq = ask "How often should port data be sent to server? (in seconds -- default: 60 seconds)\n", :bold if freq.strip.length > 0 configuration['modules']['ports'] = { 'frequency' => freq.to_i } end end say "\nYour configuration file:\n\n", [:green, :bold] configuration_yaml = YAML.dump configuration say configuration_yaml if ['yes', 'y'].include? ask("\nWould you like to save this file now? (\"y\" to save)", :bold).downcase File.open(config_file_path, 'w') { |file| file.write configuration_yaml } File.chmod(0600, config_file_path) say "Configurated saved at: #{config_file_path}", [:cyan, :bold] else say 'Configuration not saved.', [:red, :bold] end end
exec()
click to toggle source
# File lib/anamo/node/thor.rb, line 19 def exec data = inspect false response = ::Anamo::Api.new.post_node MultiJson.dump data response_data = MultiJson.load response.body if response_data.respond_to?(:has_key?) and response_data.has_key?('client_key') File.open(key_file, 'w') { |file| file.write response_data['client_key'] } File.chmod(0600, key_file) end end
inspect(output = true)
click to toggle source
# File lib/anamo/node/thor.rb, line 36 def inspect output = true ret = {} config = YAML.load_file "#{Dir.home}/anamo.conf.yml" #train train = Train.create('local') # start or reuse a connection conn = train.connection ret['api_key'] = config['api_key'] ret['beacon_modules'] = config['modules'] ret['node'] = {} ret['node']['hostname'] = Socket.gethostname ret['node']['ips'] = Socket.ip_address_list.map(){ |entry| entry.ip_address }.uniq ret['node']['os_name'] = Train.create('local').connection.os[:name] ret['node']['os_family'] = Train.create('local').connection.os[:family] ret['node']['os_release'] = Train.create('local').connection.os[:release] # run a command on Linux/Unix/Mac ret['node']['cpe'] = conn.run_command('hostnamectl | grep "Static hostname: "').stdout ret['node']['chassis'] = conn.run_command('hostnamectl | grep "Chassis: "').stdout ret['node']['machine_id'] = conn.run_command('hostnamectl | grep "Machine ID: "').stdout ret['node']['boot_id'] = conn.run_command('hostnamectl | grep "Boot ID: "').stdout ret['node']['virtualization'] = conn.run_command('hostnamectl | grep "Virtualization: "').stdout ret['node']['operating_system'] = conn.run_command('hostnamectl | grep "Operating System: "').stdout ret['node']['kernel'] = conn.run_command('hostnamectl | grep "Kernel: "').stdout ret['node']['architecture'] = conn.run_command('hostnamectl | grep "Architecture: "').stdout #Uname (General) ret['node']['uname_sysname'] = Uname.sysname # => The operating system name. e.g. "SunOS" ret['node']['uname_machine'] = Uname.machine # => The machine hardware type. e.g. "i686" ret['node']['uname_version'] = Uname.version # => The operating system version. e.g. "5.8". Windows includes patch information. ret['node']['uname_release'] = Uname.release # => The operating system release. e.g. "2.2.16-3" #Uname (Solaris-Only) #ret['node']['uname_architecture'] = Uname.architecture # => Returns the instruction set architecture. e.g. "sparc" #ret['node']['uname_platform'] = Uname.platform # => The platform identifier. e.g. "SUNW,Sun-Blade-100" #ret['node']['uname_isa_list'] = Uname.isa_list # => List of supported instr. sets, e.g. "amd64 pentium_pro+mmx pentium_pro" #ret['node']['uname_hw_provider'] = Uname.hw_provider # => The name of the hardware manufacturer. #ret['node']['uname_hw_serial_number'] = Uname.hw_provider # => Uname.hw_serial_number # => The hardware serial number puts ret if output ret end
set_config_file_path(path)
click to toggle source
# File lib/anamo/node/thor.rb, line 142 def set_config_file_path path @config_file_path = path end
Private Instance Methods
key_file()
click to toggle source
# File lib/anamo/node/thor.rb, line 158 def key_file "#{Dir.home}/anamo.client.key" end