Class: GRI::Vendor
Constant Summary collapse
- DEFS =
{}
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #get_firm(f_re, sysinfo) ⇒ Object
- #get_punits ⇒ Object
- #get_ver(v_re, sysinfo) ⇒ Object
-
#initialize(vdefs, sysinfo, options) ⇒ Vendor
constructor
A new instance of Vendor.
Constructor Details
#initialize(vdefs, sysinfo, options) ⇒ Vendor
Returns a new instance of Vendor.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/gri/vendor.rb', line 31 def initialize vdefs, sysinfo, @name = vdefs[:name] @sysinfo = sysinfo @options = {'ver'=>'1', 'interfaces'=>true, 'ipaddr'=>true} @options.merge! vdefs[:options] if vdefs[:options] @options.merge! if class <<@options def set_unless_defined k, v=true self[k] = v unless self.has_key? k end end sysinfo['_firm'] = get_firm vdefs[:firm_re], sysinfo sysinfo['_ver'] = get_ver vdefs[:version_re], sysinfo sysinfo['_sysdescr'] = sysinfo['sysDescr'] if (cb = vdefs[:after_initialize]) cb.call @sysinfo, @options end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/gri/vendor.rb', line 8 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/gri/vendor.rb', line 8 def @options end |
Class Method Details
.check(sysinfo, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gri/vendor.rb', line 10 def self.check sysinfo, ={} vdefs = nil if !(sysobjectid = sysinfo['sysObjectID']) or sysobjectid.size < 5 else sysoid = BER.dec_oid(sysobjectid[5..-1]) sysoid.size.downto(1) {|n| sysoidkey = sysoid[0, n].map {|noid| noid.to_s}.join('.') if (vdefs = self::DEFS[sysoidkey]) if Array === vdefs vname, , f_re, v_re = vdefs vdefs = {:name=>vname, :options=>, :firm_re=>f_re, :version_re=>v_re} end break end } end vdefs ||= {:name=>'unknown'} self.new vdefs, sysinfo, end |
Instance Method Details
#get_firm(f_re, sysinfo) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/gri/vendor.rb', line 50 def get_firm f_re, sysinfo sysdescr = sysinfo['sysDescr'] || '?' if f_re match = f_re.match sysdescr match ? match[1] : '?' else (f = sysdescr.scan(/\A([-\w]+)/).first) ? f[0] : '?' end end |
#get_punits ⇒ Object
71 72 73 74 |
# File 'lib/gri/vendor.rb', line 71 def get_punits units = PollingUnit.all_units .keys.map {|k| [k] ? units[k] : nil}.compact end |
#get_ver(v_re, sysinfo) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/gri/vendor.rb', line 60 def get_ver v_re, sysinfo sysdescr = sysinfo['sysDescr'] || '?' if v_re match = v_re.match sysdescr match ? match[1] : '?' else tmp, = sysdescr.scan(/(\d+\.[\.\d]+)/).first tmp || '?' end end |