Class: GRI::FakeSNMP
Instance Attribute Summary collapse
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #get_start(msg, &cb) ⇒ Object
- #get_value(enoid) ⇒ Object
-
#initialize(path) ⇒ FakeSNMP
constructor
A new instance of FakeSNMP.
- #make_req(state, arg) ⇒ Object
- #recv_msg(msg) ⇒ Object
- #sock ⇒ Object
- #vconv(str) ⇒ Object
- #walk_start(enoid, &cb) ⇒ Object
Constructor Details
#initialize(path) ⇒ FakeSNMP
Returns a new instance of FakeSNMP.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gri/fake_snmp.rb', line 10 def initialize path lines = File.readlines path @lines = [] lines.each {|line| oid, value = line.split ' = ' value = vconv value enoid = BER.enc_v_oid oid[1..-1] @lines.push [enoid, value] if value } @sock = FakeSock.new @roids = SNMP::ROIDS @state = :IDLE end |
Instance Attribute Details
#state ⇒ Object (readonly)
Returns the value of attribute state.
7 8 9 |
# File 'lib/gri/fake_snmp.rb', line 7 def state @state end |
#version ⇒ Object
Returns the value of attribute version.
8 9 10 |
# File 'lib/gri/fake_snmp.rb', line 8 def version @version end |
Instance Method Details
#get_start(msg, &cb) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gri/fake_snmp.rb', line 41 def get_start msg, &cb @cb = cb @state = :GET_REQ @get_buf = [] tag, msg, = BER.tlv msg while msg.size > 0 tag, val, msg = BER.tlv msg if val.getbyte(0) == 6 len = val.getbyte(1) enoid = val[2, len] if (value = get_value(enoid)) @get_buf.push [enoid, value[0], value[1]] end end end end |
#get_value(enoid) ⇒ Object
26 27 28 |
# File 'lib/gri/fake_snmp.rb', line 26 def get_value enoid (res = @lines.assoc enoid) ? res[1] : nil end |
#make_req(state, arg) ⇒ Object
70 71 72 |
# File 'lib/gri/fake_snmp.rb', line 70 def make_req state, arg nil end |
#recv_msg(msg) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/gri/fake_snmp.rb', line 32 def recv_msg msg for arg in @get_buf @cb.call *arg end @get_buf.clear @state = :SUCCESS nil end |
#sock ⇒ Object
30 |
# File 'lib/gri/fake_snmp.rb', line 30 def sock; @sock; end |
#vconv(str) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/gri/fake_snmp.rb', line 74 def vconv str case str when /^INTEGER: (?:\w+\()?([-\d]+)/ [0x02, $1.to_i] when /^STRING: "(.*)/ [0x04, $1[0..-2]] when /^STRING: ([^"].*)/ [0x04, $1] when /^OID: \.(1.*)/ enoid = BER.enc_v_oid $1 [0x06, enoid] when /^Counter(?:32)?: (\d+)/ [0x41, $1.to_i] when /^Gauge(?:\d+): ([-\d]+)/ [0x42, $1.to_i] when /^Counter64: (\d+)/ [0x46, $1.to_i] when /^IpAddress: ([\.\d]+)/ [0x40, $1] else nil end end |
#walk_start(enoid, &cb) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/gri/fake_snmp.rb', line 58 def walk_start enoid, &cb @cb = cb @state = :GETBULK_REQ @get_buf = [] for k, v in @lines if k.index(enoid) == 0 @get_buf.push [k, v[0], v[1]] end end end |