Class: GenesisCollector::Collector
- Inherits:
-
Object
- Object
- GenesisCollector::Collector
- Includes:
- Chef, Disks, DmiDecode, IPMI, NetworkInterfaces
- Defined in:
- lib/genesis_collector/collector.rb
Constant Summary
Constants included from DmiDecode
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#sku ⇒ Object
readonly
Returns the value of attribute sku.
Instance Method Summary collapse
- #collect! ⇒ Object
- #collect_basic_data ⇒ Object
- #collect_cpus ⇒ Object
- #collect_memories ⇒ Object
-
#initialize(config = {}) ⇒ Collector
constructor
A new instance of Collector.
- #submit! ⇒ Object
Methods included from DmiDecode
#get_dmi_data, #parse_dmidecode
Methods included from Disks
Methods included from IPMI
Methods included from Chef
#collect_chef, #collect_chef_from_knife, #collect_chef_from_node
Methods included from NetworkInterfaces
Constructor Details
#initialize(config = {}) ⇒ Collector
Returns a new instance of Collector.
22 23 24 25 26 |
# File 'lib/genesis_collector/collector.rb', line 22 def initialize(config = {}) @chef_node = config.delete(:chef_node) @config = config @payload = {} end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
14 15 16 |
# File 'lib/genesis_collector/collector.rb', line 14 def payload @payload end |
#sku ⇒ Object (readonly)
Returns the value of attribute sku.
14 15 16 |
# File 'lib/genesis_collector/collector.rb', line 14 def sku @sku end |
Instance Method Details
#collect! ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/genesis_collector/collector.rb', line 28 def collect! @sku = get_sku safely { collect_basic_data } safely { collect_chef } safely { collect_ipmi } safely { collect_network_interfaces } safely { collect_disks } safely { collect_cpus } safely { collect_memories } @payload end |
#collect_basic_data ⇒ Object
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 |
# File 'lib/genesis_collector/collector.rb', line 54 def collect_basic_data @payload = { type: 'Server', hostname: get_hostname, fqdn: get_fqdn, os: { distribution: get_distribution, release: get_release, codename: get_codename, description: get_description }, last_boot_at: get_last_boot_time, product: read_dmi('system-product-name'), vendor: read_dmi('system-manufacturer'), properties: { 'SYSTEM_SERIAL_NUMBER' => read_dmi('system-serial-number'), 'BASEBOARD_VENDOR' => read_dmi('baseboard-manufacturer'), 'BASEBOARD_PRODUCT_NAME' => read_dmi('baseboard-product-name'), 'BASEBOARD_SERIAL_NUMBER' => read_dmi('baseboard-serial-number'), 'CHASSIS_VENDOR' => read_dmi('chassis-manufacturer'), 'CHASSIS_SERIAL_NUMBER' => read_dmi('chassis-serial-number'), 'BIOS_VERSION' => read_dmi('bios-version'), 'IPMI_FIRMWARE_VERSION' => read_ipmi_fw('Firmware Revision'), } } @payload[:properties]['NODE_POSITION_IN_CHASSIS'] = read_node_position if @payload[:vendor] == 'Supermicro' if read_dmi('system-serial-number') == nil @payload[:product] = read_ipmi_fru('Product Part Number') @payload[:properties]['SYSTEM_SERIAL_NUMBER'] = read_ipmi_fru('Product Serial') @payload[:properties]['BASEBOARD_PRODUCT_NAME'] = read_ipmi_fru('Board Part Number') @payload[:properties]['BASEBOARD_SERIAL_NUMBER'] = read_ipmi_fru('Board Serial') @payload[:properties]['CHASSIS_SERIAL_NUMBER'] = read_ipmi_fru('Chassis Serial') end end |
#collect_cpus ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/genesis_collector/collector.rb', line 91 def collect_cpus @payload[:cpus] = get_dmi_data['processor'].reject { |p| p['type'] =~ /<OUT OF SPEC>/ }.map do |p| { description: p['version'], cores: p['core_count'].to_i, threads: p['thread_count'].to_i, speed: p['current_speed'], vendor_name: p['manufacturer'], physid: p['socket_designation'] } end end |
#collect_memories ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/genesis_collector/collector.rb', line 104 def collect_memories @payload[:memories] = get_dmi_data['memory_device'].map do |m| if m['type'] == 'Flash' nil else empty = m['size'] == 'No Module Installed' { size: m['size']['GB'] ? m['size'].to_i * 1024000000 : m['size'].to_i * 1000000, description: empty ? "Empty #{m['form_factor']}" : "#{m['form_factor']} #{m['type_detail']} #{m['speed']}", bank: m['bank_locator'], slot: m['locator'], product: empty ? nil : m['part_number'], vendor_name: empty ? nil : m['manufacturer'], serial_number: empty ? nil : m['serial_number'] } end end.compact end |
#submit! ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/genesis_collector/collector.rb', line 40 def submit! fail 'Must collect data first!' unless @payload headers = { 'Authorization' => "Token token=\"#{@config[:api_token]}\"", 'Content-Type' => 'application/json' } http = SimpleHTTP.new(@config[:endpoint], headers: headers) response = http.patch("/api/devices/#{@sku}", @payload) if ['404', '422'].include?(response.code) http.post('/api/devices', sku: @sku, type: 'Server') http.patch("/api/devices/#{@sku}", @payload) end end |