Class: SNMP::SNMPv1_Trap
- Inherits:
-
Object
- Object
- SNMP::SNMPv1_Trap
- Defined in:
- lib/snmp/pdu.rb
Overview
The PDU class for traps in SNMPv1.
Constant Summary collapse
- GENERIC_TRAP_NAME =
Name map for all of the generic traps defined in RFC 1157.
{ 0 => :coldStart, 1 => :warmStart, 2 => :linkDown, 3 => :linkUp, 4 => :authenticationFailure, 5 => :egpNeighborLoss, 6 => :enterpriseSpecific }
- GENERIC_TRAP_CODE =
Code map for all of the generic traps defined in RFC 1157.
GENERIC_TRAP_NAME.invert
Instance Attribute Summary collapse
-
#agent_addr ⇒ Object
Returns the value of attribute agent_addr.
-
#enterprise ⇒ Object
Returns the value of attribute enterprise.
-
#source_ip ⇒ Object
Returns the source IP address for the trap, usually derived from the source IP address of the packet that delivered the trap.
-
#specific_trap ⇒ Object
Returns the value of attribute specific_trap.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#varbind_list ⇒ Object
(also: #vb_list)
Returns the value of attribute varbind_list.
Class Method Summary collapse
Instance Method Summary collapse
- #each_varbind(&block) ⇒ Object
- #encode ⇒ Object
- #generic_trap ⇒ Object
- #generic_trap=(trap) ⇒ Object
-
#initialize(enterprise, agent_addr, generic_trap, specific_trap, timestamp, varbind_list) ⇒ SNMPv1_Trap
constructor
A new instance of SNMPv1_Trap.
Constructor Details
#initialize(enterprise, agent_addr, generic_trap, specific_trap, timestamp, varbind_list) ⇒ SNMPv1_Trap
Returns a new instance of SNMPv1_Trap.
328 329 330 331 332 333 334 335 |
# File 'lib/snmp/pdu.rb', line 328 def initialize(enterprise, agent_addr, generic_trap, specific_trap, , varbind_list) @enterprise = enterprise @agent_addr = agent_addr self.generic_trap = generic_trap @specific_trap = specific_trap @timestamp = @varbind_list = varbind_list end |
Instance Attribute Details
#agent_addr ⇒ Object
Returns the value of attribute agent_addr.
306 307 308 |
# File 'lib/snmp/pdu.rb', line 306 def agent_addr @agent_addr end |
#enterprise ⇒ Object
Returns the value of attribute enterprise.
305 306 307 |
# File 'lib/snmp/pdu.rb', line 305 def enterprise @enterprise end |
#source_ip ⇒ Object
Returns the source IP address for the trap, usually derived from the source IP address of the packet that delivered the trap.
303 304 305 |
# File 'lib/snmp/pdu.rb', line 303 def source_ip @source_ip end |
#specific_trap ⇒ Object
Returns the value of attribute specific_trap.
307 308 309 |
# File 'lib/snmp/pdu.rb', line 307 def specific_trap @specific_trap end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
308 309 310 |
# File 'lib/snmp/pdu.rb', line 308 def @timestamp end |
#varbind_list ⇒ Object Also known as: vb_list
Returns the value of attribute varbind_list.
309 310 311 |
# File 'lib/snmp/pdu.rb', line 309 def varbind_list @varbind_list end |
Class Method Details
.decode(pdu_data) ⇒ Object
313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/snmp/pdu.rb', line 313 def self.decode(pdu_data) oid_data, remainder = decode_object_id(pdu_data) enterprise = ObjectId.new(oid_data) ip_data, remainder = decode_ip_address(remainder) agent_addr = IpAddress.new(ip_data) generic_trap, remainder = decode_integer(remainder) specific_trap, remainder = decode_integer(remainder) time_data, remainder = decode_timeticks(remainder) = TimeTicks.new(time_data) varbind_list, remainder = VarBindList.decode(remainder) assert_no_remainder(remainder) SNMPv1_Trap.new(enterprise, agent_addr, generic_trap, specific_trap, , varbind_list) end |
Instance Method Details
#each_varbind(&block) ⇒ Object
376 377 378 |
# File 'lib/snmp/pdu.rb', line 376 def each_varbind(&block) @varbind_list.each(&block) end |
#encode ⇒ Object
366 367 368 369 370 371 372 373 374 |
# File 'lib/snmp/pdu.rb', line 366 def encode pdu_data = @enterprise.encode << @agent_addr.encode << encode_integer(@generic_trap) << encode_integer(@specific_trap) << @timestamp.encode << @varbind_list.encode encode_tlv(SNMPv1_Trap_PDU_TAG, pdu_data) end |
#generic_trap ⇒ Object
362 363 364 |
# File 'lib/snmp/pdu.rb', line 362 def generic_trap GENERIC_TRAP_NAME[@generic_trap] end |
#generic_trap=(trap) ⇒ Object
351 352 353 354 355 356 357 358 359 360 |
# File 'lib/snmp/pdu.rb', line 351 def generic_trap=(trap) @generic_trap = GENERIC_TRAP_CODE[trap] unless @generic_trap if trap.respond_to?(:to_i) && GENERIC_TRAP_NAME[trap.to_i] @generic_trap = trap else raise InvalidGenericTrap, trap.to_s end end end |