Class: GRI::PollingUnit
Direct Known Subclasses
Constant Summary collapse
- UNITS =
{}
Instance Attribute Summary collapse
-
#cat ⇒ Object
readonly
Returns the value of attribute cat.
-
#dhash ⇒ Object
(also: #defs)
Returns the value of attribute dhash.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#oids ⇒ Object
readonly
Returns the value of attribute oids.
-
#ophash ⇒ Object
Returns the value of attribute ophash.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #feed(wh, enoid, tag, val) ⇒ Object
- #fix_workhash(workhash) ⇒ Object
-
#initialize(name, cat) ⇒ PollingUnit
constructor
A new instance of PollingUnit.
- #inspect ⇒ Object
- #set_oids(names) ⇒ Object
Constructor Details
#initialize(name, cat) ⇒ PollingUnit
Returns a new instance of PollingUnit.
41 42 43 44 45 46 47 |
# File 'lib/gri/polling_unit.rb', line 41 def initialize name, cat @name = name @cat = cat @options = {} @ophash = nil @d_p = false end |
Instance Attribute Details
#cat ⇒ Object (readonly)
Returns the value of attribute cat.
5 6 7 |
# File 'lib/gri/polling_unit.rb', line 5 def cat @cat end |
#dhash ⇒ Object Also known as: defs
Returns the value of attribute dhash.
6 7 8 |
# File 'lib/gri/polling_unit.rb', line 6 def dhash @dhash end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/gri/polling_unit.rb', line 5 def name @name end |
#oids ⇒ Object (readonly)
Returns the value of attribute oids.
5 6 7 |
# File 'lib/gri/polling_unit.rb', line 5 def oids @oids end |
#ophash ⇒ Object
Returns the value of attribute ophash.
6 7 8 |
# File 'lib/gri/polling_unit.rb', line 6 def ophash @ophash end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/gri/polling_unit.rb', line 6 def @options end |
Class Method Details
.all_units ⇒ Object
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 |
# File 'lib/gri/polling_unit.rb', line 9 def self.all_units if UNITS.empty? for name, dhash in DEFS next unless String === name pucat = dhash[:cat] || dhash[:pucat] || (dhash[:tdb] and dhash[:tdb].first.intern) || name.intern klass = self if (puclass = dhash[:puclass]) if GRI.const_defined?("#{puclass}PollingUnit") or Object.const_defined?("#{puclass}PollingUnit") klass = eval("#{puclass}PollingUnit") end end pu = klass.new name, pucat pu.dhash = dhash pu.set_oids dhash[:oid] if dhash[:tdb] dhash[:tdb].each {|item| if item =~ /\s+\*\s+/ pre = Regexp.last_match.pre_match post = Regexp.last_match.post_match (pu.ophash ||= {})[pre] = proc {|val| val * post.to_f} end } end self::UNITS[name] = pu end end self::UNITS end |
Instance Method Details
#feed(wh, enoid, tag, val) ⇒ Object
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 |
# File 'lib/gri/polling_unit.rb', line 56 def feed wh, enoid, tag, val if (feed_proc = dhash[:feed]) feed_proc.call wh, enoid, tag, val else if enoid.getbyte(-2) < 128 ind = enoid.getbyte(-1) if ind == 0 oid_ind = enoid else oid_ind = enoid[0..-2] end else if enoid.getbyte(-3) < 128 ind = ((enoid.getbyte(-2) & 0x7f) << 7) + enoid.getbyte(-1) oid_ind = enoid[0..-3] else tmpary = BER.dec_oid enoid oid_ind = BER.enc_v_oid(tmpary[0..-2].join('.')) ind = tmpary[-1] end end if (sym_oid = SNMP::ROIDS[oid_ind]) (conv_val_proc = dhash[:conv_val]) and (val = conv_val_proc.call(sym_oid, val)) if ophash and (pr = ophash[sym_oid]) val = pr.call(val) end (wh[ind] ||= {})[sym_oid] = val end end end |
#fix_workhash(workhash) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/gri/polling_unit.rb', line 88 def fix_workhash workhash if (c = dhash[:fix_workhash]) if c.arity == 1 c.call workhash elsif c.arity == 2 c.call workhash, @options end end end |
#inspect ⇒ Object
98 99 100 |
# File 'lib/gri/polling_unit.rb', line 98 def inspect "#<PU:#{@name}>" end |