Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#_format(key, value) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
# File 'lib/facter/onering_properties_network.rb', line 2

def _format(key, value)
  rv = []
  value = nil if value =~ /Not received/i

  begin
    case key
    when :autoneg
      v0, v1 = value.split('/')
      rv << [:autoneg_supported, (v0 == 'supported')]
      rv << [:autoneg_enabled, (v1 == 'enabled')]

    when :mgmt_ip
      rv << [:management_ip, value]

    when :mau_oper_type
      rv << [:mau_type, value]

    when :port_id
      value = value.split(' ')
      value = value.select{|i| i =~ /..:..:..:..:..:../ }.first

      rv << [:port_mac, value.upcase]

    when :chassis_id
      value = value.split(' ')
      value = value.select{|i| i =~ /..:..:..:..:..:../ }.first

      rv << [:chassis_mac, value.upcase]

    when :port_descr
      port = value.split(/[^0-9]([0-9])/, 2)
      port.shift
      port = port.join('')

      rv << [:port_name, value]
      rv << [:port, port]

    when :mfs
      rv << [:mfs, (value.split(' ').first.to_i rescue nil)]

    when :sys_name

      rv << [:switch, value]

    when :lldp_med_device_type,
         :lldp_med_capabilities,
         :caps,
         :sys_descr
      return []

    else
      rv << [key, value]
    end
  rescue
    nil
  end

  return rv
end

#getcommandline(pid) ⇒ Object



24
25
26
27
# File 'lib/facter/onering_properties_netstat.rb', line 24

def getcommandline(pid)
  return nil unless pid.to_i > 0
  (File.read("/proc/#{pid}/cmdline").to_s.strip.chomp.squeeze("\u0000").squeeze("\0").gsub("\u0000", ' ').gsub("\0", ' '))
end

#sz_to_bytes(sz) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/facter/onering_properties_zfs.rb', line 2

def sz_to_bytes(sz)
  case sz[-1].chr
  when 'K'
    rv = sz[0..-2].to_f * (1024)
  when 'M'
    rv = sz[0..-2].to_f * (1024 ** 2)
  when 'G'
    rv = sz[0..-2].to_f * (1024 ** 3)
  when 'T'
    rv = sz[0..-2].to_f * (1024 ** 4)
  when 'P'
    rv = sz[0..-2].to_f * (1024 ** 5)
  when 'E'
    rv = sz[0..-2].to_f * (1024 ** 6)
  when 'Z'
    rv = sz[0..-2].to_f * (1024 ** 7)
  when 'Y'
    rv = sz[0..-2].to_f * (1024 ** 8)
  else
    rv = sz[0..-2].to_f
  end

  rv.to_i
end