Class: Anamo::Node::Thor
- Inherits:
-
Thor
- Object
- Thor
- Anamo::Node::Thor
- Defined in:
- lib/anamo/node/thor.rb
Instance Method Summary collapse
Instance Method Details
#configure ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# 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 ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# 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) ⇒ Object
36 37 38 39 40 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 |
# 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 |