Class: Net::SNMP::TrapSession
- Defined in:
- lib/net/snmp/trap_session.rb
Instance Attribute Summary
Attributes inherited from Session
#callback, #community, #peername, #requests, #struct, #version
Instance Method Summary collapse
-
#inform(options = {}, &callback) ⇒ Object
Send an SNMPv2 inform.
-
#initialize(options = {}) ⇒ TrapSession
constructor
Represents a session for sending SNMP traps.
-
#trap(options = {}) ⇒ Object
Send an SNMPv1 trap
options* :enterprise The Oid of the enterprise * :trap_type The generic trap type. -
#trap_v2(options = {}) ⇒ Object
Send an SNMPv2 trap +options * :oid The Oid of the trap * :varbinds A list of Varbind objects to send with the trap.
Methods inherited from Session
#close, #columns, #default_max_repeaters, #errno, #error, #error_message, #get, #get_bulk, #get_next, #method_missing, open, #print_errors, #select, #send_pdu, #set, #snmp_err, #table, #walk
Methods included from Debug
Constructor Details
#initialize(options = {}) ⇒ TrapSession
Represents a session for sending SNMP traps
5 6 7 8 |
# File 'lib/net/snmp/trap_session.rb', line 5 def initialize( = {}) [:peername] = "#{options[:peername]}:162" super() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Net::SNMP::Session
Instance Method Details
#inform(options = {}, &callback) ⇒ Object
Send an SNMPv2 inform. Can accept a callback to execute on confirmation of the inform +options
-
:oid The OID of the inform
-
:varbinds A list of Varbind objects to send with the inform
43 44 45 46 47 48 49 50 |
# File 'lib/net/snmp/trap_session.rb', line 43 def inform( = {}, &callback) if [:oid].kind_of?(String) [:oid] = Net::SNMP::OID.new([:oid]) end pdu = PDU.new(Constants::SNMP_MSG_INFORM) build_trap_pdu(pdu, ) send_pdu(pdu, &callback) end |
#trap(options = {}) ⇒ Object
Send an SNMPv1 trap options
-
:enterprise The Oid of the enterprise
-
:trap_type The generic trap type.
-
:specific_type The specific trap type
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/net/snmp/trap_session.rb', line 15 def trap( = {}) pdu = PDU.new(Constants::SNMP_MSG_TRAP) [:enterprise] ||= '1.3.6.1.4.1.3.1.1' # uh, just send netsnmp enterprise i guess pdu.enterprise = OID.new([:enterprise]) pdu.trap_type = [:trap_type] || 1 # need to check all these defaults pdu.specific_type = [:specific_type] || 0 pdu.time = 1 # put what here? send_pdu(pdu) true end |
#trap_v2(options = {}) ⇒ Object
Send an SNMPv2 trap +options
-
:oid The Oid of the trap
-
:varbinds A list of Varbind objects to send with the trap
30 31 32 33 34 35 36 37 |
# File 'lib/net/snmp/trap_session.rb', line 30 def trap_v2( = {}) if [:oid].kind_of?(String) [:oid] = Net::SNMP::OID.new([:oid]) end pdu = PDU.new(Constants::SNMP_MSG_TRAP2) build_trap_pdu(pdu, ) send_pdu(pdu) end |