Skip to content

Commit 76c6410

Browse files
committed
Added Facter IPMI module
1 parent 53cfc4a commit 76c6410

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Gathers hardware-related facts from the underlying system pertaining
2+
# to IPMI / BMC. Information gathered here is exposed directly as
3+
# Facter facts for the purpose of node registration.
4+
#
5+
6+
require 'facter'
7+
8+
attributes = {}
9+
if Facter.value('virtual') == 'physical'
10+
# add the facts that result from running the "ipmitool mc info" command
11+
last_keyname = ''
12+
%x[sudo ipmitool bmc info 2> /dev/null].split(/\n/).each do |line|
13+
if line.include? ':'
14+
# normal key/value entries
15+
key,val = line.split(/:/)
16+
keyname = key.strip.downcase.tr(' ', '_')
17+
val.strip! unless val.nil?
18+
19+
case keyname
20+
when 'additional_device_support'
21+
last_keyname = 'mk_ipmi_' + keyname
22+
when 'aux_firmware_rev_info'
23+
last_keyname = 'mk_ipmi_' + keyname
24+
else
25+
attributes['mk_ipmi_' + keyname] = val
26+
end
27+
else
28+
# multi value entries for last_keyname
29+
attributes[last_keyname] ||= []
30+
attributes[last_keyname] << line.strip
31+
end
32+
end
33+
34+
# add the facts that result from running the "ipmitool lan print" command
35+
%x[sudo ipmitool lan print 2> /dev/null].split(/\n/).each do |line|
36+
key,val = line.split(/:/)
37+
keyname = key.strip.downcase.tr(' ', '_')
38+
val.strip! unless val.nil?
39+
40+
case keyname
41+
when /set_in_progress|auth_type_enable/
42+
# ignore
43+
when /^$/
44+
# ignore
45+
else
46+
attributes['mk_ipmi_' + keyname] = val
47+
end
48+
end
49+
50+
# add the facts that result from running the "ipmitool fru print" command
51+
fru_id = '0'
52+
%x[sudo ipmitool fru print 2> /dev/null].split(/\n/).each do |line|
53+
if line.include? ':'
54+
key,val = line.split(/:/)
55+
keyname = key.strip.downcase.tr(' ', '_')
56+
val.strip! unless val.nil?
57+
58+
case keyname
59+
when 'fru_device_description'
60+
# value has the device id in it
61+
fru_id = val.gsub(/^.*ID\s+(\d+).*$/, '\1')
62+
else
63+
attributes['mk_ipmi_fru_' + fru_id + '_' + keyname] = val
64+
end
65+
end
66+
end
67+
end
68+
69+
attributes.each_pair do |fact,value|
70+
Facter.add(fact) do
71+
setcode { value }
72+
end
73+
end
74+

0 commit comments

Comments
 (0)