Module: Net::SNMP::Debug
- Included in:
- FFI::LibC, Agent, Listener, MIB::Node, MIB::Node, Message, OID, OID, PDU, ProviderDsl, Session, TrapHandler, V1TrapDsl, V2TrapDsl, Wrapper
- Defined in:
- lib/net/snmp/debug.rb
Class Attribute Summary collapse
-
.logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #debug(msg) ⇒ Object
- #error(msg) ⇒ Object
- #fatal(msg) ⇒ Object
- #info(msg) ⇒ Object
- #print_packet(packet) ⇒ Object
- #time(label, &block) ⇒ Object
- #warn(msg) ⇒ Object
Class Attribute Details
.logger ⇒ Object
Returns the value of attribute logger.
5 6 7 |
# File 'lib/net/snmp/debug.rb', line 5 def logger @logger end |
Instance Method Details
#debug(msg) ⇒ Object
8 9 10 |
# File 'lib/net/snmp/debug.rb', line 8 def debug(msg) Debug.logger.debug msg if Debug.logger end |
#error(msg) ⇒ Object
20 21 22 |
# File 'lib/net/snmp/debug.rb', line 20 def error(msg) Debug.logger.error msg if Debug.logger end |
#fatal(msg) ⇒ Object
24 25 26 |
# File 'lib/net/snmp/debug.rb', line 24 def fatal(msg) Debug.logger.fatal msg if Debug.logger end |
#info(msg) ⇒ Object
12 13 14 |
# File 'lib/net/snmp/debug.rb', line 12 def info(msg) Debug.logger.info msg if Debug.logger end |
#print_packet(packet) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/net/snmp/debug.rb', line 35 def print_packet(packet) byte_string = (packet.kind_of?(Array) ? packet[0] : packet) byte_array = byte_string.unpack("C*") binary = byte_array.map{|n| n.to_s(2).rjust(8, '0')} puts " # | Decimal | Hex | Binary | Character" puts "-------------------------------------------" i = 0 prev = 0 byte_array.zip(binary).each do |byte, binary_string| puts "#{i.to_s.ljust(5)}#{byte.to_s.ljust(10)}0x#{byte.to_s(16).ljust(6)}#{binary_string.ljust(11)}#{byte.chr} #{'Sequence Length' if byte == 130 && prev == 48}" prev = byte i += 1 end end |
#time(label, &block) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/net/snmp/debug.rb', line 28 def time(label, &block) t_start = Time.now block[] t_end = Time.now info "#{label}: #{(t_end - t_start)*1000}ms" end |