class Proxy::Omaha::OmahaProtocol::Request

Attributes

alephversion[R]
appid[R]
base_url[R]
board[R]
body[R]
distribution[R]
eventresult[R]
eventtype[R]
hostname[R]
ip[R]
ipaddress[R]
ipaddress6[R]
machineid[R]
oem[R]
oemversion[R]
osmajor[R]
osminor[R]
ping[R]
platform[R]
track[R]
updatecheck[R]
version[R]

Public Class Methods

new(body, options) click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/request.rb, line 11
def initialize(body, options)
  @body = body
  @ip = options.fetch(:ip)
  @base_url = options.fetch(:base_url)
  @distribution = options.fetch(:distribution)
  parse_request
  parse_ipaddress
  raise "Could not determine request hostname." if hostname.nil?
end

Public Instance Methods

event?() click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/request.rb, line 58
def event?
  !@event.empty?
end
event_description() click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/request.rb, line 38
def event_description
  Proxy::Omaha::OmahaProtocol.event_description(eventtype)
end
event_result() click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/request.rb, line 42
def event_result
  Proxy::Omaha::OmahaProtocol.event_result(eventresult)
end
facts_data() click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/request.rb, line 21
def facts_data
  {
    :name => hostname,
    :facts => to_facts.merge({:_type => :foreman_omaha, :_timestamp => Time.now})
  }
end
from_coreos?() click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/request.rb, line 46
def from_coreos?
  appid == Proxy::Omaha::OmahaProtocol::COREOS_APPID
end
ping?() click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/request.rb, line 54
def ping?
  !@ping.empty?
end
to_status() click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/request.rb, line 28
def to_status
  return :downloading if eventtype == 13 && eventresult == 1
  return :downloaded if eventtype == 14 && eventresult == 1
  return :installed if eventtype == 3 && eventresult == 1
  return :instance_hold if eventtype == 800 && eventresult == 1
  return :complete if eventtype == 3 && eventresult == 2
  return :error if eventtype == 3 && eventresult == 0
  :unknown
end
updatecheck?() click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/request.rb, line 50
def updatecheck?
  !@updatecheck.empty?
end

Private Instance Methods

lookup_hostname(hostip) click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/request.rb, line 94
def lookup_hostname(hostip)
  Resolv.getname(hostip)
rescue Resolv::ResolvError
  nil
end
parse_ipaddress() click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/request.rb, line 85
def parse_ipaddress
  ipaddr = IPAddr.new(ip) rescue nil
  return if ipaddr.nil?
  ipaddr = IPAddr.new(ipaddr.to_s.sub('::ffff:', '')) if ipaddr.ipv4_mapped?
  @ipaddress = ipaddr.to_s if ipaddr.ipv4?
  @ipaddress6 = ipaddr.to_s if ipaddr.ipv6?
  @hostname = lookup_hostname(ipaddr.to_s)
end
parse_request() click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/request.rb, line 64
def parse_request
  xml_request = Nokogiri::XML(body)
  @appid = xml_request.xpath('/request/app/@appid').to_s.tr('{}', '')
  @machineid = xml_request.xpath('/request/app/@machineid').to_s
  @version = xml_request.xpath('/request/app/@version').to_s
  @osmajor = version.gsub(/^(\d+)\.\d\.\d$/, '\1')
  @osminor = version.gsub(/^\d+\.(\d\.\d)$/, '\1')
  @track = xml_request.xpath('/request/app/@track').to_s
  @board = xml_request.xpath('/request/app/@board').to_s
  @alephversion = xml_request.xpath('/request/app/@alephversion').to_s
  @oemversion = xml_request.xpath('/request/app/@oemversion').to_s
  @oem = xml_request.xpath('/request/app/@oem').to_s
  @platform = xml_request.xpath('/request/os/@platform').to_s
  @platform = 'CoreOS' if @platform.empty?
  @updatecheck = xml_request.xpath('/request/app/updatecheck').to_s
  @ping = xml_request.xpath('/request/app/ping').to_s
  @event = xml_request.xpath('/request/app/event').to_s
  @eventtype = xml_request.xpath('/request/app/event/@eventtype').to_s.to_i
  @eventresult = xml_request.xpath('/request/app/event/@eventresult').to_s.to_i
end
to_facts() click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/request.rb, line 100
def to_facts
  {
    :appid => appid,
    :version => version,
    :track => track,
    :board => board,
    :alephversion => alephversion,
    :oemversion => oemversion,
    :oem => oem,
    :platform => platform,
    :osmajor => osmajor,
    :osminor => osminor,
    :ipaddress => ipaddress,
    :ipaddress6 => ipaddress6,
    :hostname => hostname,
    :machineid => machineid,
    :distribution => distribution
  }
end